Skip to content

Commit

Permalink
Merge branch 'main' of github.com:kube-tarian/kad into workerfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Shifna12Zarnaz committed Jun 6, 2024
2 parents ad3c4d6 + 04239d3 commit 3b28847
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 206 deletions.
6 changes: 2 additions & 4 deletions capten/agent/gin-api-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
"github.com/kube-tarian/kad/capten/agent/internal/config"
)

var log = logging.NewLogger()

func StartRestServer(rpcapi api.ServerInterface, cfg *config.SericeConfig) {
func StartRestServer(rpcapi api.ServerInterface, cfg *config.SericeConfig, log logging.Logger) error {
r := gin.Default()
api.RegisterHandlers(r, rpcapi)

r.Run(fmt.Sprintf("%s:%d", cfg.Host, cfg.RestPort))
return r.RunTLS(fmt.Sprintf("%s:%d", cfg.Host, cfg.RestPort), cfg.CertFileName, cfg.KeyFileName)
}
2 changes: 1 addition & 1 deletion capten/agent/internal/api/agent_cluster_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (a *Agent) DeployDefaultApps(ctx context.Context, request *agentpb.DeployDe
return nil, fmt.Errorf("not implemented")
}

func (a *Agent) GetClusterDefaultApps(ctx context.Context, request *agentpb.GetDefaultAppsStatusRequest) (
func (a *Agent) GetDefaultAppsStatus(ctx context.Context, request *agentpb.GetDefaultAppsStatusRequest) (
*agentpb.GetDefaultAppsStatusResponse, error) {
return nil, fmt.Errorf("not implemented")
}
6 changes: 3 additions & 3 deletions capten/agent/internal/api/cluster_plugin_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ func (a *Agent) GetClusterPlugins(ctx context.Context, request *clusterpluginspb
}

clusterPlugins := []*clusterpluginspb.ClusterPlugin{}
for idx, pluginConfig := range pluginConfigList {
clusterPlugins[idx] = &clusterpluginspb.ClusterPlugin{
for _, pluginConfig := range pluginConfigList {
clusterPlugins = append(clusterPlugins, &clusterpluginspb.ClusterPlugin{
StoreType: pluginConfig.StoreType,
PluginName: pluginConfig.PluginName,
Description: pluginConfig.Description,
Category: pluginConfig.Category,
Icon: pluginConfig.Icon,
Version: pluginConfig.Version,
InstallStatus: pluginConfig.InstallStatus,
}
})
}
return &clusterpluginspb.GetClusterPluginsResponse{
Status: clusterpluginspb.StatusCode_OK,
Expand Down
18 changes: 7 additions & 11 deletions capten/agent/internal/api/plugin_crossplane_project_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,25 @@ const (

func (a *Agent) RegisterCrossplaneProject(ctx context.Context, request *captenpluginspb.RegisterCrossplaneProjectRequest) (
*captenpluginspb.RegisterCrossplaneProjectResponse, error) {
a.log.Infof("Register Crossplane Git project request recieved")

if err := validateArgs(request.Id); err != nil {
a.log.Infof("request validation failed", err)
crossplaneProject, err := a.as.GetCrossplaneProject()
if err != nil {
a.log.Infof("failed to get git project, %v", err)
return &captenpluginspb.RegisterCrossplaneProjectResponse{
Status: captenpluginspb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "request validation failed",
}, nil
}
a.log.Infof("Register Crossplane Git project %s request recieved", request.Id)

crossplaneProject, err := a.as.GetCrossplaneProjectForID(request.Id)
if err != nil {
a.log.Infof("failed to get git project %s, %v", request.Id, err)
return &captenpluginspb.RegisterCrossplaneProjectResponse{
Status: captenpluginspb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "request validation failed",
}, nil
if crossplaneProject.Status == "" {
crossplaneProject.Status = string(model.CrossplaneProjectAvailable)
}

if crossplaneProject.Status != string(model.CrossplaneProjectConfigurationFailed) &&
crossplaneProject.Status != string(model.CrossplaneProjectAvailable) &&
crossplaneProject.Status != string(model.CrossplaneProjectConfigured) {
a.log.Infof("currently the Crossplane project configuration on-going %s, %v", request.Id, crossplaneProject.Status)
a.log.Infof("currently the Crossplane project configuration on-going %s, %v", crossplaneProject.Id, crossplaneProject.Status)
return &captenpluginspb.RegisterCrossplaneProjectResponse{
Status: captenpluginspb.StatusCode_OK,
StatusMessage: "Crossplane configuration on-going",
Expand Down
8 changes: 5 additions & 3 deletions capten/agent/internal/api/plugin_crossplane_provider_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"

"github.com/google/uuid"
"github.com/kube-tarian/kad/capten/common-pkg/gerrors"
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres"
"github.com/kube-tarian/kad/capten/model"
)

Expand All @@ -23,15 +25,15 @@ func (a *Agent) AddCrossplanProvider(ctx context.Context, request *captenplugins
}
a.log.Infof("Add Crossplane Provider type %s with cloud provider %s request recieved", request.CloudType, request.CloudProviderId)

project, err := a.as.GetCrossplanProviderByCloudType(request.CloudType)
if err != nil {
existingProvider, err := a.as.GetCrossplanProviderByCloudType(request.CloudType)
if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist {
a.log.Infof("failed to get crossplane provider", err)
return &captenpluginspb.AddCrossplanProviderResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to get crossplane provider for " + request.CloudType,
}, nil
}
if project != nil {
if existingProvider != nil {
return &captenpluginspb.AddCrossplanProviderResponse{
Status: captenpluginspb.StatusCode_NOT_FOUND,
StatusMessage: "Crossplane provider is already available",
Expand Down
13 changes: 5 additions & 8 deletions capten/agent/internal/api/plugin_tekton_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import (
func (a *Agent) RegisterTektonProject(ctx context.Context, request *captenpluginspb.RegisterTektonProjectRequest) (
*captenpluginspb.RegisterTektonProjectResponse, error) {
a.log.Infof("registering the tekton project")
if err := validateArgs(request.Id); err != nil {
a.log.Infof("request validation failed", err)
return &captenpluginspb.RegisterTektonProjectResponse{
Status: captenpluginspb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "request validation failed",
}, err
}

project, err := a.as.GetTektonProject()
if err != nil {
Expand All @@ -28,10 +21,14 @@ func (a *Agent) RegisterTektonProject(ctx context.Context, request *captenplugin
}, err
}

if project.Status == "" {
project.Status = string(model.TektonProjectAvailable)
}

if project.Status != string(model.TektonProjectConfigurationFailed) &&
project.Status != string(model.TektonProjectAvailable) &&
project.Status != string(model.TektonProjectConfigured) {
a.log.Infof("currently the Tekton project configuration on-going %s, %v", request.Id, project.Status)
a.log.Infof("currently the Tekton project configuration on-going %s, %v", project.Id, project.Status)
return &captenpluginspb.RegisterTektonProjectResponse{
Status: captenpluginspb.StatusCode_OK,
StatusMessage: "Tekton configuration on-going",
Expand Down
11 changes: 9 additions & 2 deletions capten/agent/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/kube-tarian/kad/capten/agent/internal/job"
captenstore "github.com/kube-tarian/kad/capten/common-pkg/capten-store"
"github.com/kube-tarian/kad/capten/common-pkg/crossplane"
"github.com/kube-tarian/kad/capten/common-pkg/k8s"
"github.com/kube-tarian/kad/capten/common-pkg/pb/agentpb"
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
"github.com/kube-tarian/kad/capten/common-pkg/pb/clusterpluginspb"
Expand Down Expand Up @@ -81,11 +82,17 @@ func Start() {
}
}()

err = setupCACertIssuser(cfg.ClusterCAIssuerName)
err = k8s.SetupCACertIssuser(cfg.ClusterCAIssuerName, log)
if err != nil {
log.Fatalf("Failed to setupt CA Cert Issuer in cert-manager %v", err)
}
go ginapiserver.StartRestServer(rpcapi, cfg)

go func() {
err := ginapiserver.StartRestServer(rpcapi, cfg, log)
if err != nil {
log.Errorf("Failed to start REST server, %v", err)
}
}()

err = registerK8SWatcher(as)
if err != nil {
Expand Down
148 changes: 0 additions & 148 deletions capten/agent/internal/app/ca_cert_issuer.go

This file was deleted.

4 changes: 3 additions & 1 deletion capten/agent/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type SericeConfig struct {
Host string `envconfig:"HOST" default:"0.0.0.0"`
Port int `envconfig:"PORT" default:"9091"`
RestPort int `envconfig:"REST_PORT" default:"9092"`
RestPort int `envconfig:"REST_PORT" default:"8443"`
Mode string `envconfig:"MODE" default:"production"`
AuthEnabled bool `envconfig:"AUTH_ENABLED" default:"false"`
CrossplaneSyncJobEnabled bool `envconfig:"CROSSPLANE_SYNC_JOB_ENABLED" default:"true"`
Expand All @@ -16,6 +16,8 @@ type SericeConfig struct {
TektonSyncJobInterval string `envconfig:"TEKTON_SYNC_JOB_INTERVAL" default:"@every 1h"`
DomainName string `envconfig:"DOMAIN_NAME" default:"example.com"`
ClusterCAIssuerName string `envconfig:"AGENT_CLUSTER_CA_ISSUER_NAME" default:"agent-ca-issuer"`
CertFileName string `envconfig:"CERT_FILE_NAME" default:"/tmp/certs/tls.crt"`
KeyFileName string `envconfig:"KEY_FILE_NAME" default:"/tmp/certs/tls.key"`
}

func GetServiceConfig() (*SericeConfig, error) {
Expand Down
2 changes: 1 addition & 1 deletion capten/common-pkg/capten-store/app_config_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (a *Store) GetAllApps() ([]*agentpb.SyncAppData, error) {
return nil, fmt.Errorf("failed to fetch apps: %v", err.Error())
}

var appData []*agentpb.SyncAppData
appData := []*agentpb.SyncAppData{}
for _, ac := range appConfigs {
overrideValues, err := base64.StdEncoding.DecodeString(ac.OverrideValues)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (a *Store) GetAllClusterPluginConfigs() ([]*clusterpluginspb.Plugin, error)
return nil, fmt.Errorf("failed to fetch plugins: %v", err.Error())
}

var pluginConfigs []*clusterpluginspb.Plugin
pluginConfigs := []*clusterpluginspb.Plugin{}
for _, p := range plugins {
values, _ := base64.StdEncoding.DecodeString(p.Values)
overrideValues, _ := base64.StdEncoding.DecodeString(p.OverrideValues)
Expand Down
2 changes: 1 addition & 1 deletion capten/common-pkg/cert/generate_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func GenerateRootCerts() (*CertificatesData, error) {
}, nil
}

func generateCACert() (*Key, *Cert, error) { //(rootKey *rsa.PrivateKey, rootCertTemplate *x509.Certificate, err error) {
func generateCACert() (*Key, *Cert, error) {
rootKey, err := rsa.GenerateKey(rand.Reader, caBitSize)
if err != nil {
err = errors.WithMessage(err, "failed to generate RSA key for root certificate")
Expand Down
Loading

0 comments on commit 3b28847

Please sign in to comment.