diff --git a/capten/Makefile b/capten/Makefile index 9dd646d8..d5ef29d4 100644 --- a/capten/Makefile +++ b/capten/Makefile @@ -32,7 +32,7 @@ build: go mod download CGO_ENABLED=0 go build -o build/deployment_worker deployment-worker/main.go CGO_ENABLED=0 go build -o build/config_worker config-worker/main.go - CGO_ENABLED=0 go build -o build/agent agent/cmd/agent/main.go + CGO_ENABLED=0 go build -o build/agent agent/cmd/main.go clean: rm -rf build diff --git a/capten/agent/cmd/main.go b/capten/agent/cmd/main.go new file mode 100644 index 00000000..cfbbfc78 --- /dev/null +++ b/capten/agent/cmd/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/kube-tarian/kad/capten/agent/internal/app" +) + +func main() { + app.Start() +} diff --git a/capten/agent/pkg/agent/agent.go b/capten/agent/internal/api/agent.go similarity index 78% rename from capten/agent/pkg/agent/agent.go rename to capten/agent/internal/api/agent.go index f4b098ae..e904f571 100644 --- a/capten/agent/pkg/agent/agent.go +++ b/capten/agent/internal/api/agent.go @@ -1,15 +1,15 @@ -package agent +package api import ( "context" "fmt" "github.com/intelops/go-common/logging" - captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" - "github.com/kube-tarian/kad/capten/agent/pkg/config" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" - "github.com/kube-tarian/kad/capten/agent/pkg/temporalclient" + captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store" + "github.com/kube-tarian/kad/capten/agent/internal/config" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/temporalclient" ) var _ agentpb.AgentServer = &Agent{} diff --git a/capten/agent/pkg/agent/agent_auth.go b/capten/agent/internal/api/agent_auth.go similarity index 99% rename from capten/agent/pkg/agent/agent_auth.go rename to capten/agent/internal/api/agent_auth.go index f6f5e263..b2e1cb86 100644 --- a/capten/agent/pkg/agent/agent_auth.go +++ b/capten/agent/internal/api/agent_auth.go @@ -1,4 +1,4 @@ -package agent +package api import ( "context" diff --git a/capten/agent/pkg/agent/agent_cluster_apps.go b/capten/agent/internal/api/agent_cluster_apps.go similarity index 98% rename from capten/agent/pkg/agent/agent_cluster_apps.go rename to capten/agent/internal/api/agent_cluster_apps.go index 165a4144..ae07e3f1 100644 --- a/capten/agent/pkg/agent/agent_cluster_apps.go +++ b/capten/agent/internal/api/agent_cluster_apps.go @@ -1,9 +1,9 @@ -package agent +package api import ( "context" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" ) func (a *Agent) SyncApp(ctx context.Context, request *agentpb.SyncAppRequest) ( diff --git a/capten/agent/pkg/agent/agent_cluster_apps_test.go b/capten/agent/internal/api/agent_cluster_apps_test.go similarity index 97% rename from capten/agent/pkg/agent/agent_cluster_apps_test.go rename to capten/agent/internal/api/agent_cluster_apps_test.go index 88a9339a..8c0baad6 100644 --- a/capten/agent/pkg/agent/agent_cluster_apps_test.go +++ b/capten/agent/internal/api/agent_cluster_apps_test.go @@ -1,12 +1,12 @@ -package agent +package api import ( "context" "os" "testing" - "github.com/kube-tarian/kad/capten/agent/pkg/config" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/config" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" "github.com/kube-tarian/kad/integrator/common-pkg/logging" "github.com/stretchr/testify/suite" "gopkg.in/yaml.v2" diff --git a/capten/agent/pkg/agent/agent_conf_sso.go b/capten/agent/internal/api/app_config_sso.go similarity index 92% rename from capten/agent/pkg/agent/agent_conf_sso.go rename to capten/agent/internal/api/app_config_sso.go index 698e66b5..bf538a53 100644 --- a/capten/agent/pkg/agent/agent_conf_sso.go +++ b/capten/agent/internal/api/app_config_sso.go @@ -1,10 +1,11 @@ -package agent +package api import ( "context" - "github.com/kube-tarian/kad/capten/agent/pkg/credential" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/common-pkg/credential" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -62,7 +63,7 @@ func (a *Agent) ConfigureAppSSO(ctx context.Context, }, nil } - updateAppConfig.Config.InstallStatus = string(appUpgradingStatus) + updateAppConfig.Config.InstallStatus = string(model.AppUpgradingStatus) if err := a.as.UpsertAppConfig(updateAppConfig); err != nil { a.log.Errorf("failed to update app config data for app %s, %v", req.ReleaseName, err) return &agentpb.ConfigureAppSSOResponse{ diff --git a/capten/agent/pkg/agent/agent_conf_sso_test.go b/capten/agent/internal/api/app_config_sso_test.go similarity index 98% rename from capten/agent/pkg/agent/agent_conf_sso_test.go rename to capten/agent/internal/api/app_config_sso_test.go index c2af10af..9437f930 100644 --- a/capten/agent/pkg/agent/agent_conf_sso_test.go +++ b/capten/agent/internal/api/app_config_sso_test.go @@ -1,4 +1,4 @@ -package agent +package api import ( "testing" diff --git a/capten/agent/pkg/agent/agent_app_deploy.go b/capten/agent/internal/api/app_deploy_apis.go similarity index 92% rename from capten/agent/pkg/agent/agent_app_deploy.go rename to capten/agent/internal/api/app_deploy_apis.go index 6fd63999..236f443e 100644 --- a/capten/agent/pkg/agent/agent_app_deploy.go +++ b/capten/agent/internal/api/app_deploy_apis.go @@ -1,11 +1,11 @@ -package agent +package api import ( "context" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" - "github.com/kube-tarian/kad/capten/agent/pkg/workers" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/workers" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" ) @@ -45,7 +45,7 @@ func (a *Agent) InstallApp(ctx context.Context, request *agentpb.InstallAppReque Icon: request.AppConfig.Icon, LaunchURL: launchURL, LaunchUIDescription: request.AppConfig.LaunchUIDescription, - InstallStatus: string(appIntallingStatus), + InstallStatus: string(model.AppIntallingStatus), DefualtApp: request.AppConfig.DefualtApp, PluginName: request.AppConfig.PluginName, PluginDescription: request.AppConfig.PluginDescription, @@ -103,7 +103,7 @@ func (a *Agent) UnInstallApp(ctx context.Context, request *agentpb.UnInstallAppR Timeout: 10, } - appConfigdata.Config.InstallStatus = string(appUnInstallingStatus) + appConfigdata.Config.InstallStatus = string(model.AppUnInstallingStatus) if err := a.as.UpsertAppConfig(appConfigdata); err != nil { a.log.Errorf("failed to update app config status with UnInstalling for app %s, %v", req.ReleaseName, err) return &agentpb.UnInstallAppResponse{ @@ -163,7 +163,7 @@ func (a *Agent) UpdateAppValues(ctx context.Context, req *agentpb.UpdateAppValue } appConfig.Config.LaunchURL = launchURL - appConfig.Config.InstallStatus = string(appUpgradingStatus) + appConfig.Config.InstallStatus = string(model.AppUpgradingStatus) if err := a.as.UpsertAppConfig(appConfig); err != nil { a.log.Errorf("failed to update app config data for app %s, %v", req.ReleaseName, err) return &agentpb.UpdateAppValuesResponse{ @@ -238,7 +238,7 @@ func (a *Agent) UpgradeApp(ctx context.Context, req *agentpb.UpgradeAppRequest) Icon: req.AppConfig.Icon, LaunchURL: launchURL, LaunchUIDescription: req.AppConfig.LaunchUIDescription, - InstallStatus: string(appIntallingStatus), + InstallStatus: string(model.AppIntallingStatus), DefualtApp: req.AppConfig.DefualtApp, PluginName: req.AppConfig.PluginName, PluginDescription: req.AppConfig.PluginDescription, @@ -272,9 +272,9 @@ func (a *Agent) UpgradeApp(ctx context.Context, req *agentpb.UpgradeAppRequest) func (a *Agent) installAppWithWorkflow(req *model.ApplicationInstallRequest, appConfig *agentpb.SyncAppData) { wd := workers.NewDeployment(a.tc, a.log) - _, err := wd.SendEvent(context.TODO(), string(appInstallAction), req) + _, err := wd.SendEvent(context.TODO(), string(model.AppInstallAction), req) if err != nil { - appConfig.Config.InstallStatus = string(appIntallFailedStatus) + appConfig.Config.InstallStatus = string(model.AppIntallFailedStatus) if err := a.as.UpsertAppConfig(appConfig); err != nil { a.log.Errorf("failed to update app config for app %s, %v", appConfig.Config.ReleaseName, err) return @@ -283,7 +283,7 @@ func (a *Agent) installAppWithWorkflow(req *model.ApplicationInstallRequest, return } - appConfig.Config.InstallStatus = string(appIntalledStatus) + appConfig.Config.InstallStatus = string(model.AppIntalledStatus) if err := a.as.UpsertAppConfig(appConfig); err != nil { a.log.Errorf("failed to update app config for app %s, %v", appConfig.Config.ReleaseName, err) return @@ -292,11 +292,11 @@ func (a *Agent) installAppWithWorkflow(req *model.ApplicationInstallRequest, func (a *Agent) unInstallAppWithWorkflow(req *model.ApplicationDeleteRequest, appConfig *agentpb.SyncAppData) { wd := workers.NewDeployment(a.tc, a.log) - _, err := wd.SendDeleteEvent(context.TODO(), string(appUnInstallAction), req) + _, err := wd.SendDeleteEvent(context.TODO(), string(model.AppUnInstallAction), req) if err != nil { a.log.Errorf("failed to send delete event to workflow for app %s, %v", req.ReleaseName, err) - appConfig.Config.InstallStatus = string(appIntalledStatus) + appConfig.Config.InstallStatus = string(model.AppIntalledStatus) if err := a.as.UpsertAppConfig(appConfig); err != nil { a.log.Errorf("failed to update app config status with Installed for app %s, %v", req.ReleaseName, err) } @@ -312,9 +312,9 @@ func (a *Agent) unInstallAppWithWorkflow(req *model.ApplicationDeleteRequest, ap func (a *Agent) upgradeAppWithWorkflow(req *model.ApplicationInstallRequest, appConfig *agentpb.SyncAppData) { wd := workers.NewDeployment(a.tc, a.log) - _, err := wd.SendEvent(context.TODO(), string(appUpgradeAction), req) + _, err := wd.SendEvent(context.TODO(), string(model.AppUpgradeAction), req) if err != nil { - appConfig.Config.InstallStatus = string(appUpgradeFaileddStatus) + appConfig.Config.InstallStatus = string(model.AppUpgradeFaileddStatus) if err := a.as.UpsertAppConfig(appConfig); err != nil { a.log.Errorf("failed to update app config for app %s, %v", appConfig.Config.ReleaseName, err) return @@ -323,7 +323,7 @@ func (a *Agent) upgradeAppWithWorkflow(req *model.ApplicationInstallRequest, return } - appConfig.Config.InstallStatus = string(appUpgradedStatus) + appConfig.Config.InstallStatus = string(model.AppUpgradedStatus) if err := a.as.UpsertAppConfig(appConfig); err != nil { a.log.Errorf("failed to update app config for app %s, %v", appConfig.Config.ReleaseName, err) return diff --git a/capten/agent/pkg/agent/agent_app_values_values.go b/capten/agent/internal/api/app_values_util.go similarity index 97% rename from capten/agent/pkg/agent/agent_app_values_values.go rename to capten/agent/internal/api/app_values_util.go index 0c9152bc..6cbbacb1 100644 --- a/capten/agent/pkg/agent/agent_app_values_values.go +++ b/capten/agent/internal/api/app_values_util.go @@ -1,4 +1,4 @@ -package agent +package api import ( "bytes" @@ -8,9 +8,9 @@ import ( "strings" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/agent/pkg/credential" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/common-pkg/credential" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" "gopkg.in/yaml.v2" ) diff --git a/capten/agent/pkg/agent/agent_app_values_util_test.go b/capten/agent/internal/api/app_values_util_test.go similarity index 98% rename from capten/agent/pkg/agent/agent_app_values_util_test.go rename to capten/agent/internal/api/app_values_util_test.go index 98ae338f..ff946912 100644 --- a/capten/agent/pkg/agent/agent_app_values_util_test.go +++ b/capten/agent/internal/api/app_values_util_test.go @@ -1,4 +1,4 @@ -package agent +package api import ( "log" @@ -6,7 +6,7 @@ import ( "testing" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" ) diff --git a/capten/agent/pkg/agent/get_capten_plugins.go b/capten/agent/internal/api/capten_plugin_apis.go similarity index 93% rename from capten/agent/pkg/agent/get_capten_plugins.go rename to capten/agent/internal/api/capten_plugin_apis.go index 4c0f7f63..f2108e15 100644 --- a/capten/agent/pkg/agent/get_capten_plugins.go +++ b/capten/agent/internal/api/capten_plugin_apis.go @@ -1,9 +1,9 @@ -package agent +package api import ( "context" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" ) func (a *Agent) GetCaptenPlugins(ctx context.Context, request *captenpluginspb.GetCaptenPluginsRequest) ( diff --git a/capten/agent/pkg/agent/plugin_argocd_apis.go b/capten/agent/internal/api/plugin_argocd_apis.go similarity index 97% rename from capten/agent/pkg/agent/plugin_argocd_apis.go rename to capten/agent/internal/api/plugin_argocd_apis.go index dc9c2c57..b70ffed3 100644 --- a/capten/agent/pkg/agent/plugin_argocd_apis.go +++ b/capten/agent/internal/api/plugin_argocd_apis.go @@ -1,14 +1,14 @@ -package agent +package api import ( "context" "fmt" "github.com/intelops/go-common/logging" - captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" "github.com/kube-tarian/kad/capten/common-pkg/plugins/argocd" + "github.com/kube-tarian/kad/capten/model" ) const ( diff --git a/capten/agent/pkg/agent/plugin_cloud_provider_apis.go b/capten/agent/internal/api/plugin_cloud_provider_apis.go similarity index 99% rename from capten/agent/pkg/agent/plugin_cloud_provider_apis.go rename to capten/agent/internal/api/plugin_cloud_provider_apis.go index b698b668..92ef44a4 100644 --- a/capten/agent/pkg/agent/plugin_cloud_provider_apis.go +++ b/capten/agent/internal/api/plugin_cloud_provider_apis.go @@ -1,4 +1,4 @@ -package agent +package api import ( "context" @@ -6,7 +6,7 @@ import ( "github.com/google/uuid" "github.com/intelops/go-common/credentials" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" ) const cloudProviderEntityName = "cloud-provider" diff --git a/capten/agent/pkg/agent/plugin_crossplane_project_apis.go b/capten/agent/internal/api/plugin_crossplane_project_apis.go similarity index 98% rename from capten/agent/pkg/agent/plugin_crossplane_project_apis.go rename to capten/agent/internal/api/plugin_crossplane_project_apis.go index 375de450..10fe0877 100644 --- a/capten/agent/pkg/agent/plugin_crossplane_project_apis.go +++ b/capten/agent/internal/api/plugin_crossplane_project_apis.go @@ -1,12 +1,12 @@ -package agent +package api import ( "context" "fmt" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" - "github.com/kube-tarian/kad/capten/agent/pkg/workers" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/workers" + "github.com/kube-tarian/kad/capten/model" captenmodel "github.com/kube-tarian/kad/capten/model" ) diff --git a/capten/agent/pkg/agent/plugin_crossplane_provider_apis.go b/capten/agent/internal/api/plugin_crossplane_provider_apis.go similarity index 96% rename from capten/agent/pkg/agent/plugin_crossplane_provider_apis.go rename to capten/agent/internal/api/plugin_crossplane_provider_apis.go index b7b9bf7b..c820d8e9 100644 --- a/capten/agent/pkg/agent/plugin_crossplane_provider_apis.go +++ b/capten/agent/internal/api/plugin_crossplane_provider_apis.go @@ -1,11 +1,11 @@ -package agent +package api import ( "context" "github.com/google/uuid" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/model" ) const ( @@ -77,12 +77,12 @@ func (a *Agent) DeleteCrossplanProvider(ctx context.Context, request *captenplug func (a *Agent) GetCrossplanProviders(ctx context.Context, _ *captenpluginspb.GetCrossplanProvidersRequest) ( *captenpluginspb.GetCrossplanProvidersResponse, error) { - a.log.Infof("Get Crossplane Providers request received") providers, err := a.as.GetCrossplaneProviders() if err != nil { if err.Error() == objectNotFoundErrorMessage { + a.log.Info("No crossplane providers in DB") return &captenpluginspb.GetCrossplanProvidersResponse{ Status: captenpluginspb.StatusCode_NOT_FOUND, StatusMessage: "No crossplane providers found", diff --git a/capten/agent/pkg/agent/plugin_git_apis.go b/capten/agent/internal/api/plugin_git_apis.go similarity index 99% rename from capten/agent/pkg/agent/plugin_git_apis.go rename to capten/agent/internal/api/plugin_git_apis.go index fedd05c3..7f25f82d 100644 --- a/capten/agent/pkg/agent/plugin_git_apis.go +++ b/capten/agent/internal/api/plugin_git_apis.go @@ -1,4 +1,4 @@ -package agent +package api import ( "context" @@ -6,7 +6,7 @@ import ( "github.com/google/uuid" "github.com/intelops/go-common/credentials" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" ) const gitProjectEntityName = "git-project" diff --git a/capten/agent/pkg/agent/plugin_managed_clusters_apis.go b/capten/agent/internal/api/plugin_managed_clusters_apis.go similarity index 97% rename from capten/agent/pkg/agent/plugin_managed_clusters_apis.go rename to capten/agent/internal/api/plugin_managed_clusters_apis.go index 549bc451..dce198a1 100644 --- a/capten/agent/pkg/agent/plugin_managed_clusters_apis.go +++ b/capten/agent/internal/api/plugin_managed_clusters_apis.go @@ -1,11 +1,11 @@ -package agent +package api import ( "context" "fmt" "github.com/intelops/go-common/credentials" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" ) const ManagedClusterEntityName = "managedcluster" diff --git a/capten/agent/pkg/agent/plugin_tekton_apis.go b/capten/agent/internal/api/plugin_tekton_apis.go similarity index 97% rename from capten/agent/pkg/agent/plugin_tekton_apis.go rename to capten/agent/internal/api/plugin_tekton_apis.go index 581b7ba8..2cbb2e6b 100644 --- a/capten/agent/pkg/agent/plugin_tekton_apis.go +++ b/capten/agent/internal/api/plugin_tekton_apis.go @@ -1,11 +1,11 @@ -package agent +package api import ( "context" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" - "github.com/kube-tarian/kad/capten/agent/pkg/workers" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/workers" + "github.com/kube-tarian/kad/capten/model" captenmodel "github.com/kube-tarian/kad/capten/model" ) diff --git a/capten/agent/pkg/agent/agent_store_cred.go b/capten/agent/internal/api/store_cred_apis.go similarity index 93% rename from capten/agent/pkg/agent/agent_store_cred.go rename to capten/agent/internal/api/store_cred_apis.go index 84a78e45..1475d4d0 100644 --- a/capten/agent/pkg/agent/agent_store_cred.go +++ b/capten/agent/internal/api/store_cred_apis.go @@ -1,11 +1,11 @@ -package agent +package api import ( "context" "fmt" - "github.com/kube-tarian/kad/capten/agent/pkg/credential" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/common-pkg/credential" "github.com/intelops/go-common/credentials" ) diff --git a/capten/agent/cmd/agent/main.go b/capten/agent/internal/app/app.go similarity index 78% rename from capten/agent/cmd/agent/main.go rename to capten/agent/internal/app/app.go index 469f97dc..66402b79 100644 --- a/capten/agent/cmd/agent/main.go +++ b/capten/agent/internal/app/app.go @@ -1,4 +1,4 @@ -package main +package app import ( "fmt" @@ -10,13 +10,13 @@ import ( "google.golang.org/grpc" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/agent/pkg/agent" - captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" - "github.com/kube-tarian/kad/capten/agent/pkg/config" - "github.com/kube-tarian/kad/capten/agent/pkg/job" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" - "github.com/kube-tarian/kad/capten/agent/pkg/util" + agentapi "github.com/kube-tarian/kad/capten/agent/internal/api" + captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store" + "github.com/kube-tarian/kad/capten/agent/internal/config" + "github.com/kube-tarian/kad/capten/agent/internal/job" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/util" dbinit "github.com/kube-tarian/kad/capten/common-pkg/cassandra/db-init" dbmigrate "github.com/kube-tarian/kad/capten/common-pkg/cassandra/db-migrate" "github.com/pkg/errors" @@ -28,7 +28,7 @@ var ( StrInterval = "@every %ss" ) -func main() { +func Start() { log.Infof("Staring Agent") cfg, err := config.GetServiceConfig() @@ -47,7 +47,7 @@ func main() { log.Errorf("failed to initialize store, %v", err) } - s, err := agent.NewAgent(log, cfg, as) + rpcapi, err := agentapi.NewAgent(log, cfg, as) if err != nil { log.Fatalf("Agent initialization failed, %v", err) } @@ -60,13 +60,13 @@ func main() { var grpcServer *grpc.Server if cfg.AuthEnabled { log.Info("Agent Authentication enabled") - grpcServer = grpc.NewServer(grpc.UnaryInterceptor(s.AuthInterceptor)) + grpcServer = grpc.NewServer(grpc.UnaryInterceptor(rpcapi.AuthInterceptor)) } else { log.Info("Agent Authentication disabled") grpcServer = grpc.NewServer() } - agentpb.RegisterAgentServer(grpcServer, s) - captenpluginspb.RegisterCaptenPluginsServer(grpcServer, s) + agentpb.RegisterAgentServer(grpcServer, rpcapi) + captenpluginspb.RegisterCaptenPluginsServer(grpcServer, rpcapi) log.Infof("Agent listening at %v", listener.Addr()) reflection.Register(grpcServer) @@ -85,6 +85,8 @@ func main() { jobScheduler.Start() defer jobScheduler.Stop() + log.Info("syncing clusterClaim started successfully...") + signals := make(chan os.Signal, 1) signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) <-signals diff --git a/capten/agent/pkg/capten-store/app_config_store.go b/capten/agent/internal/capten-store/app_config_store.go similarity index 98% rename from capten/agent/pkg/capten-store/app_config_store.go rename to capten/agent/internal/capten-store/app_config_store.go index f53eb7ef..70c57fae 100644 --- a/capten/agent/pkg/capten-store/app_config_store.go +++ b/capten/agent/internal/capten-store/app_config_store.go @@ -8,8 +8,8 @@ import ( "time" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/agentpb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/agentpb" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/argocd_projects.go b/capten/agent/internal/capten-store/argocd_projects.go similarity index 98% rename from capten/agent/pkg/capten-store/argocd_projects.go rename to capten/agent/internal/capten-store/argocd_projects.go index cc2c8665..7eb3c0d7 100644 --- a/capten/agent/pkg/capten-store/argocd_projects.go +++ b/capten/agent/internal/capten-store/argocd_projects.go @@ -5,7 +5,7 @@ import ( "time" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/model" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/cloud_provider.go b/capten/agent/internal/capten-store/cloud_provider.go similarity index 98% rename from capten/agent/pkg/capten-store/cloud_provider.go rename to capten/agent/internal/capten-store/cloud_provider.go index a305ee31..ea58a2c5 100644 --- a/capten/agent/pkg/capten-store/cloud_provider.go +++ b/capten/agent/internal/capten-store/cloud_provider.go @@ -6,7 +6,7 @@ import ( "time" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/crossplane_project.go b/capten/agent/internal/capten-store/crossplane_project.go similarity index 98% rename from capten/agent/pkg/capten-store/crossplane_project.go rename to capten/agent/internal/capten-store/crossplane_project.go index 914f69a5..ff853128 100644 --- a/capten/agent/pkg/capten-store/crossplane_project.go +++ b/capten/agent/internal/capten-store/crossplane_project.go @@ -6,7 +6,7 @@ import ( "github.com/gocql/gocql" "github.com/google/uuid" - "github.com/kube-tarian/kad/capten/agent/pkg/model" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/crossplane_store.go b/capten/agent/internal/capten-store/crossplane_store.go similarity index 96% rename from capten/agent/pkg/capten-store/crossplane_store.go rename to capten/agent/internal/capten-store/crossplane_store.go index 55b1495a..79e65042 100644 --- a/capten/agent/pkg/capten-store/crossplane_store.go +++ b/capten/agent/internal/capten-store/crossplane_store.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/git_projects.go b/capten/agent/internal/capten-store/git_projects.go similarity index 98% rename from capten/agent/pkg/capten-store/git_projects.go rename to capten/agent/internal/capten-store/git_projects.go index 3ae8da15..a8501310 100644 --- a/capten/agent/pkg/capten-store/git_projects.go +++ b/capten/agent/internal/capten-store/git_projects.go @@ -6,7 +6,7 @@ import ( "time" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/managed_cluster.go b/capten/agent/internal/capten-store/managed_cluster.go similarity index 98% rename from capten/agent/pkg/capten-store/managed_cluster.go rename to capten/agent/internal/capten-store/managed_cluster.go index cc3b088f..577dff39 100644 --- a/capten/agent/pkg/capten-store/managed_cluster.go +++ b/capten/agent/internal/capten-store/managed_cluster.go @@ -6,7 +6,7 @@ import ( "time" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/capten-store/store.go b/capten/agent/internal/capten-store/store.go similarity index 100% rename from capten/agent/pkg/capten-store/store.go rename to capten/agent/internal/capten-store/store.go diff --git a/capten/agent/pkg/capten-store/tekton_projects.go b/capten/agent/internal/capten-store/tekton_projects.go similarity index 98% rename from capten/agent/pkg/capten-store/tekton_projects.go rename to capten/agent/internal/capten-store/tekton_projects.go index 26049a8d..5e017d65 100644 --- a/capten/agent/pkg/capten-store/tekton_projects.go +++ b/capten/agent/internal/capten-store/tekton_projects.go @@ -5,7 +5,7 @@ import ( "time" "github.com/gocql/gocql" - "github.com/kube-tarian/kad/capten/agent/pkg/model" + "github.com/kube-tarian/kad/capten/model" "github.com/pkg/errors" ) diff --git a/capten/agent/pkg/config/config.go b/capten/agent/internal/config/config.go similarity index 100% rename from capten/agent/pkg/config/config.go rename to capten/agent/internal/config/config.go diff --git a/capten/agent/pkg/crossplane/crossplane_cluster_claims.go b/capten/agent/internal/crossplane/crossplane_cluster_claims.go similarity index 91% rename from capten/agent/pkg/crossplane/crossplane_cluster_claims.go rename to capten/agent/internal/crossplane/crossplane_cluster_claims.go index 854e7807..d8d70f12 100644 --- a/capten/agent/pkg/crossplane/crossplane_cluster_claims.go +++ b/capten/agent/internal/crossplane/crossplane_cluster_claims.go @@ -9,12 +9,12 @@ import ( "github.com/google/uuid" "github.com/intelops/go-common/credentials" "github.com/intelops/go-common/logging" - captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" + captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" - "github.com/kube-tarian/kad/capten/agent/pkg/model" "github.com/kube-tarian/kad/capten/common-pkg/k8s" + "github.com/kube-tarian/kad/capten/model" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -35,8 +35,8 @@ type ClusterClaimSyncHandler struct { clusters map[string]*captenpluginspb.ManagedCluster } -func NewClusterClaimSyncHandler(log logging.Logger, dbStore *captenstore.Store) *ClusterClaimSyncHandler { - return &ClusterClaimSyncHandler{log: log, dbStore: dbStore, clusters: map[string]*captenpluginspb.ManagedCluster{}} +func NewClusterClaimSyncHandler(log logging.Logger, dbStore *captenstore.Store) (*ClusterClaimSyncHandler, error) { + return &ClusterClaimSyncHandler{log: log, dbStore: dbStore, clusters: map[string]*captenpluginspb.ManagedCluster{}}, nil } func (h *ClusterClaimSyncHandler) Sync() error { diff --git a/capten/agent/pkg/crossplane/crossplane_providers.go b/capten/agent/internal/crossplane/crossplane_providers.go similarity index 83% rename from capten/agent/pkg/crossplane/crossplane_providers.go rename to capten/agent/internal/crossplane/crossplane_providers.go index 1f7f21b6..12e2492b 100644 --- a/capten/agent/pkg/crossplane/crossplane_providers.go +++ b/capten/agent/internal/crossplane/crossplane_providers.go @@ -5,12 +5,13 @@ import ( "encoding/json" "fmt" + "github.com/intelops/go-common/credentials" "github.com/intelops/go-common/logging" - captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" + captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/pb/captenpluginspb" + "github.com/kube-tarian/kad/capten/agent/internal/pb/captenpluginspb" "github.com/kube-tarian/kad/capten/common-pkg/k8s" + "github.com/kube-tarian/kad/capten/model" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -20,11 +21,13 @@ const ( type ProvidersSyncHandler struct { log logging.Logger + client *k8s.K8SClient dbStore *captenstore.Store + creds credentials.CredentialAdmin } -func NewProvidersSyncHandler(log logging.Logger, dbStore *captenstore.Store) *ProvidersSyncHandler { - return &ProvidersSyncHandler{log: log, dbStore: dbStore} +func NewProvidersSyncHandler(log logging.Logger, dbStore *captenstore.Store) (*ProvidersSyncHandler, error) { + return &ProvidersSyncHandler{log: log, dbStore: dbStore}, nil } func (h *ProvidersSyncHandler) Sync() error { diff --git a/capten/agent/internal/job/crossplane_resources_sync.go b/capten/agent/internal/job/crossplane_resources_sync.go new file mode 100644 index 00000000..b74c0f16 --- /dev/null +++ b/capten/agent/internal/job/crossplane_resources_sync.go @@ -0,0 +1,30 @@ +package job + +import ( + "github.com/intelops/go-common/logging" + captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store" +) + +type CrossplaneResourcesSync struct { + dbStore *captenstore.Store + log logging.Logger + frequency string +} + +func NewCrossplaneResourcesSync(log logging.Logger, frequency string, dbStore *captenstore.Store) (*CrossplaneResourcesSync, error) { + return &CrossplaneResourcesSync{ + log: log, + frequency: frequency, + dbStore: dbStore, + }, nil +} + +func (v *CrossplaneResourcesSync) CronSpec() string { + return v.frequency +} + +func (v *CrossplaneResourcesSync) Run() { + v.log.Debug("started crossplane resource sync job") + + v.log.Debug("crossplane resource sync job completed") +} diff --git a/capten/agent/pkg/job/schduler.go b/capten/agent/internal/job/schduler.go similarity index 100% rename from capten/agent/pkg/job/schduler.go rename to capten/agent/internal/job/schduler.go diff --git a/capten/agent/pkg/pb/agentpb/agent.pb.go b/capten/agent/internal/pb/agentpb/agent.pb.go similarity index 100% rename from capten/agent/pkg/pb/agentpb/agent.pb.go rename to capten/agent/internal/pb/agentpb/agent.pb.go diff --git a/capten/agent/pkg/pb/agentpb/agent_grpc.pb.go b/capten/agent/internal/pb/agentpb/agent_grpc.pb.go similarity index 100% rename from capten/agent/pkg/pb/agentpb/agent_grpc.pb.go rename to capten/agent/internal/pb/agentpb/agent_grpc.pb.go diff --git a/capten/agent/pkg/pb/captenpluginspb/capten_plugins.pb.go b/capten/agent/internal/pb/captenpluginspb/capten_plugins.pb.go similarity index 100% rename from capten/agent/pkg/pb/captenpluginspb/capten_plugins.pb.go rename to capten/agent/internal/pb/captenpluginspb/capten_plugins.pb.go diff --git a/capten/agent/pkg/pb/captenpluginspb/capten_plugins_grpc.pb.go b/capten/agent/internal/pb/captenpluginspb/capten_plugins_grpc.pb.go similarity index 100% rename from capten/agent/pkg/pb/captenpluginspb/capten_plugins_grpc.pb.go rename to capten/agent/internal/pb/captenpluginspb/capten_plugins_grpc.pb.go diff --git a/capten/agent/pkg/temporalclient/client.go b/capten/agent/internal/temporalclient/client.go similarity index 100% rename from capten/agent/pkg/temporalclient/client.go rename to capten/agent/internal/temporalclient/client.go diff --git a/capten/agent/pkg/temporalclient/dataconverter.go b/capten/agent/internal/temporalclient/dataconverter.go similarity index 100% rename from capten/agent/pkg/temporalclient/dataconverter.go rename to capten/agent/internal/temporalclient/dataconverter.go diff --git a/capten/agent/pkg/temporalclient/encrypt.go b/capten/agent/internal/temporalclient/encrypt.go similarity index 100% rename from capten/agent/pkg/temporalclient/encrypt.go rename to capten/agent/internal/temporalclient/encrypt.go diff --git a/capten/agent/pkg/util/synch_cassandra_secret.go b/capten/agent/internal/util/synch_cassandra_secret.go similarity index 100% rename from capten/agent/pkg/util/synch_cassandra_secret.go rename to capten/agent/internal/util/synch_cassandra_secret.go diff --git a/capten/agent/pkg/workers/configure.go b/capten/agent/internal/workers/configure.go similarity index 98% rename from capten/agent/pkg/workers/configure.go rename to capten/agent/internal/workers/configure.go index 396d34df..36d36137 100644 --- a/capten/agent/pkg/workers/configure.go +++ b/capten/agent/internal/workers/configure.go @@ -9,7 +9,7 @@ import ( "github.com/google/uuid" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/agent/pkg/temporalclient" + "github.com/kube-tarian/kad/capten/agent/internal/temporalclient" "github.com/kube-tarian/kad/capten/model" "go.temporal.io/sdk/client" ) diff --git a/capten/agent/pkg/workers/deployment.go b/capten/agent/internal/workers/deployment.go similarity index 97% rename from capten/agent/pkg/workers/deployment.go rename to capten/agent/internal/workers/deployment.go index d8f66c53..881aaaab 100644 --- a/capten/agent/pkg/workers/deployment.go +++ b/capten/agent/internal/workers/deployment.go @@ -9,8 +9,8 @@ import ( "github.com/google/uuid" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/agent/pkg/temporalclient" + "github.com/kube-tarian/kad/capten/agent/internal/temporalclient" + "github.com/kube-tarian/kad/capten/model" "go.temporal.io/sdk/client" ) diff --git a/capten/agent/pkg/workers/types.go b/capten/agent/internal/workers/types.go similarity index 100% rename from capten/agent/pkg/workers/types.go rename to capten/agent/internal/workers/types.go diff --git a/capten/agent/pkg/agent/types.go b/capten/agent/pkg/agent/types.go deleted file mode 100644 index 108e6fbc..00000000 --- a/capten/agent/pkg/agent/types.go +++ /dev/null @@ -1,22 +0,0 @@ -package agent - -type appStatus string - -const ( - appIntallingStatus appStatus = "Installing" - appIntalledStatus appStatus = "Installed" - appUpgradingStatus appStatus = "Upgrading" - appUpgradedStatus appStatus = "Upgraded" - appIntallFailedStatus appStatus = "Installion Failed" - appUpgradeFaileddStatus appStatus = "Upgrade Failed" - appUnInstalledStatus appStatus = "UnInstalled" - appUnInstallingStatus appStatus = "UnInstalling" -) - -type appDeployAction string - -const ( - appInstallAction appDeployAction = "install" - appUnInstallAction appDeployAction = "delete" - appUpgradeAction appDeployAction = "upgrade" -) diff --git a/capten/agent/pkg/credential/client.go b/capten/agent/pkg/credential/client.go deleted file mode 100644 index e3b78186..00000000 --- a/capten/agent/pkg/credential/client.go +++ /dev/null @@ -1,159 +0,0 @@ -package credential - -import ( - "context" - - "github.com/intelops/go-common/credentials" - "github.com/pkg/errors" -) - -const ( - clusterCertEntity = "client-cert" - serviceClientOAuthEntityName = "service-client-oauth" - oauthClientIdKey = "CLIENT_ID" - oauthClientSecretKey = "CLIENT_SECRET" - captenConfigEntityName = "capten-config" - globalValuesCredIdentifier = "global-values" -) - -func GetServiceUserCredential(ctx context.Context, svcEntity, userName string) (cred credentials.ServiceCredential, err error) { - credReader, err := credentials.NewCredentialReader(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential reader") - return - } - cred, err = credReader.GetServiceUserCredential(context.Background(), svcEntity, userName) - if err != nil { - err = errors.WithMessagef(err, "error in reading credential for %s/%s", svcEntity, userName) - } - return -} - -func GetClusterCerts(ctx context.Context, clusterID string) (cred credentials.CertificateData, err error) { - credReader, err := credentials.NewCredentialReader(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential reader") - return - } - - cred, err = credReader.GetCertificateData(context.Background(), clusterCertEntity, clusterID) - if err != nil { - err = errors.WithMessagef(err, "error in reading cert for %s/%s", clusterCertEntity, clusterID) - } - return -} - -func GetGenericCredential(ctx context.Context, entityName, credIndentifer string) (cred map[string]string, err error) { - credReader, err := credentials.NewCredentialReader(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential reader") - return - } - - cred, err = credReader.GetCredential(context.Background(), credentials.GenericCredentialType, entityName, credIndentifer) - if err != nil { - err = errors.WithMessagef(err, "error in reading cred for %s/%s", clusterCertEntity, credIndentifer) - } - return -} - -func PutClusterCerts(ctx context.Context, clusterID, clientCAChainData, clientKeyData, clientCertData string) error { - credReader, err := credentials.NewCredentialAdmin(ctx) - if err != nil { - return errors.WithMessage(err, "error in initializing credential admin") - } - - err = credReader.PutCertificateData(context.Background(), clusterCertEntity, clusterID, - credentials.CertificateData{ - CACert: clientCAChainData, - Key: clientKeyData, - Cert: clientCertData, - }) - if err != nil { - return errors.WithMessagef(err, "error in put cert for %s/%s", clusterCertEntity, clusterID) - } - return nil -} - -func DeleteClusterCerts(ctx context.Context, clusterID string) (err error) { - credReader, err := credentials.NewCredentialAdmin(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential admin") - return - } - - err = credReader.DeleteCertificateData(context.Background(), clusterCertEntity, clusterID) - if err != nil { - err = errors.WithMessagef(err, "error in delete cert for %s/%s", clusterCertEntity, clusterID) - } - return -} - -func StoreAppOauthCredential(ctx context.Context, serviceName, clientId, clientSecret string) error { - credWriter, err := credentials.NewCredentialAdmin(ctx) - if err != nil { - return errors.WithMessage(err, "error in initializing credential admin") - } - - cred := map[string]string{ - oauthClientIdKey: clientId, - oauthClientSecretKey: clientSecret, - } - - err = credWriter.PutCredential(ctx, credentials.GenericCredentialType, - serviceClientOAuthEntityName, serviceName, cred) - if err != nil { - return errors.WithMessagef(err, "error while storing service oauth credential %s/%s into the vault", - serviceClientOAuthEntityName, serviceName) - } - return nil -} - -func GetAppOauthCredential(ctx context.Context, serviceName string) (clientId, clientSecret string, err error) { - credReader, err := credentials.NewCredentialReader(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential reader") - return - } - - cred, err := credReader.GetCredential(ctx, credentials.GenericCredentialType, - serviceClientOAuthEntityName, serviceName) - if err != nil { - err = errors.WithMessagef(err, "error while reading service oauth credential %s/%s from the vault", - serviceClientOAuthEntityName, serviceName) - return - } - - clientId = cred[oauthClientIdKey] - clientSecret = cred[oauthClientSecretKey] - if len(clientId) == 0 || len(clientSecret) == 0 { - err = errors.WithMessagef(err, "invalid service oauth credential %s/%s in the vault", - serviceClientOAuthEntityName, serviceName) - return - } - return -} - -func GetClusterGlobalValues(ctx context.Context) (globalValues string, err error) { - credReader, err := credentials.NewCredentialReader(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential reader") - return - } - - cred, err := credReader.GetCredential(ctx, credentials.GenericCredentialType, - captenConfigEntityName, globalValuesCredIdentifier) - if err != nil { - err = errors.WithMessagef(err, "error while reading cluster global values %s/%s from the vault", - captenConfigEntityName, globalValuesCredIdentifier) - return - } - - globalValues = cred[globalValuesCredIdentifier] - if len(globalValues) == 0 { - err = errors.WithMessagef(err, "invalid cluster global values %s/%s in the vault", - captenConfigEntityName, globalValuesCredIdentifier) - return - } - return -} diff --git a/capten/agent/pkg/job/crossplane_resources_sync.go b/capten/agent/pkg/job/crossplane_resources_sync.go deleted file mode 100644 index f02ab664..00000000 --- a/capten/agent/pkg/job/crossplane_resources_sync.go +++ /dev/null @@ -1,39 +0,0 @@ -package job - -import ( - "github.com/intelops/go-common/logging" - captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" - "github.com/kube-tarian/kad/capten/agent/pkg/crossplane" -) - -type CrossplaneResourcesSync struct { - log logging.Logger - frequency string - clusterHandler *crossplane.ClusterClaimSyncHandler - providerHandler *crossplane.ProvidersSyncHandler -} - -func NewCrossplaneResourcesSync(log logging.Logger, frequency string, dbStore *captenstore.Store) (*CrossplaneResourcesSync, error) { - return &CrossplaneResourcesSync{ - log: log, - frequency: frequency, - clusterHandler: crossplane.NewClusterClaimSyncHandler(log, dbStore), - providerHandler: crossplane.NewProvidersSyncHandler(log, dbStore), - }, nil -} - -func (s *CrossplaneResourcesSync) CronSpec() string { - return s.frequency -} - -func (s *CrossplaneResourcesSync) Run() { - s.log.Debug("started crossplane resource sync job") - if err := s.providerHandler.Sync(); err != nil { - s.log.Errorf("failed to synch providers, %v", err) - } - - if err := s.clusterHandler.Sync(); err != nil { - s.log.Errorf("failed to synch managed clusters, %v", err) - } - s.log.Debug("crossplane resource sync job completed") -} diff --git a/capten/agent/pkg/model/types.go b/capten/agent/pkg/model/types.go deleted file mode 100644 index a7831794..00000000 --- a/capten/agent/pkg/model/types.go +++ /dev/null @@ -1,130 +0,0 @@ -package model - -import ( - "encoding/json" - "fmt" -) - -type WorkFlowStatus string - -const ( - WorkFlowStatusStarted WorkFlowStatus = "started" - WorkFlowStatusCompleted WorkFlowStatus = "completed" - WorkFlowStatusInProgress WorkFlowStatus = "in-progress" - WorkFlowStatusFailed WorkFlowStatus = "failed" -) - -type ArgoCDProjectStatus string - -const ( - ArgoCDProjectAvailable ArgoCDProjectStatus = "available" - ArgoCDProjectConfigured ArgoCDProjectStatus = "configured" - ArgoCDProjectConfigurationFailed ArgoCDProjectStatus = "configuration-failed" -) - -type TektonProjectStatus string - -const ( - TektonProjectAvailable TektonProjectStatus = "available" - TektonProjectConfigured TektonProjectStatus = "configured" - TektonProjectConfigurationOngoing TektonProjectStatus = "configuration-ongoing" - TektonProjectConfigurationFailed TektonProjectStatus = "configuration-failed" -) - -type CrossplaneProjectStatus string - -const ( - CrossplaneProjectAvailable CrossplaneProjectStatus = "available" - CrossplaneProjectConfigured CrossplaneProjectStatus = "configured" - CrossplaneProjectConfigurationOngoing CrossplaneProjectStatus = "configuration-ongoing" - CrossplaneProjectConfigurationFailed CrossplaneProjectStatus = "configuration-failed" -) - -type AppConfig struct { - AppName string `json:"AppName,omitempty"` - Version string `json:"Version,omitempty"` - Category string `json:"Category,omitempty"` - Description string `json:"Description,omitempty"` - ChartName string `json:"ChartName,omitempty"` - RepoName string `json:"RepoName,omitempty"` - ReleaseName string `json:"ReleaseName,omitempty"` - RepoURL string `json:"RepoURL,omitempty"` - Namespace string `json:"Namespace,omitempty"` - CreateNamespace bool `json:"CreateNamespace"` - PrivilegedNamespace bool `json:"PrivilegedNamespace"` - Icon string `json:"Icon,omitempty"` - LaunchURL string `json:"LaunchURL,omitempty"` - LaunchUIDescription string `json:"LaunchUIDescription,omitempty"` -} - -type ApplicationInstallRequest struct { - PluginName string `json:"PluginName,omitempty"` - RepoName string `json:"RepoName,omitempty"` - RepoURL string `json:"RepoURL,omitempty"` - ChartName string `json:"ChartName,omitempty"` - Namespace string `json:"Namespace,omitempty"` - ReleaseName string `json:"ReleaseName,omitempty"` - Timeout uint32 `json:"Timeout,omitempty"` - Version string `json:"Version,omitempty"` - ClusterName string `json:"ClusterName,omitempty"` - OverrideValues string `json:"OverrideValues,omitempty"` -} - -type ApplicationDeleteRequest struct { - PluginName string `json:"plugin_name,omitempty"` - Namespace string `json:"namespace,omitempty"` - ReleaseName string `json:"release_name,omitempty"` - Timeout uint32 `json:"timeout,omitempty"` - ClusterName string `json:"cluster_name,omitempty"` -} - -type ResponsePayload struct { - Status string `json:"status"` - Message json.RawMessage `json:"message,omitempty"` // TODO: This will be enhanced along with plugin implementation -} - -func (rsp *ResponsePayload) ToString() string { - return fmt.Sprintf("Status: %s, Message: %s", rsp.Status, string(rsp.Message)) -} - -type ClusterGitoptsConfig struct { - Usecase string `json:"usecase,omitempty"` - ProjectUrl string `json:"project_url,omitempty"` - Status string `json:"status,omitempty"` -} - -type TektonProject struct { - Id string `json:"id,omitempty"` - GitProjectId string `json:"git_project_id,omitempty"` - GitProjectUrl string `json:"git_project_url,omitempty"` - Status string `json:"status,omitempty"` - LastUpdateTime string `json:"last_update_time,omitempty"` - WorkflowId string `json:"workflow_id,omitempty"` - WorkflowStatus string `json:"workflow_status,omitempty"` -} - -type CrossplaneProject struct { - Id string `json:"id,omitempty"` - GitProjectId string `json:"git_project_id,omitempty"` - GitProjectUrl string `json:"git_project_url,omitempty"` - Status string `json:"status,omitempty"` - LastUpdateTime string `json:"last_update_time,omitempty"` - WorkflowId string `json:"workflow_id,omitempty"` - WorkflowStatus string `json:"workflow_status,omitempty"` -} - -type ArgoCDProject struct { - Id string `json:"id,omitempty"` - GitProjectId string `json:"git_project_id,omitempty"` - GitProjectUrl string `json:"git_project_url,omitempty"` - Status string `json:"status,omitempty"` - LastUpdateTime string `json:"last_update_time,omitempty"` -} - -type CrossplaneProvider struct { - Id string `json:"id,omitempty"` - CloudType string `json:"cloud_type,omitempty"` - ProviderName string `json:"provider_name,omitempty"` - CloudProviderId string `json:"cloud_provider_id,omitempty"` - Status string `json:"status,omitempty"` -} diff --git a/capten/common-pkg/credential/client.go b/capten/common-pkg/credential/client.go index 15c84373..6920b13a 100644 --- a/capten/common-pkg/credential/client.go +++ b/capten/common-pkg/credential/client.go @@ -9,7 +9,12 @@ import ( ) const ( - clusterCertEntity = "client-cert" + clusterCertEntity = "client-cert" + serviceClientOAuthEntityName = "service-client-oauth" + oauthClientIdKey = "CLIENT_ID" + oauthClientSecretKey = "CLIENT_SECRET" + captenConfigEntityName = "capten-config" + globalValuesCredIdentifier = "global-values" ) func GetServiceUserCredential(ctx context.Context, svcEntity, userName string) (cred credentials.ServiceCredential, err error) { @@ -18,7 +23,6 @@ func GetServiceUserCredential(ctx context.Context, svcEntity, userName string) ( err = errors.WithMessage(err, "error in initializing credential reader") return } - cred, err = credReader.GetServiceUserCredential(context.Background(), svcEntity, userName) if err != nil { err = errors.WithMessagef(err, "error in reading credential for %s/%s", svcEntity, userName) @@ -26,17 +30,16 @@ func GetServiceUserCredential(ctx context.Context, svcEntity, userName string) ( return } -func GetClusterCerts(ctx context.Context, orgID, clusterName string) (cred credentials.CertificateData, err error) { +func GetClusterCerts(ctx context.Context, clusterID string) (cred credentials.CertificateData, err error) { credReader, err := credentials.NewCredentialReader(ctx) if err != nil { err = errors.WithMessage(err, "error in initializing credential reader") return } - certIndetifier := getClusterCertIndentifier(orgID, clusterName) - cred, err = credReader.GetCertificateData(context.Background(), clusterCertEntity, certIndetifier) + cred, err = credReader.GetCertificateData(context.Background(), clusterCertEntity, clusterID) if err != nil { - err = errors.WithMessagef(err, "error in reading cert for %s/%s", clusterCertEntity, certIndetifier) + err = errors.WithMessagef(err, "error in reading cert for %s/%s", clusterCertEntity, clusterID) } return } @@ -55,6 +58,89 @@ func GetGenericCredential(ctx context.Context, entityName, credIndentifer string return } +func DeleteClusterCerts(ctx context.Context, clusterID string) (err error) { + credReader, err := credentials.NewCredentialAdmin(ctx) + if err != nil { + err = errors.WithMessage(err, "error in initializing credential admin") + return + } + + err = credReader.DeleteCertificateData(context.Background(), clusterCertEntity, clusterID) + if err != nil { + err = errors.WithMessagef(err, "error in delete cert for %s/%s", clusterCertEntity, clusterID) + } + return +} + +func StoreAppOauthCredential(ctx context.Context, serviceName, clientId, clientSecret string) error { + credWriter, err := credentials.NewCredentialAdmin(ctx) + if err != nil { + return errors.WithMessage(err, "error in initializing credential admin") + } + + cred := map[string]string{ + oauthClientIdKey: clientId, + oauthClientSecretKey: clientSecret, + } + + err = credWriter.PutCredential(ctx, credentials.GenericCredentialType, + serviceClientOAuthEntityName, serviceName, cred) + if err != nil { + return errors.WithMessagef(err, "error while storing service oauth credential %s/%s into the vault", + serviceClientOAuthEntityName, serviceName) + } + return nil +} + +func GetAppOauthCredential(ctx context.Context, serviceName string) (clientId, clientSecret string, err error) { + credReader, err := credentials.NewCredentialReader(ctx) + if err != nil { + err = errors.WithMessage(err, "error in initializing credential reader") + return + } + + cred, err := credReader.GetCredential(ctx, credentials.GenericCredentialType, + serviceClientOAuthEntityName, serviceName) + if err != nil { + err = errors.WithMessagef(err, "error while reading service oauth credential %s/%s from the vault", + serviceClientOAuthEntityName, serviceName) + return + } + + clientId = cred[oauthClientIdKey] + clientSecret = cred[oauthClientSecretKey] + if len(clientId) == 0 || len(clientSecret) == 0 { + err = errors.WithMessagef(err, "invalid service oauth credential %s/%s in the vault", + serviceClientOAuthEntityName, serviceName) + return + } + return +} + +func GetClusterGlobalValues(ctx context.Context) (globalValues string, err error) { + credReader, err := credentials.NewCredentialReader(ctx) + if err != nil { + err = errors.WithMessage(err, "error in initializing credential reader") + return + } + + cred, err := credReader.GetCredential(ctx, credentials.GenericCredentialType, + captenConfigEntityName, globalValuesCredIdentifier) + if err != nil { + err = errors.WithMessagef(err, "error while reading cluster global values %s/%s from the vault", + captenConfigEntityName, globalValuesCredIdentifier) + return + } + + globalValues = cred[globalValuesCredIdentifier] + if len(globalValues) == 0 { + err = errors.WithMessagef(err, "invalid cluster global values %s/%s in the vault", + captenConfigEntityName, globalValuesCredIdentifier) + return + } + return +} + func PutServiceUserCredential(ctx context.Context, svcEntity, userIdentifer, userName, password string) error { credAdmin, err := credentials.NewCredentialAdmin(ctx) if err != nil { @@ -91,21 +177,6 @@ func PutClusterCerts(ctx context.Context, orgID, clusterName, clientCAChainData, return nil } -func DeleteClusterCerts(ctx context.Context, orgID, clusterName string) (err error) { - credReader, err := credentials.NewCredentialAdmin(ctx) - if err != nil { - err = errors.WithMessage(err, "error in initializing credential admin") - return - } - - certIndetifier := getClusterCertIndentifier(orgID, clusterName) - err = credReader.DeleteCertificateData(context.Background(), clusterCertEntity, certIndetifier) - if err != nil { - err = errors.WithMessagef(err, "error in delete cert for %s/%s", clusterCertEntity, certIndetifier) - } - return -} - func getClusterCertIndentifier(orgID, clusterName string) string { return fmt.Sprintf("%s:%s", orgID, clusterName) } diff --git a/capten/config-worker/integration_tests/main_test.go b/capten/config-worker/integration_tests/main_test.go deleted file mode 100644 index 9b583dc4..00000000 --- a/capten/config-worker/integration_tests/main_test.go +++ /dev/null @@ -1,169 +0,0 @@ -package integrationtests - -import ( - "context" - "encoding/json" - "os" - "testing" - "time" - - "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/config-worker/pkg/workflows" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/application" - "github.com/kube-tarian/kad/capten/model" - "go.temporal.io/sdk/client" -) - -var logger = logging.NewLogger() - -func TestMain(m *testing.M) { - m.Run() -} - -type TestContextData struct { -} - -func setupENV() { -} - -func setup() *TestContextData { - setupENV() - return &TestContextData{} -} - -func tearDown(t *TestContextData) { -} - -func TestIntegrationArgocdConfigEvent(t *testing.T) { - testData := setup() - - data := &model.Request{ - RepoName: "argocd-example", - RepoURL: "https://gitlab.privatecloud.sk/vladoportos/argo-cd-example.git", - ChartName: "hello-world", - Namespace: "default", - ReleaseName: "hello-world", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendConfigEvent(t, "argocd", dataJSON, "install") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) -} - -func TestIntegrationArgocdDeleteEvent(t *testing.T) { - testData := setup() - - data := &model.Request{ - RepoName: "argocd-example", - RepoURL: "https://gitlab.privatecloud.sk/vladoportos/argo-cd-example.git", - ChartName: "hello-world", - Namespace: "default", - ReleaseName: "hello-world", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendConfigEvent(t, "argocd", dataJSON, "delete") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) -} - -func TestIntegrationHelmConfigEvent(t *testing.T) { - testData := setup() - - data := &model.Request{ - RepoName: "argo", - RepoURL: "https://argoproj.github.io/argo-helm", - ChartName: "argo-cd", - Namespace: "default", - ReleaseName: "argocd", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendConfigEvent(t, "helm", dataJSON, "install") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) -} - -func TestIntegrationHelmDeleteEvent(t *testing.T) { - testData := setup() - - data := &model.Request{ - RepoName: "argo", - RepoURL: "https://argoproj.github.io/argo-helm", - ChartName: "argo-cd", - Namespace: "default", - ReleaseName: "argocd", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendConfigEvent(t, "helm", dataJSON, "delete") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) -} - -func sendConfigEvent(t *testing.T, pluginName string, dataJSON json.RawMessage, action string) { - // The client is a heavyweight object that should be created once per process. - temporalAddress := os.Getenv("TEMPORAL_SERVICE_URL") - if len(temporalAddress) == 0 { - temporalAddress = "127.0.0.1:7233" - } - c, err := client.Dial(client.Options{ - HostPort: temporalAddress, - Logger: logger, - }) - if err != nil { - t.Errorf("Unable to create client, %v", err) - } - defer c.Close() - - workflowOptions := client.StartWorkflowOptions{ - ID: "config_worker_workflow", - TaskQueue: application.WorkflowTaskQueueName, - } - - p := []model.RequestPayload{{PluginName: pluginName, Action: action, Data: dataJSON}} - payload, _ := json.Marshal(p) - we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, workflows.Workflow, payload) - if err != nil { - t.Errorf("Unable to execute workflow, %v", err) - } - - logger.Infof("Started workflow, WorkflowID: %v RunID: %v", we.GetID(), we.GetRunID()) - - // Synchronously wait for the workflow completion. - var result model.ResponsePayload - err = we.Get(context.Background(), &result) - if err != nil { - t.Errorf("Unable get workflow result, %v", err) - } - logger.Infof("Workflow result: %+v", result.ToString()) -} diff --git a/capten/config-worker/pkg/activities/activity.go b/capten/config-worker/internal/activities/activity.go similarity index 87% rename from capten/config-worker/pkg/activities/activity.go rename to capten/config-worker/internal/activities/activity.go index bcb5113a..da3437df 100644 --- a/capten/config-worker/pkg/activities/activity.go +++ b/capten/config-worker/internal/activities/activity.go @@ -6,9 +6,9 @@ import ( "fmt" "github.com/intelops/go-common/logging" - agentmodel "github.com/kube-tarian/kad/capten/agent/pkg/model" - "github.com/kube-tarian/kad/capten/config-worker/pkg/crossplane" + "github.com/kube-tarian/kad/capten/config-worker/internal/crossplane" "github.com/kube-tarian/kad/capten/model" + agentmodel "github.com/kube-tarian/kad/capten/model" ) type Activities struct{} diff --git a/capten/config-worker/internal/app/app.go b/capten/config-worker/internal/app/app.go new file mode 100644 index 00000000..a9fe789e --- /dev/null +++ b/capten/config-worker/internal/app/app.go @@ -0,0 +1,29 @@ +package app + +import ( + "github.com/intelops/go-common/logging" + workerframework "github.com/kube-tarian/kad/capten/common-pkg/worker-framework" + "github.com/kube-tarian/kad/capten/config-worker/internal/crossplane" + "github.com/kube-tarian/kad/capten/config-worker/internal/workflows" +) + +const ( + WorkflowTaskQueueName = "Configure" +) + +func Start() { + logger := logging.NewLogger() + logger.Infof("Starting config worker..\n") + + worker, err := workerframework.NewWorker(WorkflowTaskQueueName, workflows.Workflow, &crossplane.CrossPlaneActivities{}, logger) + if err != nil { + logger.Fatalf("Worker initialization failed, Reason: %v\n", err) + } + + logger.Infof("Running config worker..\n") + if err := worker.Run(); err != nil { + logger.Fatalf("failed to start the config-worker, err: %v", err) + } + + logger.Infof("Exiting config worker\n") +} diff --git a/capten/config-worker/pkg/app_config/app_git_helper.go b/capten/config-worker/internal/app_config/app_git_helper.go similarity index 100% rename from capten/config-worker/pkg/app_config/app_git_helper.go rename to capten/config-worker/internal/app_config/app_git_helper.go diff --git a/capten/config-worker/pkg/crossplane/activity.go b/capten/config-worker/internal/crossplane/activity.go similarity index 87% rename from capten/config-worker/pkg/crossplane/activity.go rename to capten/config-worker/internal/crossplane/activity.go index 428151f7..496e4072 100644 --- a/capten/config-worker/pkg/crossplane/activity.go +++ b/capten/config-worker/internal/crossplane/activity.go @@ -5,7 +5,6 @@ import ( "encoding/json" "github.com/intelops/go-common/logging" - agentmodel "github.com/kube-tarian/kad/capten/agent/pkg/model" "github.com/kube-tarian/kad/capten/model" ) @@ -19,7 +18,7 @@ func (c *CrossPlaneActivities) ConfigurationActivity(ctx context.Context, params req := &model.CrossplaneUseCase{} if err := json.Unmarshal(payload, req); err != nil { return model.ResponsePayload{ - Status: string(agentmodel.WorkFlowStatusFailed), + Status: string(model.WorkFlowStatusFailed), Message: json.RawMessage("{\"error\": \"failed to read payload\"}"), }, err } @@ -27,7 +26,7 @@ func (c *CrossPlaneActivities) ConfigurationActivity(ctx context.Context, params config, err := NewCrossPlaneApp() if err != nil { return model.ResponsePayload{ - Status: string(agentmodel.WorkFlowStatusFailed), + Status: string(model.WorkFlowStatusFailed), Message: json.RawMessage("{\"error\": \"failed to initialize crossplane plugin\"}"), }, err } diff --git a/capten/config-worker/pkg/crossplane/config_crossplane_app.go b/capten/config-worker/internal/crossplane/config_crossplane_app.go similarity index 95% rename from capten/config-worker/pkg/crossplane/config_crossplane_app.go rename to capten/config-worker/internal/crossplane/config_crossplane_app.go index 5dd848ff..ed2356d1 100644 --- a/capten/config-worker/pkg/crossplane/config_crossplane_app.go +++ b/capten/config-worker/internal/crossplane/config_crossplane_app.go @@ -10,9 +10,9 @@ import ( "github.com/intelops/go-common/credentials" "github.com/kelseyhightower/envconfig" - agentmodel "github.com/kube-tarian/kad/capten/agent/pkg/model" - appconfig "github.com/kube-tarian/kad/capten/config-worker/pkg/app_config" + appconfig "github.com/kube-tarian/kad/capten/config-worker/internal/app_config" "github.com/kube-tarian/kad/capten/model" + agentmodel "github.com/kube-tarian/kad/capten/model" "github.com/otiai10/copy" "github.com/pkg/errors" ) diff --git a/capten/config-worker/pkg/crossplane/config_crossplane_app_test.go b/capten/config-worker/internal/crossplane/config_crossplane_app_test.go similarity index 97% rename from capten/config-worker/pkg/crossplane/config_crossplane_app_test.go rename to capten/config-worker/internal/crossplane/config_crossplane_app_test.go index ba27f336..fdc0e95f 100644 --- a/capten/config-worker/pkg/crossplane/config_crossplane_app_test.go +++ b/capten/config-worker/internal/crossplane/config_crossplane_app_test.go @@ -5,8 +5,8 @@ import ( "path/filepath" "testing" - model2 "github.com/kube-tarian/kad/capten/agent/pkg/model" "github.com/kube-tarian/kad/capten/model" + model2 "github.com/kube-tarian/kad/capten/model" cp "github.com/otiai10/copy" ) diff --git a/capten/config-worker/pkg/crossplane/types.go b/capten/config-worker/internal/crossplane/types.go similarity index 100% rename from capten/config-worker/pkg/crossplane/types.go rename to capten/config-worker/internal/crossplane/types.go diff --git a/capten/config-worker/pkg/model/payload.go b/capten/config-worker/internal/model/payload.go similarity index 100% rename from capten/config-worker/pkg/model/payload.go rename to capten/config-worker/internal/model/payload.go diff --git a/capten/config-worker/pkg/workflows/workflow.go b/capten/config-worker/internal/workflows/workflow.go similarity index 93% rename from capten/config-worker/pkg/workflows/workflow.go rename to capten/config-worker/internal/workflows/workflow.go index b11c7b49..45b69021 100644 --- a/capten/config-worker/pkg/workflows/workflow.go +++ b/capten/config-worker/internal/workflows/workflow.go @@ -5,7 +5,7 @@ import ( "time" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/config-worker/pkg/activities" + "github.com/kube-tarian/kad/capten/config-worker/internal/activities" "github.com/kube-tarian/kad/capten/model" "go.temporal.io/sdk/temporal" "go.temporal.io/sdk/workflow" diff --git a/capten/config-worker/main.go b/capten/config-worker/main.go index ea7bb6c1..a1662a33 100644 --- a/capten/config-worker/main.go +++ b/capten/config-worker/main.go @@ -1,29 +1,9 @@ package main import ( - "github.com/intelops/go-common/logging" - workerframework "github.com/kube-tarian/kad/capten/common-pkg/worker-framework" - "github.com/kube-tarian/kad/capten/config-worker/pkg/crossplane" - "github.com/kube-tarian/kad/capten/config-worker/pkg/workflows" -) - -const ( - WorkflowTaskQueueName = "Configure" + "github.com/kube-tarian/kad/capten/config-worker/internal/app" ) func main() { - logger := logging.NewLogger() - logger.Infof("Starting config worker..\n") - - worker, err := workerframework.NewWorker(WorkflowTaskQueueName, workflows.Workflow, &crossplane.CrossPlaneActivities{}, logger) - if err != nil { - logger.Fatalf("Worker initialization failed, Reason: %v\n", err) - } - - logger.Infof("Running config worker..\n") - if err := worker.Run(); err != nil { - logger.Fatalf("failed to start the config-worker, err: %v", err) - } - - logger.Infof("Exiting config worker\n") + app.Start() } diff --git a/capten/cassandra/config/cassandra.yaml b/capten/database/cassandra/config/cassandra.yaml similarity index 100% rename from capten/cassandra/config/cassandra.yaml rename to capten/database/cassandra/config/cassandra.yaml diff --git a/capten/cassandra/migrations/001_app_config.down.cql b/capten/database/cassandra/migrations/001_app_config.down.cql similarity index 100% rename from capten/cassandra/migrations/001_app_config.down.cql rename to capten/database/cassandra/migrations/001_app_config.down.cql diff --git a/capten/cassandra/migrations/001_app_config.up.cql b/capten/database/cassandra/migrations/001_app_config.up.cql similarity index 100% rename from capten/cassandra/migrations/001_app_config.up.cql rename to capten/database/cassandra/migrations/001_app_config.up.cql diff --git a/capten/cassandra/migrations/002_git_projects.down.cql b/capten/database/cassandra/migrations/002_git_projects.down.cql similarity index 100% rename from capten/cassandra/migrations/002_git_projects.down.cql rename to capten/database/cassandra/migrations/002_git_projects.down.cql diff --git a/capten/cassandra/migrations/002_git_projects.up.cql b/capten/database/cassandra/migrations/002_git_projects.up.cql similarity index 100% rename from capten/cassandra/migrations/002_git_projects.up.cql rename to capten/database/cassandra/migrations/002_git_projects.up.cql diff --git a/capten/cassandra/migrations/003_cloud_providers.down.cql b/capten/database/cassandra/migrations/003_cloud_providers.down.cql similarity index 100% rename from capten/cassandra/migrations/003_cloud_providers.down.cql rename to capten/database/cassandra/migrations/003_cloud_providers.down.cql diff --git a/capten/cassandra/migrations/003_cloud_providers.up.cql b/capten/database/cassandra/migrations/003_cloud_providers.up.cql similarity index 100% rename from capten/cassandra/migrations/003_cloud_providers.up.cql rename to capten/database/cassandra/migrations/003_cloud_providers.up.cql diff --git a/capten/cassandra/migrations/004_argocd_project.down.cql b/capten/database/cassandra/migrations/004_argocd_project.down.cql similarity index 100% rename from capten/cassandra/migrations/004_argocd_project.down.cql rename to capten/database/cassandra/migrations/004_argocd_project.down.cql diff --git a/capten/cassandra/migrations/004_argocd_project.up.cql b/capten/database/cassandra/migrations/004_argocd_project.up.cql similarity index 100% rename from capten/cassandra/migrations/004_argocd_project.up.cql rename to capten/database/cassandra/migrations/004_argocd_project.up.cql diff --git a/capten/cassandra/migrations/005_tekton_project_data.down.cql b/capten/database/cassandra/migrations/005_tekton_project_data.down.cql similarity index 100% rename from capten/cassandra/migrations/005_tekton_project_data.down.cql rename to capten/database/cassandra/migrations/005_tekton_project_data.down.cql diff --git a/capten/cassandra/migrations/005_tekton_project_data.up.cql b/capten/database/cassandra/migrations/005_tekton_project_data.up.cql similarity index 100% rename from capten/cassandra/migrations/005_tekton_project_data.up.cql rename to capten/database/cassandra/migrations/005_tekton_project_data.up.cql diff --git a/capten/cassandra/migrations/006_crossplane_project.down.cql b/capten/database/cassandra/migrations/006_crossplane_project.down.cql similarity index 100% rename from capten/cassandra/migrations/006_crossplane_project.down.cql rename to capten/database/cassandra/migrations/006_crossplane_project.down.cql diff --git a/capten/cassandra/migrations/006_crossplane_project.up.cql b/capten/database/cassandra/migrations/006_crossplane_project.up.cql similarity index 100% rename from capten/cassandra/migrations/006_crossplane_project.up.cql rename to capten/database/cassandra/migrations/006_crossplane_project.up.cql diff --git a/capten/cassandra/migrations/007_crossplane_provider.down.cql b/capten/database/cassandra/migrations/007_crossplane_provider.down.cql similarity index 100% rename from capten/cassandra/migrations/007_crossplane_provider.down.cql rename to capten/database/cassandra/migrations/007_crossplane_provider.down.cql diff --git a/capten/cassandra/migrations/007_crossplane_provider.up.cql b/capten/database/cassandra/migrations/007_crossplane_provider.up.cql similarity index 100% rename from capten/cassandra/migrations/007_crossplane_provider.up.cql rename to capten/database/cassandra/migrations/007_crossplane_provider.up.cql diff --git a/capten/cassandra/migrations/008_managed_clusters.down.cql b/capten/database/cassandra/migrations/008_managed_clusters.down.cql similarity index 100% rename from capten/cassandra/migrations/008_managed_clusters.down.cql rename to capten/database/cassandra/migrations/008_managed_clusters.down.cql diff --git a/capten/cassandra/migrations/008_managed_clusters.up.cql b/capten/database/cassandra/migrations/008_managed_clusters.up.cql similarity index 100% rename from capten/cassandra/migrations/008_managed_clusters.up.cql rename to capten/database/cassandra/migrations/008_managed_clusters.up.cql diff --git a/capten/deployment-worker/api/deployment_worker.gen.go b/capten/deployment-worker/api/deployment_worker.gen.go deleted file mode 100644 index 2505e6ad..00000000 --- a/capten/deployment-worker/api/deployment_worker.gen.go +++ /dev/null @@ -1,273 +0,0 @@ -// Package api provides primitives to interact with the openapi HTTP API. -// -// Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. -package api - -import ( - "bytes" - "compress/gzip" - "encoding/base64" - "fmt" - "net/http" - "net/url" - "path" - "strings" - - "github.com/getkin/kin-openapi/openapi3" - "github.com/go-chi/chi/v5" -) - -// ServerInterface represents all server handlers. -type ServerInterface interface { - // List of APIs provided by the service - // (GET /api-docs) - GetApiDocs(w http.ResponseWriter, r *http.Request) - // Kubernetes readiness and liveness probe endpoint - // (GET /status) - GetStatus(w http.ResponseWriter, r *http.Request) -} - -// ServerInterfaceWrapper converts contexts to parameters. -type ServerInterfaceWrapper struct { - Handler ServerInterface - HandlerMiddlewares []MiddlewareFunc - ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error) -} - -type MiddlewareFunc func(http.Handler) http.Handler - -// GetApiDocs operation middleware -func (siw *ServerInterfaceWrapper) GetApiDocs(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - - var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetApiDocs(w, r) - }) - - for _, middleware := range siw.HandlerMiddlewares { - handler = middleware(handler) - } - - handler.ServeHTTP(w, r.WithContext(ctx)) -} - -// GetStatus operation middleware -func (siw *ServerInterfaceWrapper) GetStatus(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - - var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetStatus(w, r) - }) - - for _, middleware := range siw.HandlerMiddlewares { - handler = middleware(handler) - } - - handler.ServeHTTP(w, r.WithContext(ctx)) -} - -type UnescapedCookieParamError struct { - ParamName string - Err error -} - -func (e *UnescapedCookieParamError) Error() string { - return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName) -} - -func (e *UnescapedCookieParamError) Unwrap() error { - return e.Err -} - -type UnmarshallingParamError struct { - ParamName string - Err error -} - -func (e *UnmarshallingParamError) Error() string { - return fmt.Sprintf("Error unmarshalling parameter %s as JSON: %s", e.ParamName, e.Err.Error()) -} - -func (e *UnmarshallingParamError) Unwrap() error { - return e.Err -} - -type RequiredParamError struct { - ParamName string -} - -func (e *RequiredParamError) Error() string { - return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName) -} - -type RequiredHeaderError struct { - ParamName string - Err error -} - -func (e *RequiredHeaderError) Error() string { - return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName) -} - -func (e *RequiredHeaderError) Unwrap() error { - return e.Err -} - -type InvalidParamFormatError struct { - ParamName string - Err error -} - -func (e *InvalidParamFormatError) Error() string { - return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error()) -} - -func (e *InvalidParamFormatError) Unwrap() error { - return e.Err -} - -type TooManyValuesForParamError struct { - ParamName string - Count int -} - -func (e *TooManyValuesForParamError) Error() string { - return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count) -} - -// Handler creates http.Handler with routing matching OpenAPI spec. -func Handler(si ServerInterface) http.Handler { - return HandlerWithOptions(si, ChiServerOptions{}) -} - -type ChiServerOptions struct { - BaseURL string - BaseRouter chi.Router - Middlewares []MiddlewareFunc - ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error) -} - -// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux. -func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler { - return HandlerWithOptions(si, ChiServerOptions{ - BaseRouter: r, - }) -} - -func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler { - return HandlerWithOptions(si, ChiServerOptions{ - BaseURL: baseURL, - BaseRouter: r, - }) -} - -// HandlerWithOptions creates http.Handler with additional options -func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler { - r := options.BaseRouter - - if r == nil { - r = chi.NewRouter() - } - if options.ErrorHandlerFunc == nil { - options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) { - http.Error(w, err.Error(), http.StatusBadRequest) - } - } - wrapper := ServerInterfaceWrapper{ - Handler: si, - HandlerMiddlewares: options.Middlewares, - ErrorHandlerFunc: options.ErrorHandlerFunc, - } - - r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api-docs", wrapper.GetApiDocs) - }) - r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/status", wrapper.GetStatus) - }) - - return r -} - -// Base64 encoded, gzipped, json marshaled Swagger object -var swaggerSpec = []string{ - - "H4sIAAAAAAAC/4yRwWrDMAyGX8XonKXpdvOt0DFKBx3rYIfSg2MrrVhiC8sJlJB3H05hjA5GT0bw6/P3", - "oxFs6Dh49ElAj1MB5JsAegSHYiNxouBBwxq5DZcOfVKfIX5hVDtGr96f9x9q9bZRwmipIWvmfAGJUot3", - "7O1v9gaMcv1xWVZlBVMBgdEbJtDwVFblEgpgk87ZFhaG6cEFOw8nTPkJjHGmbRxoeMG0YlrnSAERhYMX", - "nOOPVfW35m4L01SA9F1n4gU0vJIkFZrsKopjGMihU/VFpTMqwTiQxVzXnAT0AbivW7JwzJCFJJP6f9X2", - "18Q9ZtJbiyJN36ofzI3rtq8xekwoKqJx5FFEGe9USwPOA8dQo0LvOJBPv70jDSZhFs9IjPkOoA8j9LEF", - "DQuYjtN3AAAA//+ogzv3LAIAAA==", -} - -// GetSwagger returns the content of the embedded swagger specification file -// or error if failed to decode -func decodeSpec() ([]byte, error) { - zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, "")) - if err != nil { - return nil, fmt.Errorf("error base64 decoding spec: %s", err) - } - zr, err := gzip.NewReader(bytes.NewReader(zipped)) - if err != nil { - return nil, fmt.Errorf("error decompressing spec: %s", err) - } - var buf bytes.Buffer - _, err = buf.ReadFrom(zr) - if err != nil { - return nil, fmt.Errorf("error decompressing spec: %s", err) - } - - return buf.Bytes(), nil -} - -var rawSpec = decodeSpecCached() - -// a naive cached of a decoded swagger spec -func decodeSpecCached() func() ([]byte, error) { - data, err := decodeSpec() - return func() ([]byte, error) { - return data, err - } -} - -// Constructs a synthetic filesystem for resolving external references when loading openapi specifications. -func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) { - var res = make(map[string]func() ([]byte, error)) - if len(pathToFile) > 0 { - res[pathToFile] = rawSpec - } - - return res -} - -// GetSwagger returns the Swagger specification corresponding to the generated code -// in this file. The external references of Swagger specification are resolved. -// The logic of resolving external references is tightly connected to "import-mapping" feature. -// Externally referenced files must be embedded in the corresponding golang packages. -// Urls can be supported but this task was out of the scope. -func GetSwagger() (swagger *openapi3.T, err error) { - var resolvePath = PathToRawSpec("") - - loader := openapi3.NewLoader() - loader.IsExternalRefsAllowed = true - loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) { - var pathToFile = url.String() - pathToFile = path.Clean(pathToFile) - getSpec, ok := resolvePath[pathToFile] - if !ok { - err1 := fmt.Errorf("path not found: %s", pathToFile) - return nil, err1 - } - return getSpec() - } - var specData []byte - specData, err = rawSpec() - if err != nil { - return - } - swagger, err = loader.LoadFromData(specData) - if err != nil { - return - } - return -} diff --git a/capten/deployment-worker/integration_tests/main_test.go b/capten/deployment-worker/integration_tests/main_test.go deleted file mode 100644 index 107a7ff3..00000000 --- a/capten/deployment-worker/integration_tests/main_test.go +++ /dev/null @@ -1,167 +0,0 @@ -package integrationtests - -import ( - "context" - "encoding/json" - "os" - "testing" - "time" - - "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/application" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/workflows" - "github.com/kube-tarian/kad/capten/model" - "go.temporal.io/sdk/client" -) - -var logger = logging.NewLogger() - -func TestMain(m *testing.M) { - m.Run() -} - -func TestIntegrationArgocdDeploymentEvent(t *testing.T) { - testData := setup() - - stop := startMain() - - data := &model.Request{ - RepoName: "argocd-example", - RepoURL: "https://gitlab.privatecloud.sk/vladoportos/argo-cd-example.git", - ChartName: "hello-world", - Namespace: "default", - ReleaseName: "hello-world", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendDeploymentEvent(t, "argocd", dataJSON, "install") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) - stop <- true -} - -func TestIntegrationArgocdDeleteEvent(t *testing.T) { - testData := setup() - - stop := startMain() - - data := &model.Request{ - RepoName: "argocd-example", - RepoURL: "https://gitlab.privatecloud.sk/vladoportos/argo-cd-example.git", - ChartName: "hello-world", - Namespace: "default", - ReleaseName: "hello-world", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendDeploymentEvent(t, "argocd", dataJSON, "delete") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) - stop <- true -} - -func TestIntegrationHelmDeploymentEvent(t *testing.T) { - testData := setup() - - stop := startMain() - - data := &model.Request{ - RepoName: "argo", - RepoURL: "https://argoproj.github.io/argo-helm", - ChartName: "argo-cd", - Namespace: "default", - ReleaseName: "argocd", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendDeploymentEvent(t, "helm", dataJSON, "install") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) - stop <- true -} - -func TestIntegrationHelmDeleteEvent(t *testing.T) { - testData := setup() - - stop := startMain() - - data := &model.Request{ - RepoName: "argo", - RepoURL: "https://argoproj.github.io/argo-helm", - ChartName: "argo-cd", - Namespace: "default", - ReleaseName: "argocd", - Timeout: 5, - } - dataJSON, err := json.Marshal(data) - if err != nil { - t.Errorf("Data marshalling failed, %v", err) - } - - sendDeploymentEvent(t, "helm", dataJSON, "delete") - logger.Info("Sleeping now for 5 seconds") - time.Sleep(5 * time.Second) - - logger.Info("Starting teardown") - tearDown(testData) - stop <- true -} - -func sendDeploymentEvent(t *testing.T, pluginName string, dataJSON json.RawMessage, action string) { - // The client is a heavyweight object that should be created once per process. - temporalAddress := os.Getenv("TEMPORAL_SERVICE_URL") - if len(temporalAddress) == 0 { - temporalAddress = "127.0.0.1:7233" - } - c, err := client.Dial(client.Options{ - HostPort: temporalAddress, - Logger: logger, - }) - if err != nil { - t.Errorf("Unable to create client, %v", err) - } - defer c.Close() - - workflowOptions := client.StartWorkflowOptions{ - ID: "deployment_worker_workflow", - TaskQueue: application.WorkflowTaskQueueName, - } - - p := []model.RequestPayload{{PluginName: pluginName, Action: action, Data: dataJSON}} - payload, _ := json.Marshal(p) - we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, workflows.Workflow, payload) - if err != nil { - t.Errorf("Unable to execute workflow, %v", err) - } - - logger.Infof("Started workflow, WorkflowID: %v RunID: %v", we.GetID(), we.GetRunID()) - - // Synchronously wait for the workflow completion. - var result model.ResponsePayload - err = we.Get(context.Background(), &result) - if err != nil { - t.Errorf("Unable get workflow result, %v", err) - } - logger.Infof("Workflow result: %+v", result.ToString()) -} diff --git a/capten/deployment-worker/integration_tests/setup_test.go b/capten/deployment-worker/integration_tests/setup_test.go deleted file mode 100644 index 8fca777c..00000000 --- a/capten/deployment-worker/integration_tests/setup_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package integrationtests - -import ( - "bytes" - "fmt" - "net/http" - "os" - "time" - - "github.com/kelseyhightower/envconfig" - "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/application" -) - -type TestContextData struct { -} - -func setupENV() { -} - -func setup() *TestContextData { - setupENV() - cfg := &application.Configuration{} - if err := envconfig.Process("", cfg); err != nil { - logger.Fatalf("Could not parse env Config: %v", err) - } - - return &TestContextData{} -} - -func tearDown(t *TestContextData) { -} - -func startMain() chan bool { - stopCh := make(chan bool) - - // Start agent and client - go startApplication(stopCh) - time.Sleep(2 * time.Second) - - // Wait till Agent and Client healthy - isApplicationHealthy := false - for { - select { - // wait till 1min, after that exit 1 - case <-time.After(1 * time.Minute): - logger.Fatalf("Deployment worker application not healthy") - case <-time.After(2 * time.Second): - // Check Agent health - isApplicationHealthy = getHealth(http.MethodGet, "http://localhost:9080", "status", "agent") - } - if isApplicationHealthy { - break - } - } - return stopCh -} - -func getHealth(method, url, path, serviceName string) bool { - resp, err := callHTTPRequest(method, url, path, nil) - if err != nil { - logger.Errorf("%v health check call failed: %v", serviceName, err) - return false - } - - return checkResponse(resp, http.StatusOK) -} - -func checkResponse(resp *http.Response, statusCode int) bool { - return resp.StatusCode == statusCode -} - -func startApplication(stop chan bool) { - os.Setenv("PORT", "9080") - log := logging.NewLogger() - app := application.New(log) - go app.Start() - - <-stop -} - -func callHTTPRequest(method, url, path string, body []byte) (*http.Response, error) { - finalURL := fmt.Sprintf("%s/%s", url, path) - var req *http.Request - if body != nil { - req, _ = http.NewRequest(method, finalURL, bytes.NewBuffer(body)) - } else { - req, _ = http.NewRequest(method, finalURL, nil) - } - client := http.Client{ - Timeout: 5 * time.Second, - } - - return client.Do(req) -} diff --git a/capten/deployment-worker/pkg/activities/activity.go b/capten/deployment-worker/internal/activities/activity.go similarity index 100% rename from capten/deployment-worker/pkg/activities/activity.go rename to capten/deployment-worker/internal/activities/activity.go diff --git a/capten/deployment-worker/pkg/activities/activity_test.go b/capten/deployment-worker/internal/activities/activity_test.go similarity index 100% rename from capten/deployment-worker/pkg/activities/activity_test.go rename to capten/deployment-worker/internal/activities/activity_test.go diff --git a/capten/deployment-worker/internal/app/app.go b/capten/deployment-worker/internal/app/app.go new file mode 100644 index 00000000..c0ee20a4 --- /dev/null +++ b/capten/deployment-worker/internal/app/app.go @@ -0,0 +1,29 @@ +package app + +import ( + "github.com/intelops/go-common/logging" + workerframework "github.com/kube-tarian/kad/capten/common-pkg/worker-framework" + "github.com/kube-tarian/kad/capten/deployment-worker/internal/activities" + "github.com/kube-tarian/kad/capten/deployment-worker/internal/workflows" +) + +const ( + WorkflowTaskQueueName = "Deployment" +) + +func Start() { + logger := logging.NewLogger() + logger.Infof("Started deployment worker\n") + + worker, err := workerframework.NewWorker(WorkflowTaskQueueName, workflows.Workflow, &activities.Activities{}, logger) + if err != nil { + logger.Fatalf("Worker initialization failed, Reason: %v\n", err) + } + + logger.Infof("Running deployment worker..\n") + if err := worker.Run(); err != nil { + logger.Fatalf("failed to start the deployment-worker, err: %v", err) + } + + logger.Infof("Exiting deployment worker\n") +} diff --git a/capten/deployment-worker/pkg/workflows/workflow.go b/capten/deployment-worker/internal/workflows/workflow.go similarity index 95% rename from capten/deployment-worker/pkg/workflows/workflow.go rename to capten/deployment-worker/internal/workflows/workflow.go index f0303c07..b0fa44d6 100644 --- a/capten/deployment-worker/pkg/workflows/workflow.go +++ b/capten/deployment-worker/internal/workflows/workflow.go @@ -6,7 +6,7 @@ import ( "time" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/activities" + "github.com/kube-tarian/kad/capten/deployment-worker/internal/activities" "github.com/kube-tarian/kad/capten/model" "go.temporal.io/sdk/temporal" "go.temporal.io/sdk/workflow" diff --git a/capten/deployment-worker/pkg/workflows/workflow_test.go b/capten/deployment-worker/internal/workflows/workflow_test.go similarity index 92% rename from capten/deployment-worker/pkg/workflows/workflow_test.go rename to capten/deployment-worker/internal/workflows/workflow_test.go index a389d016..908264b1 100644 --- a/capten/deployment-worker/pkg/workflows/workflow_test.go +++ b/capten/deployment-worker/internal/workflows/workflow_test.go @@ -3,7 +3,7 @@ package workflows import ( "testing" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/activities" + "github.com/kube-tarian/kad/capten/deployment-worker/internal/activities" "github.com/kube-tarian/kad/capten/model" "go.temporal.io/sdk/worker" diff --git a/capten/deployment-worker/main.go b/capten/deployment-worker/main.go index e79c583a..ec58bc09 100644 --- a/capten/deployment-worker/main.go +++ b/capten/deployment-worker/main.go @@ -1,24 +1,9 @@ package main import ( - "os" - "os/signal" - "syscall" - - "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/application" + "github.com/kube-tarian/kad/capten/deployment-worker/internal/app" ) func main() { - logger := logging.NewLogger() - logger.Infof("Started deployment worker\n") - app := application.New(logger) - go app.Start() - - signals := make(chan os.Signal, 1) - signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) - <-signals - - app.Close() - logger.Infof("Exiting deployment worker\n") + app.Start() } diff --git a/capten/deployment-worker/pkg/application/application.go b/capten/deployment-worker/pkg/application/application.go deleted file mode 100755 index 52a5ad27..00000000 --- a/capten/deployment-worker/pkg/application/application.go +++ /dev/null @@ -1,93 +0,0 @@ -package application - -import ( - "context" - "errors" - "fmt" - "net/http" - - "github.com/go-chi/chi/v5" - "github.com/kelseyhightower/envconfig" - "github.com/intelops/go-common/logging" - workerframework "github.com/kube-tarian/kad/capten/common-pkg/worker-framework" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/activities" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/handler" - "github.com/kube-tarian/kad/capten/deployment-worker/pkg/workflows" -) - -const ( - WorkflowTaskQueueName = "Deployment" - HelmPluginName = "helm" -) - -type Configuration struct { - Port int `envconfig:"PORT" default:"9080"` -} - -type Application struct { - conf *Configuration - apiServer *handler.APIHandler - httpServer *http.Server - worker *workerframework.Worker - logger logging.Logger -} - -func New(logger logging.Logger) *Application { - cfg := &Configuration{} - if err := envconfig.Process("", cfg); err != nil { - logger.Fatalf("Could not parse env Config: %v\n", err) - } - - worker, err := workerframework.NewWorker(WorkflowTaskQueueName, workflows.Workflow, &activities.Activities{}, logger) - if err != nil { - logger.Fatalf("Worker initialization failed, Reason: %v\n", err) - } - - apiServer, err := handler.NewAPIHandler(worker) - if err != nil { - logger.Fatalf("API Handler initialisation failed: %v\n", err) - } - - mux := chi.NewMux() - apiServer.BindRequest(mux) - - httpServer := &http.Server{ - Addr: fmt.Sprintf("0.0.0.0:%d", cfg.Port), - Handler: mux, - } - - return &Application{ - conf: cfg, - apiServer: apiServer, - httpServer: httpServer, - worker: worker, - logger: logger, - } -} - -func (app *Application) Start() { - app.logger.Infof("Starting worker\n") - go func() { - err := app.worker.Run() - if err != nil { - app.logger.Errorf("Worker stopped listening on temporal, exiting. Readon: %v\n", err) - app.Close() - } - }() - - app.logger.Infof("Starting server at %v", app.httpServer.Addr) - var err error - if err = app.httpServer.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) { - app.logger.Fatalf("Unexpected server close: %v", err) - } - app.logger.Fatalf("Server closed") -} - -func (app *Application) Close() { - app.logger.Infof("Closing the service gracefully") - app.worker.Close() - - if err := app.httpServer.Shutdown(context.Background()); err != nil { - app.logger.Errorf("Could not close the service gracefully: %v", err) - } -} diff --git a/capten/deployment-worker/pkg/handler/api_handler.go b/capten/deployment-worker/pkg/handler/api_handler.go deleted file mode 100755 index a893ce0e..00000000 --- a/capten/deployment-worker/pkg/handler/api_handler.go +++ /dev/null @@ -1,45 +0,0 @@ -package handler - -import ( - "encoding/json" - "net/http" - - "github.com/go-chi/chi/v5" - workerframework "github.com/kube-tarian/kad/capten/common-pkg/worker-framework" - "github.com/kube-tarian/kad/capten/deployment-worker/api" -) - -type APIHandler struct { - worker *workerframework.Worker -} - -const ( - appJSONContentType = "application/json" - contentType = "Content-Type" -) - -func NewAPIHandler(worker *workerframework.Worker) (*APIHandler, error) { - return &APIHandler{ - worker: worker, - }, nil -} - -func (ah *APIHandler) BindRequest(mux *chi.Mux) { - mux.Route("/", func(r chi.Router) { - api.HandlerFromMux(ah, r) - }) -} - -func (ah *APIHandler) GetApiDocs(w http.ResponseWriter, r *http.Request) { - swagger, err := api.GetSwagger() - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - } - w.Header().Set(contentType, appJSONContentType) - _ = json.NewEncoder(w).Encode(swagger) -} - -func (ah *APIHandler) GetStatus(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentType, appJSONContentType) - w.WriteHeader(http.StatusOK) -} diff --git a/capten/go.mod b/capten/go.mod index 24491645..2862d82a 100644 --- a/capten/go.mod +++ b/capten/go.mod @@ -1,11 +1,9 @@ module github.com/kube-tarian/kad/capten -go 1.19 +go 1.21 require ( github.com/argoproj/argo-cd/v2 v2.5.5 - github.com/getkin/kin-openapi v0.107.0 - github.com/go-chi/chi/v5 v5.0.7 github.com/gocql/gocql v1.3.1 github.com/gogo/status v1.1.1 github.com/golang-migrate/migrate/v4 v4.15.2 @@ -127,7 +125,6 @@ require ( github.com/huandu/xstrings v1.3.2 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect - github.com/invopop/yaml v0.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jmoiron/sqlx v1.3.5 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect @@ -154,7 +151,6 @@ require ( github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect diff --git a/capten/go.sum b/capten/go.sum index 62b02588..cce76fd0 100644 --- a/capten/go.sum +++ b/capten/go.sum @@ -405,6 +405,7 @@ github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ClickHouse/clickhouse-go v1.4.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/GoogleCloudPlatform/k8s-cloud-provider v1.16.1-0.20210702024009-ea6160c1d0e3/go.mod h1:8XasY4ymP2V/tn2OOV9ZadmiTE1FIB/h3W+yNlPttKw= github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= @@ -446,6 +447,7 @@ github.com/Microsoft/hcsshim v0.8.22/go.mod h1:91uVCVzvX2QD16sMCenoxxXo6L1wJnLMX github.com/Microsoft/hcsshim v0.8.23/go.mod h1:4zegtUJth7lAvFyc6cH2gGQ5B3OFQim01nnU2M8jKDg= github.com/Microsoft/hcsshim v0.9.2/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc= github.com/Microsoft/hcsshim v0.9.6 h1:VwnDOgLeoi2du6dAznfmspNqTiwczvjv4K7NxuY9jsY= +github.com/Microsoft/hcsshim v0.9.6/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc= github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU= github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= @@ -473,7 +475,9 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5 github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0= github.com/alexflint/go-filemutex v1.1.0/go.mod h1:7P4iRhttt/nUvUOrYIhcpMzv2G6CY9UnI16Z+UJqRyk= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= +github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/miniredis/v2 v2.14.2 h1:VeoqKUAsJfT2af61nDE7qhBzqn3J6xjnt9MFAbdrEtg= +github.com/alicebob/miniredis/v2 v2.14.2/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -561,6 +565,7 @@ github.com/bradleyfalzon/ghinstallation/v2 v2.0.4 h1:tXKVfhE7FcSkhkv0UwkLvPDeZ4k github.com/bradleyfalzon/ghinstallation/v2 v2.0.4/go.mod h1:B40qPqJxWE0jDZgOR1JmaMy+4AY1eBP+IByOvqyAKp0= github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk= github.com/bshuster-repo/logrus-logstash-hook v1.0.0 h1:e+C0SB5R1pu//O4MQ3f9cFuPGoOVeF2fE4Og9otCc70= +github.com/bshuster-repo/logrus-logstash-hook v1.0.0/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk= github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd h1:rFt+Y/IK1aEZkEHchZRSq9OQbsSzIT/OrI8YFFmRIng= @@ -640,6 +645,7 @@ github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTF github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU= github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8= github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA= +github.com/containerd/cgroups v1.0.4/go.mod h1:nLNQtsF7Sl2HxNebu77i1R0oDlhiTG+kO4JTrUzo6IA= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE= @@ -776,6 +782,7 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dhui/dktest v0.3.10/go.mod h1:h5Enh0nG3Qbo9WjNFRrwmKUaePEBhXMOygbz3Ww7Sz0= github.com/distribution/distribution/v3 v3.0.0-20220526142353-ffbd94cbe269 h1:hbCT8ZPPMqefiAWD2ZKjn7ypokIGViTvBBg/ExLSdCk= +github.com/distribution/distribution/v3 v3.0.0-20220526142353-ffbd94cbe269/go.mod h1:28YO/VJk9/64+sTGNuYaBjWxrXTPrj0C0XmgTIOjxX4= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/cli v20.10.18+incompatible h1:f/GQLsVpo10VvToRay2IraVA1wHz9KktZyjev3SIVDU= @@ -864,9 +871,11 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= +github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/fsouza/fake-gcs-server v1.17.0/go.mod h1:D1rTE4YCyHFNa99oyJJ5HyclvN/0uQR+pM/VdlL83bw= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= github.com/fvbommel/sortorder v1.0.1 h1:dSnXLt4mJYH25uDDGa3biZNQsozaUWDSWeKJ0qqFfzE= @@ -875,15 +884,11 @@ github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmx github.com/gabriel-vasile/mimetype v1.4.0/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8= github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg= -github.com/getkin/kin-openapi v0.107.0 h1:bxhL6QArW7BXQj8NjXfIJQy680NsMKd25nwhvpCXchg= -github.com/getkin/kin-openapi v0.107.0/go.mod h1:9Dhr+FasATJZjS4iOLvB0hkaxgYdulrNYm2e9epLWOo= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= -github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= @@ -1071,6 +1076,7 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k= +github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= @@ -1162,6 +1168,7 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51 github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= +github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= @@ -1263,8 +1270,6 @@ github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9FCCAVRQ= github.com/intelops/go-common v1.0.15 h1:w5arGiN4bUxYNOK+Bhk3nUGgRy2mzrzyqMQSZHTLg5g= github.com/intelops/go-common v1.0.15/go.mod h1:MtFNUbf8Br2pyCB4cOOGXnLcODJm6oBgmpnWpnFUD4g= -github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc= -github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= github.com/ishidawataru/sctp v0.0.0-20190723014705-7c296d48a2b5/go.mod h1:DM4VvS+hD/kDi1U1QsX2fnZowwBhqD0Dk3bRPKF/Oc8= github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA= github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw= @@ -1385,6 +1390,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -1530,8 +1536,6 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mohae/deepcopy v0.0.0-20170603005431-491d3605edfb/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= @@ -1581,6 +1585,7 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= +github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -1592,6 +1597,7 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= @@ -1637,6 +1643,7 @@ github.com/ory/client-go v1.1.44/go.mod h1:txO25o+LB3I03DNgHV679Jnpx19/AYKIb2CY+ github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY= github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww= github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= +github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= @@ -1652,6 +1659,7 @@ github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9 github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= +github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY= github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= @@ -1914,6 +1922,7 @@ github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg= +github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43 h1:+lm10QQTNSBd8DVTNGHx7o/IKu9HYDvLMffDhbyLccI= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50 h1:hlE8//ciYMztlGpl/VA+Zm1AcTPHYkHJPbHqE6WJUXE= diff --git a/capten/model/app_types.go b/capten/model/app_types.go new file mode 100644 index 00000000..4cea089d --- /dev/null +++ b/capten/model/app_types.go @@ -0,0 +1,68 @@ +package model + +type WorkFlowStatus string + +type AppStatus string + +const ( + AppIntallingStatus AppStatus = "Installing" + AppIntalledStatus AppStatus = "Installed" + AppUpgradingStatus AppStatus = "Upgrading" + AppUpgradedStatus AppStatus = "Upgraded" + AppIntallFailedStatus AppStatus = "Installion Failed" + AppUpgradeFaileddStatus AppStatus = "Upgrade Failed" + AppUnInstalledStatus AppStatus = "UnInstalled" + AppUnInstallingStatus AppStatus = "UnInstalling" +) + +type AppDeployAction string + +const ( + AppInstallAction AppDeployAction = "install" + AppUnInstallAction AppDeployAction = "delete" + AppUpgradeAction AppDeployAction = "upgrade" +) + +type AppConfig struct { + AppName string `json:"AppName,omitempty"` + Version string `json:"Version,omitempty"` + Category string `json:"Category,omitempty"` + Description string `json:"Description,omitempty"` + ChartName string `json:"ChartName,omitempty"` + RepoName string `json:"RepoName,omitempty"` + ReleaseName string `json:"ReleaseName,omitempty"` + RepoURL string `json:"RepoURL,omitempty"` + Namespace string `json:"Namespace,omitempty"` + CreateNamespace bool `json:"CreateNamespace"` + PrivilegedNamespace bool `json:"PrivilegedNamespace"` + Icon string `json:"Icon,omitempty"` + LaunchURL string `json:"LaunchURL,omitempty"` + LaunchUIDescription string `json:"LaunchUIDescription,omitempty"` +} + +type ApplicationInstallRequest struct { + PluginName string `json:"PluginName,omitempty"` + RepoName string `json:"RepoName,omitempty"` + RepoURL string `json:"RepoURL,omitempty"` + ChartName string `json:"ChartName,omitempty"` + Namespace string `json:"Namespace,omitempty"` + ReleaseName string `json:"ReleaseName,omitempty"` + Timeout uint32 `json:"Timeout,omitempty"` + Version string `json:"Version,omitempty"` + ClusterName string `json:"ClusterName,omitempty"` + OverrideValues string `json:"OverrideValues,omitempty"` +} + +type ApplicationDeleteRequest struct { + PluginName string `json:"plugin_name,omitempty"` + Namespace string `json:"namespace,omitempty"` + ReleaseName string `json:"release_name,omitempty"` + Timeout uint32 `json:"timeout,omitempty"` + ClusterName string `json:"cluster_name,omitempty"` +} + +type ClusterGitoptsConfig struct { + Usecase string `json:"usecase,omitempty"` + ProjectUrl string `json:"project_url,omitempty"` + Status string `json:"status,omitempty"` +} diff --git a/capten/model/argocd_types.go b/capten/model/argocd_types.go new file mode 100644 index 00000000..e9dd0588 --- /dev/null +++ b/capten/model/argocd_types.go @@ -0,0 +1,17 @@ +package model + +type ArgoCDProjectStatus string + +const ( + ArgoCDProjectAvailable ArgoCDProjectStatus = "available" + ArgoCDProjectConfigured ArgoCDProjectStatus = "configured" + ArgoCDProjectConfigurationFailed ArgoCDProjectStatus = "configuration-failed" +) + +type ArgoCDProject struct { + Id string `json:"id,omitempty"` + GitProjectId string `json:"git_project_id,omitempty"` + GitProjectUrl string `json:"git_project_url,omitempty"` + Status string `json:"status,omitempty"` + LastUpdateTime string `json:"last_update_time,omitempty"` +} diff --git a/capten/model/config_workflow_types.go b/capten/model/config_workflow_types.go new file mode 100644 index 00000000..81c92851 --- /dev/null +++ b/capten/model/config_workflow_types.go @@ -0,0 +1,31 @@ +package model + +const ( + WorkFlowStatusStarted WorkFlowStatus = "started" + WorkFlowStatusCompleted WorkFlowStatus = "completed" + WorkFlowStatusInProgress WorkFlowStatus = "in-progress" + WorkFlowStatusFailed WorkFlowStatus = "failed" +) + +type ConfigureParameters struct { + Resource string + Action string +} + +type UseCase struct { + Type string `json:"Type,omitempty"` + RepoURL string `json:"RepoURL,omitempty"` + VaultCredIdentifier string `json:"VaultCredIdentifier,omitempty"` + Timeout uint32 `json:"Timeout,omitempty"` + OverrideValues map[string]string `json:"OverrideValues,omitempty"` + PushToDefaultBranch bool `json:"PushToDefaultBranch,omitempty"` +} + +type CrossplaneUseCase struct { + Type string `json:"Type,omitempty"` + RepoURL string `json:"RepoURL,omitempty"` + VaultCredIdentifier string `json:"VaultCredIdentifier,omitempty"` + Timeout uint32 `json:"Timeout,omitempty"` + OverrideValues map[string]string `json:"OverrideValues,omitempty"` + CrossplaneProviders []CrossplaneProvider `json:"ProviderInfo,omitempty"` +} diff --git a/capten/model/configure.go b/capten/model/configure.go deleted file mode 100644 index dd67c24b..00000000 --- a/capten/model/configure.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -type ConfigureParameters struct { - Resource string - Action string -} diff --git a/capten/agent/pkg/model/crossplane_types.go b/capten/model/crossplane_types.go similarity index 69% rename from capten/agent/pkg/model/crossplane_types.go rename to capten/model/crossplane_types.go index fcaa7d1b..6eaf0d6d 100644 --- a/capten/agent/pkg/model/crossplane_types.go +++ b/capten/model/crossplane_types.go @@ -5,6 +5,41 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +type CrossplaneProviderStatus string + +const ( + CrossPlaneProviderOutofSynch CrossplaneProviderStatus = "OutOfSynch" + CrossPlaneProviderInSynch CrossplaneProviderStatus = "InSynch" + CrossPlaneProviderFailedToSynch CrossplaneProviderStatus = "FailedToSynch" +) + +type CrossplaneProvider struct { + Id string `json:"id,omitempty"` + CloudType string `json:"cloud_type,omitempty"` + ProviderName string `json:"provider_name,omitempty"` + CloudProviderId string `json:"cloud_provider_id,omitempty"` + Status string `json:"status,omitempty"` +} + +type CrossplaneProjectStatus string + +const ( + CrossplaneProjectAvailable CrossplaneProjectStatus = "available" + CrossplaneProjectConfigured CrossplaneProjectStatus = "configured" + CrossplaneProjectConfigurationOngoing CrossplaneProjectStatus = "configuration-ongoing" + CrossplaneProjectConfigurationFailed CrossplaneProjectStatus = "configuration-failed" +) + +type CrossplaneProject struct { + Id string `json:"id,omitempty"` + GitProjectId string `json:"git_project_id,omitempty"` + GitProjectUrl string `json:"git_project_url,omitempty"` + Status string `json:"status,omitempty"` + LastUpdateTime string `json:"last_update_time,omitempty"` + WorkflowId string `json:"workflow_id,omitempty"` + WorkflowStatus string `json:"workflow_status,omitempty"` +} + // A ConditionType represents a condition a resource could be in. type ConditionType string diff --git a/capten/model/deploy_workflow_types.go b/capten/model/deploy_workflow_types.go new file mode 100644 index 00000000..d833b376 --- /dev/null +++ b/capten/model/deploy_workflow_types.go @@ -0,0 +1,32 @@ +package model + +// DeployerDeleteRequest defines model for DeployerDeleteRequest. +type DeployerDeleteRequest struct { + // ClusterName Cluster in which to be deleted, default in-build cluster + ClusterName *string `json:"cluster_name,omitempty"` + + // Namespace Namespace chart to be installed + Namespace string `json:"namespace"` + + // PluginName Plugin name + PluginName string `json:"plugin_name"` + + // ReleaseName Release name to be used for install + ReleaseName string `json:"release_name"` + + // Timeout Timeout for the application installation + Timeout int `json:"timeout"` +} + +type ApplicationDeployRequest struct { + PluginName string `json:"PluginName,omitempty"` + RepoName string `json:"RepoName,omitempty"` + RepoURL string `json:"RepoURL,omitempty"` + ChartName string `json:"ChartName,omitempty"` + Namespace string `json:"Namespace,omitempty"` + ReleaseName string `json:"ReleaseName,omitempty"` + Timeout uint32 `json:"Timeout,omitempty"` + Version string `json:"Version,omitempty"` + ClusterName string `json:"ClusterName,omitempty"` + OverrideValues string `json:"OverrideValues,omitempty"` +} diff --git a/capten/model/server.gen.go b/capten/model/server.gen.go deleted file mode 100644 index cf74f960..00000000 --- a/capten/model/server.gen.go +++ /dev/null @@ -1,157 +0,0 @@ -package model - -import "github.com/kube-tarian/kad/capten/agent/pkg/model" - -// AgentRequest defines model for AgentRequest. -type AgentRequest struct { - CustomerId string `json:"customer_id"` - Endpoint string `json:"endpoint"` -} - -// ClimonDeleteRequest defines model for ClimonDeleteRequest. -type ClimonDeleteRequest struct { - // ClusterName Cluster in which to be deleted, default in-build cluster - ClusterName *string `json:"cluster_name,omitempty"` - - // Namespace Namespace chart to be installed - Namespace string `json:"namespace"` - - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // ReleaseName Release name to be used for install - ReleaseName string `json:"release_name"` - - // Timeout Timeout for the application installation - Timeout int `json:"timeout"` -} - -// ClimonPostRequest defines model for ClimonPostRequest. -type ClimonPostRequest struct { - // ChartName Chart name in Repository - ChartName string `json:"chart_name"` - - // ClusterName Cluster in which to be installed, default in-build cluster - ClusterName *string `json:"cluster_name,omitempty"` - - // Namespace Namespace chart to be installed - Namespace string `json:"namespace"` - - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // ReleaseName Release name to be used for install - ReleaseName string `json:"release_name"` - - // RepoName Repository name - RepoName string `json:"repo_name"` - - // RepoUrl Repository URL - RepoUrl string `json:"repo_url"` - - // Timeout Timeout for the application installation - Timeout int `json:"timeout"` - - // Version Version of the chart - Version *string `json:"version,omitempty"` -} - -// ClusterRequest defines model for ClusterRequest. -type ClusterRequest struct { - ClusterName string `json:"cluster_name"` - PluginName string `json:"plugin_name"` -} - -// DeployerDeleteRequest defines model for DeployerDeleteRequest. -type DeployerDeleteRequest struct { - // ClusterName Cluster in which to be deleted, default in-build cluster - ClusterName *string `json:"cluster_name,omitempty"` - - // Namespace Namespace chart to be installed - Namespace string `json:"namespace"` - - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // ReleaseName Release name to be used for install - ReleaseName string `json:"release_name"` - - // Timeout Timeout for the application installation - Timeout int `json:"timeout"` -} - -type ApplicationDeployRequest struct { - PluginName string `json:"PluginName,omitempty"` - RepoName string `json:"RepoName,omitempty"` - RepoURL string `json:"RepoURL,omitempty"` - ChartName string `json:"ChartName,omitempty"` - Namespace string `json:"Namespace,omitempty"` - ReleaseName string `json:"ReleaseName,omitempty"` - Timeout uint32 `json:"Timeout,omitempty"` - Version string `json:"Version,omitempty"` - ClusterName string `json:"ClusterName,omitempty"` - OverrideValues string `json:"OverrideValues,omitempty"` -} - -type UseCase struct { - Type string `json:"Type,omitempty"` - RepoURL string `json:"RepoURL,omitempty"` - VaultCredIdentifier string `json:"VaultCredIdentifier,omitempty"` - Timeout uint32 `json:"Timeout,omitempty"` - OverrideValues map[string]string `json:"OverrideValues,omitempty"` - PushToDefaultBranch bool `json:"PushToDefaultBranch,omitempty"` -} - -type CrossplaneUseCase struct { - Type string `json:"Type,omitempty"` - RepoURL string `json:"RepoURL,omitempty"` - VaultCredIdentifier string `json:"VaultCredIdentifier,omitempty"` - Timeout uint32 `json:"Timeout,omitempty"` - OverrideValues map[string]string `json:"OverrideValues,omitempty"` - CrossplaneProviders []model.CrossplaneProvider `json:"ProviderInfo,omitempty"` -} - -// ProjectDeleteRequest defines model for ProjectDeleteRequest. -type ProjectDeleteRequest struct { - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // ProjectName Project name to be created in plugin - ProjectName string `json:"project_name"` -} - -// ProjectPostRequest defines model for ProjectPostRequest. -type ProjectPostRequest struct { - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // ProjectName Project name to be created in plugin - ProjectName string `json:"project_name"` -} - -// RepositoryDeleteRequest defines model for RepositoryDeleteRequest. -type RepositoryDeleteRequest struct { - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // RepoName Repository to added to plugin - RepoName string `json:"repo_name"` -} - -// RepositoryPostRequest defines model for RepositoryPostRequest. -type RepositoryPostRequest struct { - // PluginName Plugin name - PluginName string `json:"plugin_name"` - - // RepoName Repository to added to plugin - RepoName string `json:"repo_name"` - - // RepoUrl Repository URL - RepoUrl string `json:"repo_url"` -} - -// Response Configuration request response -type Response struct { - Message string `json:"message"` - Status string `json:"status"` -} diff --git a/capten/model/tekton_types.go b/capten/model/tekton_types.go new file mode 100644 index 00000000..22d73671 --- /dev/null +++ b/capten/model/tekton_types.go @@ -0,0 +1,20 @@ +package model + +type TektonProjectStatus string + +const ( + TektonProjectAvailable TektonProjectStatus = "available" + TektonProjectConfigured TektonProjectStatus = "configured" + TektonProjectConfigurationOngoing TektonProjectStatus = "configuration-ongoing" + TektonProjectConfigurationFailed TektonProjectStatus = "configuration-failed" +) + +type TektonProject struct { + Id string `json:"id,omitempty"` + GitProjectId string `json:"git_project_id,omitempty"` + GitProjectUrl string `json:"git_project_url,omitempty"` + Status string `json:"status,omitempty"` + LastUpdateTime string `json:"last_update_time,omitempty"` + WorkflowId string `json:"workflow_id,omitempty"` + WorkflowStatus string `json:"workflow_status,omitempty"` +} diff --git a/capten/tests/argocd-helm-plugin-delete.json b/capten/tests/argocd-helm-plugin-delete.json deleted file mode 100644 index de8b8950..00000000 --- a/capten/tests/argocd-helm-plugin-delete.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "plugin_name": "helm", - "namespace": "default", - "release_name": "argocd", - "timeout": 5, - "version": "" -} diff --git a/capten/tests/argocd-helm-plugin.json b/capten/tests/argocd-helm-plugin.json deleted file mode 100644 index a6a7d382..00000000 --- a/capten/tests/argocd-helm-plugin.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugin_name": "helm", - "repo_name": "argo", - "repo_url": "https://argoproj.github.io/argo-helm", - "chart_name": "argo-cd", - "namespace": "default", - "release_name": "argocd", - "timeout": 5, - "version": "" -} diff --git a/capten/tests/dynamicconfig/development-cass.yaml b/capten/tests/dynamicconfig/development-cass.yaml deleted file mode 100644 index 4b916163..00000000 --- a/capten/tests/dynamicconfig/development-cass.yaml +++ /dev/null @@ -1,3 +0,0 @@ -system.forceSearchAttributesCacheRefreshOnRead: - - value: true # Dev setup only. Please don't turn this on in production. - constraints: {} diff --git a/capten/tests/dynamicconfig/development-sql.yaml b/capten/tests/dynamicconfig/development-sql.yaml deleted file mode 100644 index 8862dfad..00000000 --- a/capten/tests/dynamicconfig/development-sql.yaml +++ /dev/null @@ -1,6 +0,0 @@ -limit.maxIDLength: - - value: 255 - constraints: {} -system.forceSearchAttributesCacheRefreshOnRead: - - value: true # Dev setup only. Please don't turn this on in production. - constraints: {} diff --git a/capten/tests/hello-world-argocd-plugin-delete.json b/capten/tests/hello-world-argocd-plugin-delete.json deleted file mode 100644 index 17809eae..00000000 --- a/capten/tests/hello-world-argocd-plugin-delete.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugin_name": "argocd", - "namespace": "default", - "release_name": "hello-world", - "timeout": 5 -} diff --git a/capten/tests/hello-world-argocd-plugin.json b/capten/tests/hello-world-argocd-plugin.json deleted file mode 100644 index 3e5fc7d2..00000000 --- a/capten/tests/hello-world-argocd-plugin.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugin_name": "argocd", - "action": "install", - "repo_name": "argocd-example", - "repo_url": "https://gitlab.privatecloud.sk/vladoportos/argo-cd-example.git", - "chart_name": "hello-world", - "namespace": "default", - "release_name": "hello-world", - "timeout": 5 -} diff --git a/capten/tests/kind-config.yaml b/capten/tests/kind-config.yaml deleted file mode 100644 index ca91971e..00000000 --- a/capten/tests/kind-config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -kind: Cluster -apiVersion: kind.x-k8s.io/v1alpha4 -nodes: -- role: control-plane - kubeadmConfigPatches: - - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" diff --git a/capten/tests/migrations/cassandra/001_add_tab.down.cql b/capten/tests/migrations/cassandra/001_add_tab.down.cql deleted file mode 100644 index d9fafe86..00000000 --- a/capten/tests/migrations/cassandra/001_add_tab.down.cql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE Agents_by_agent_id; \ No newline at end of file diff --git a/capten/tests/migrations/cassandra/001_add_tab.up.cql b/capten/tests/migrations/cassandra/001_add_tab.up.cql deleted file mode 100644 index d02d6983..00000000 --- a/capten/tests/migrations/cassandra/001_add_tab.up.cql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE Agents_by_agent_id( - agent_name text, - agent_id text, - client_id text, - client_secret text, - additional_info text, - email text, - PRIMARY KEY (agent_id, client_id) -) WITH bloom_filter_fp_chance = 0.01 - AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} - AND comment = '' - AND compaction = {'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'tombstone_compaction_interval': '1800', 'tombstone_threshold': '0.01', 'unchecked_tombstone_compaction': 'true'} - AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} - AND crc_check_chance = 1.0 - AND default_time_to_live = 0 - AND gc_grace_seconds = 3600 - AND max_index_interval = 2048 - AND memtable_flush_period_in_ms = 0 - AND min_index_interval = 128 - AND speculative_retry = '99PERCENTILE'; - diff --git a/charts/kad/Chart.yaml b/charts/kad/Chart.yaml index 30835f57..bcb68b83 100644 --- a/charts/kad/Chart.yaml +++ b/charts/kad/Chart.yaml @@ -15,10 +15,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.2.11 +version: 0.2.12 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.21.0" +appVersion: "1.22.0" diff --git a/charts/kad/templates/deployment-worker-deployment.yaml b/charts/kad/templates/deployment-worker-deployment.yaml index ad332e7c..0034ef84 100644 --- a/charts/kad/templates/deployment-worker-deployment.yaml +++ b/charts/kad/templates/deployment-worker-deployment.yaml @@ -40,14 +40,6 @@ spec: - name: http containerPort: {{ .Values.service.port }} protocol: TCP - livenessProbe: - httpGet: - path: /status - port: http - readinessProbe: - httpGet: - path: /status - port: http env: - name: LOG_LEVEL value: {{ .Values.env.logLevel }} diff --git a/dockerfiles/agent/Dockerfile b/dockerfiles/agent/Dockerfile index 44f659f5..5aedf2c1 100644 --- a/dockerfiles/agent/Dockerfile +++ b/dockerfiles/agent/Dockerfile @@ -1,14 +1,14 @@ -FROM golang:1.19.4 AS builder +FROM golang:1.21.3 AS builder WORKDIR / COPY ./capten ./ RUN rm -rf vendor RUN go mod download -RUN CGO_ENABLED=0 go build -o ./build/agent agent/cmd/agent/main.go +RUN CGO_ENABLED=0 go build -o ./build/agent agent/cmd/main.go FROM scratch COPY --from=builder ./build/agent agent -COPY ./capten/cassandra/ cassandra/ +COPY ./capten/database/cassandra/ cassandra/ USER 65532:65532 ENTRYPOINT ["./agent"] diff --git a/dockerfiles/config-worker/Dockerfile b/dockerfiles/config-worker/Dockerfile index 36a8e55b..9e9c12e9 100644 --- a/dockerfiles/config-worker/Dockerfile +++ b/dockerfiles/config-worker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.4 AS builder +FROM golang:1.21.3 AS builder WORKDIR / COPY ./capten ./ RUN rm -rf vendor diff --git a/dockerfiles/deployment-worker/Dockerfile b/dockerfiles/deployment-worker/Dockerfile index fac59af6..d498be4a 100644 --- a/dockerfiles/deployment-worker/Dockerfile +++ b/dockerfiles/deployment-worker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.4 AS builder +FROM golang:1.21.3 AS builder WORKDIR / COPY ./capten ./ RUN rm -rf vendor diff --git a/dockerfiles/server/Dockerfile b/dockerfiles/server/Dockerfile index a0678a34..977e8639 100644 --- a/dockerfiles/server/Dockerfile +++ b/dockerfiles/server/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.4 AS builder +FROM golang:1.21.3 AS builder WORKDIR / COPY ./server ./ RUN rm -rf vendor diff --git a/server/go.mod b/server/go.mod index 0bc6bfd4..61716d0a 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,6 +1,6 @@ module github.com/kube-tarian/kad/server -go 1.19 +go 1.21 require ( github.com/gocql/gocql v1.3.1 diff --git a/server/go.sum b/server/go.sum index 9585dae2..c0a709fe 100644 --- a/server/go.sum +++ b/server/go.sum @@ -1,8 +1,11 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3 h1:mw6pDQqv38/WGF1cO/jF5t/jyAJ2yi7CmtFLLO5tGFI= +github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/hcsshim v0.8.16 h1:8/auA4LFIZFTGrqfKhGBSXwM6/4X1fHa/xniyEHu8ac= +github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= @@ -10,21 +13,28 @@ github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCS github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= +github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68 h1:hkGVFjz+plgr5UfxZUTPFbUFIF/Km6/s+RVRIRHLrrY= +github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE= github.com/containerd/containerd v1.5.0-beta.4 h1:zjz4MOAOFgdBlwid2nNUlJ3YLpVi/97L36lfMYJex60= +github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= +github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v20.10.7+incompatible h1:Z6O9Nhsjv+ayUEeI1IojKbYcsGdgYSNqxe1s2MYzUhQ= +github.com/docker/docker v20.10.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= +github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -39,6 +49,7 @@ github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a github.com/gocql/gocql v1.3.1 h1:BTwM4rux+ah5G3oH6/MQa+tur/TDd/XAAOXDxBBs7rg= github.com/gocql/gocql v1.3.1/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -68,6 +79,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -139,12 +151,19 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/sys/mount v0.2.0 h1:WhCW5B355jtxndN5ovugJlMFJawbUODuW8fSnEH6SSM= +github.com/moby/sys/mount v0.2.0/go.mod h1:aAivFE2LB3W4bACsUXChRHQ0qKWsetY4Y9V7sxOougM= github.com/moby/sys/mountinfo v0.4.1 h1:1O+1cHA1aujwEwwVMa2Xm2l+gIpUHyd3+D+d7LZh1kM= +github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 h1:rzf0wL0CHVc8CEsgyygG0Mn9CNCCPZqOPaz8RiiHYQk= +github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= +github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= +github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v1.0.0-rc95 h1:RMuWVfY3E1ILlVsC3RhIq38n4sJtlOFwU9gfFZSqrd0= +github.com/opencontainers/runc v1.0.0-rc95/go.mod h1:z+bZxa/+Tz/FmYVWkhUajJdzFeOqjc5vrqskhVyHGUM= github.com/ory/client-go v1.1.49 h1:cHeiCxbtFOY+o/nQMpTlWLa6DFdTPfmrqyqcau/c+S4= github.com/ory/client-go v1.1.49/go.mod h1:txO25o+LB3I03DNgHV679Jnpx19/AYKIb2CY+GHQJGw= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -177,7 +196,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/testcontainers/testcontainers-go v0.11.1 h1:FiYsB83LSGbiawoV8TpAZGfcCUbtaeeg1SXqEKUxh08= +github.com/testcontainers/testcontainers-go v0.11.1/go.mod h1:/V0UVq+1e7NWYoqTPog179clf0Qp9TOyp4EcXaEFQz8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= diff --git a/server/pkg/api/plugin_crossplane_provider_apis.go b/server/pkg/api/plugin_crossplane_provider_apis.go index 44e5fef5..9109e050 100644 --- a/server/pkg/api/plugin_crossplane_provider_apis.go +++ b/server/pkg/api/plugin_crossplane_provider_apis.go @@ -174,22 +174,25 @@ func (s *Server) GetCrossplanProviders(ctx context.Context, request *captenplugi response, err := agent.GetCaptenPluginsClient().GetCrossplanProviders(context.Background(), request) if err != nil { - s.log.Errorf("failed to get the Cluster CrossplanProvider, %v", err) + s.log.Errorf("failed to get the Cluster Crossplane Providers, %v", err) return &captenpluginspb.GetCrossplanProvidersResponse{ Status: captenpluginspb.StatusCode_INTERNAL_ERROR, StatusMessage: "failed to get the Cluster CrossplanProvider", }, nil } - if response.Status != captenpluginspb.StatusCode_OK { - s.log.Errorf("failed to get the ClusterProject") + if response.Status == captenpluginspb.StatusCode_NOT_FOUND { + response.Providers = []*captenpluginspb.CrossplaneProvider{} + + } else if response.Status != captenpluginspb.StatusCode_OK { + s.log.Errorf("failed to get the Crossplane Providers") return &captenpluginspb.GetCrossplanProvidersResponse{ Status: captenpluginspb.StatusCode_INTERNAL_ERROR, StatusMessage: "failed to get the Cluster CrossplanProvider", }, nil } - s.log.Infof("Fetched %d Git projects request for cluster %s processed, [org: %s]", + s.log.Infof("Fetched %d Crossplane Providers for cluster %s processed, [org: %s]", len(response.Providers), clusterId, orgId) return &captenpluginspb.GetCrossplanProvidersResponse{ Providers: response.Providers,