diff --git a/capten/agent/internal/api/plugin_tekton_pipelines.go b/capten/agent/internal/api/plugin_tekton_pipelines.go index f4ee93cd..0e5b7f80 100644 --- a/capten/agent/internal/api/plugin_tekton_pipelines.go +++ b/capten/agent/internal/api/plugin_tekton_pipelines.go @@ -61,23 +61,23 @@ func (a *Agent) CreateTektonPipeline(ctx context.Context, request *captenplugins }, nil } - _, err = a.as.GetCrossplaneProjectForID(request.CrossPlaneGitProjectId) - if err != nil { - a.log.Infof("failed to get crossplane git project %s, %v", request.CrossPlaneGitProjectId, err) - return &captenpluginspb.CreateTektonPipelineResponse{ - Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, - StatusMessage: "failed to get crossplane git project", - }, nil - } - - _, err = a.as.GetManagedClusterForID(request.ManagedClusterId) - if err != nil { - a.log.Infof("failed to get managedCluster id %s, %v", request.ManagedClusterId, err) - return &captenpluginspb.CreateTektonPipelineResponse{ - Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, - StatusMessage: "failed to get managedCluster id", - }, nil - } + // _, err = a.as.GetCrossplaneProjectForID(request.CrossPlaneGitProjectId) + // if err != nil { + // a.log.Infof("failed to get crossplane git project %s, %v", request.CrossPlaneGitProjectId, err) + // return &captenpluginspb.CreateTektonPipelineResponse{ + // Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, + // StatusMessage: "failed to get crossplane git project", + // }, nil + // } + + // _, err = a.as.GetManagedClusterForID(request.ManagedClusterId) + // if err != nil { + // a.log.Infof("failed to get managedCluster id %s, %v", request.ManagedClusterId, err) + // return &captenpluginspb.CreateTektonPipelineResponse{ + // Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, + // StatusMessage: "failed to get managedCluster id", + // }, nil + // } a.log.Infof("Add Create Tekton Pipeline registry %s request received", request.PipelineName) @@ -142,23 +142,23 @@ func (a *Agent) UpdateTektonPipeline(ctx context.Context, request *captenplugins }, nil } - _, err = a.as.GetCrossplaneProjectForID(request.CrossPlaneGitProjectId) - if err != nil { - a.log.Infof("failed to get crossplane git project %s, %v", request.CrossPlaneGitProjectId, err) - return &captenpluginspb.UpdateTektonPipelineResponse{ - Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, - StatusMessage: "failed to get crossplane git project", - }, nil - } - - _, err = a.as.GetManagedClusterForID(request.ManagedClusterId) - if err != nil { - a.log.Infof("failed to get managedCluster id %s, %v", request.ManagedClusterId, err) - return &captenpluginspb.UpdateTektonPipelineResponse{ - Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, - StatusMessage: "failed to get managedCluster id", - }, nil - } + // _, err = a.as.GetCrossplaneProjectForID(request.CrossPlaneGitProjectId) + // if err != nil { + // a.log.Infof("failed to get crossplane git project %s, %v", request.CrossPlaneGitProjectId, err) + // return &captenpluginspb.UpdateTektonPipelineResponse{ + // Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, + // StatusMessage: "failed to get crossplane git project", + // }, nil + // } + + // _, err = a.as.GetManagedClusterForID(request.ManagedClusterId) + // if err != nil { + // a.log.Infof("failed to get managedCluster id %s, %v", request.ManagedClusterId, err) + // return &captenpluginspb.UpdateTektonPipelineResponse{ + // Status: captenpluginspb.StatusCode_INVALID_ARGUMENT, + // StatusMessage: "failed to get managedCluster id", + // }, nil + // } a.log.Infof("Update tekton pipelines project, %s request recieved", request.Id) @@ -310,17 +310,17 @@ func (a *Agent) configureTektonPipelinesGitRepo(req *model.TektonPipeline, actio return "", fmt.Errorf("failed to send event to workflow to configure %s, %v", req.GitProjectId, err) } - extraGitProject, err := a.as.GetCrossplaneProjectForID(req.CrossplaneGitProjectId) - if err != nil { - a.log.Infof("failed to get crossplane git project %s, %v", req.CrossplaneGitProjectId, err) - return "", fmt.Errorf("failed to get crossplane git project %s, %v", req.CrossplaneGitProjectId, err) - } + // extraGitProject, err := a.as.GetCrossplaneProjectForID(req.CrossplaneGitProjectId) + // if err != nil { + // a.log.Infof("failed to get crossplane git project %s, %v", req.CrossplaneGitProjectId, err) + // return "", fmt.Errorf("failed to get crossplane git project %s, %v", req.CrossplaneGitProjectId, err) + // } - managedCluster, err := a.as.GetManagedClusterForID(req.ManagedClusterId) - if err != nil { - a.log.Infof("failed to get managed clsuter %s, %v", req.ManagedClusterId, err) - return "", fmt.Errorf("failed to get managed clsuter %s, %v", req.ManagedClusterId, err) - } + // managedCluster, err := a.as.GetManagedClusterForID(req.ManagedClusterId) + // if err != nil { + // a.log.Infof("failed to get managed clsuter %s, %v", req.ManagedClusterId, err) + // return "", fmt.Errorf("failed to get managed clsuter %s, %v", req.ManagedClusterId, err) + // } containerRegURLIdMap := make(map[string]string) containerRegURLIdMap[containerReg.Id] = containerReg.RegistryUrl @@ -331,8 +331,8 @@ func (a *Agent) configureTektonPipelinesGitRepo(req *model.TektonPipeline, actio captenmodel.Git: {Identifier: gitProjectEntityName, Id: req.GitProjectId}, captenmodel.Container: {Identifier: containerRegEntityName, Id: req.ContainerRegId[0], Url: containerReg.RegistryUrl}, - captenmodel.ManagedCluster: {Identifier: ManagedClusterEntityName, Id: req.ManagedClusterId, Url: managedCluster.ClusterName}, - captenmodel.ExtraGitProject: {Identifier: gitProjectEntityName, Id: req.CrossplaneGitProjectId, Url: extraGitProject.GitProjectUrl}, + captenmodel.ManagedCluster: {Identifier: ManagedClusterEntityName, Id: req.ManagedClusterId, Url: "test"}, + captenmodel.ExtraGitProject: {Identifier: gitProjectEntityName, Id: req.CrossplaneGitProjectId, Url: "test"}, }} wd := workers.NewConfig(a.tc, a.log) diff --git a/capten/common-pkg/plugins/argocd/client.go b/capten/common-pkg/plugins/argocd/client.go index eb27543f..185128ff 100644 --- a/capten/common-pkg/plugins/argocd/client.go +++ b/capten/common-pkg/plugins/argocd/client.go @@ -40,12 +40,13 @@ func GetConfig(logger logging.Logger) (*Configuration, error) { cfg.Password = password } - if !cfg.IsSSLEnabled { // TODO: Configure SSL certificates logger.Errorf("SSL not yet supported, continuing with insecure verify true") } + logger.Info("DATA : ", cfg.ServiceURL, cfg.Password, cfg.Username) + return cfg, nil } diff --git a/capten/config-worker/internal/app_config/app_git_helper.go b/capten/config-worker/internal/app_config/app_git_helper.go index a32a24b3..455439e8 100644 --- a/capten/config-worker/internal/app_config/app_git_helper.go +++ b/capten/config-worker/internal/app_config/app_git_helper.go @@ -11,9 +11,11 @@ import ( "github.com/intelops/go-common/credentials" "github.com/intelops/go-common/logging" "github.com/kelseyhightower/envconfig" + "github.com/kube-tarian/kad/capten/common-pkg/credential" "github.com/kube-tarian/kad/capten/common-pkg/k8s" "github.com/kube-tarian/kad/capten/common-pkg/plugins/git" "github.com/pkg/errors" + "gopkg.in/yaml.v2" "github.com/kube-tarian/kad/capten/common-pkg/plugins/argocd" ) @@ -26,8 +28,9 @@ const ( kubeConfig = "kubeconfig" k8sEndpoint = "endpoint" k8sClusterCA = "clusterCA" - cosignKey = "cosign.key" - cosignPub = "cosign.pub" + CosignKey = "cosign.key" + CosignPub = "cosign.pub" + DomainName = "DomainName" ) type Config struct { @@ -92,6 +95,26 @@ func (ca *AppGitConfigHelper) GetClusterCreds(ctx context.Context, entityName, p return cred[kubeConfig], cred[k8sClusterCA], cred[k8sEndpoint], nil } +func (ca *AppGitConfigHelper) GetClusterGlobalValues(ctx context.Context, val map[string]string) (map[string]string, error) { + cred, err := credential.GetClusterGlobalValues(ctx) + if err != nil { + return nil, err + } + + var gvMap map[string]interface{} + + decoder := yaml.NewDecoder(strings.NewReader(cred)) + if err := decoder.Decode(&gvMap); err != nil { + return nil, err + } + + for key, value := range gvMap { + val[key] = value.(string) + } + + return val, nil +} + func (ca *AppGitConfigHelper) GetCosingKeys(ctx context.Context, entityName, projectId string) (string, string, error) { credReader, err := credentials.NewCredentialReader(ctx) if err != nil { @@ -107,7 +130,7 @@ func (ca *AppGitConfigHelper) GetCosingKeys(ctx context.Context, entityName, pro return "", "", err } - return cred[cosignKey], cred[cosignPub], nil + return cred[CosignKey], cred[CosignPub], nil } func (ca *AppGitConfigHelper) GetContainerRegCreds(ctx context.Context, entityName, projectId string) (string, string, error) { diff --git a/capten/config-worker/internal/crossplane/config_cluster_updates.go b/capten/config-worker/internal/crossplane/config_cluster_updates.go index 626d1297..38bd9289 100644 --- a/capten/config-worker/internal/crossplane/config_cluster_updates.go +++ b/capten/config-worker/internal/crossplane/config_cluster_updates.go @@ -6,11 +6,10 @@ import ( "fmt" "os" "path/filepath" - "strings" "github.com/intelops/go-common/logging" - "github.com/kube-tarian/kad/capten/common-pkg/credential" "github.com/kube-tarian/kad/capten/common-pkg/k8s" + appConf "github.com/kube-tarian/kad/capten/config-worker/internal/app_config" fileutil "github.com/kube-tarian/kad/capten/config-worker/internal/file_util" "github.com/kube-tarian/kad/capten/model" agentmodel "github.com/kube-tarian/kad/capten/model" @@ -287,27 +286,11 @@ func removeClusterValues(valuesFileName, clusterName string) error { func (cp *CrossPlaneApp) prepareTemplateVaules(ctx context.Context, clusterName string) (map[string]string, error) { val := map[string]string{ - "DomainName": cp.cfg.DomainName, - "ClusterName": clusterName, + appConf.DomainName: cp.cfg.DomainName, + "ClusterName": clusterName, } - cred, err := credential.GetClusterGlobalValues(ctx) - if err != nil { - return nil, err - } - - var gvMap map[string]interface{} - - decoder := yaml.NewDecoder(strings.NewReader(cred)) - if err := decoder.Decode(&gvMap); err != nil { - return nil, err - } - - for key, value := range gvMap { - val[key] = value.(string) - } - - return val, nil + return cp.helper.GetClusterGlobalValues(ctx, val) } func prepareClusterData(clusterName, endpoint string, defaultApps []DefaultApps) Cluster { diff --git a/capten/config-worker/internal/tekton/argocd_app_values.go b/capten/config-worker/internal/tekton/argocd_app_values.go index b24f054d..f8a2aba8 100644 --- a/capten/config-worker/internal/tekton/argocd_app_values.go +++ b/capten/config-worker/internal/tekton/argocd_app_values.go @@ -45,7 +45,6 @@ type TektonConfigValues struct { type TektonPieplineConfigValues struct { PipelineName string `json:"pipelineName,omitempty"` IngressDomainName string `json:"ingressDomainName,omitempty"` - TektonDashboard string `json:"tektonDashboard,omitempty"` Namespace string `json:"namespace,omitempty"` SecretName *[]SecretNames `json:"secretName,omitempty"` } diff --git a/capten/config-worker/internal/tekton/config_tekton_app.go b/capten/config-worker/internal/tekton/config_tekton_app.go index 81ea9b8f..d2ca4334 100644 --- a/capten/config-worker/internal/tekton/config_tekton_app.go +++ b/capten/config-worker/internal/tekton/config_tekton_app.go @@ -123,8 +123,14 @@ func (cp *TektonApp) configureProjectAndApps(ctx context.Context, req *model.Tek return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to updateArgoCDTemplate") } + gloablVal, err := cp.helper.GetClusterGlobalValues(ctx, map[string]string{ + appconfig.DomainName: cp.cfg.DomainName}) + if err != nil { + return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to get clusetr gloablValues") + } + err = updatePipelineTemplate(filepath.Join(customerRepo, - strings.ReplaceAll(cp.pluginConfig.PipelineSyncUpdate.PipelineValues, "", req.PipelineName)), req.PipelineName, cp.cfg.DomainName) + strings.ReplaceAll(cp.pluginConfig.PipelineSyncUpdate.PipelineValues, "", req.PipelineName)), req.PipelineName, gloablVal[appconfig.DomainName]) if err != nil { return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to updatePipelineTemplate") } @@ -301,7 +307,7 @@ func (cp *TektonApp) createOrUpdateSecrets(ctx context.Context, req *model.Tekto } if err := k8sclient.CreateOrUpdateSecret(ctx, pipelineNamespace, cosignSecName, - v1.SecretTypeOpaque, map[string][]byte{"COSIGN_KEY": []byte(key), "COSIGN_PUB": []byte(pub)}, + v1.SecretTypeOpaque, map[string][]byte{appconfig.CosignKey: []byte(key), appconfig.CosignPub: []byte(pub)}, map[string]string{}); err != nil { return fmt.Errorf("failed to create/update cosign-keys k8s secret, %v", err) } @@ -344,6 +350,7 @@ func (cp *TektonApp) createOrUpdateSecrets(ctx context.Context, req *model.Tekto if err != nil { return fmt.Errorf("failed to get argo-cd secret, %v", err) } + log.Info("DATA : ", cfg.ServiceURL, cfg.Password, cfg.Username) strdata["SERVER_URL"] = []byte(cfg.ServiceURL) strdata["USERNAME"] = []byte(cfg.Username) strdata["PASSWORD"] = []byte(cfg.Password) @@ -352,23 +359,22 @@ func (cp *TektonApp) createOrUpdateSecrets(ctx context.Context, req *model.Tekto return fmt.Errorf("failed to create/update k8s secret, %v", err) } case extraConfig: - username, token, err := cp.helper.GetGitCreds(ctx, req.CredentialIdentifiers[agentmodel.ExtraGitProject].Id) - if err != nil { - return fmt.Errorf("failed to get git secret, %v", err) - } - - kubeConfig, kubeCa, kubeEndpoint, err := cp.helper.GetClusterCreds(ctx, req.CredentialIdentifiers[agentmodel.ManagedCluster].Identifier, req.CredentialIdentifiers[agentmodel.ManagedCluster].Id) - if err != nil { - return fmt.Errorf("failed to get GetClusterCreds, %v", err) - } - strdata["GIT_USER_NAME"] = []byte(username) - strdata["GIT_TOKEN"] = []byte(token) + // username, token, err := cp.helper.GetGitCreds(ctx, req.CredentialIdentifiers[agentmodel.ExtraGitProject].Id) + // if err != nil { + // return fmt.Errorf("failed to get git secret, %v", err) + // } + + // kubeConfig, kubeCa, kubeEndpoint, err := cp.helper.GetClusterCreds(ctx, req.CredentialIdentifiers[agentmodel.ManagedCluster].Identifier, req.CredentialIdentifiers[agentmodel.ManagedCluster].Id) + // if err != nil { + // return fmt.Errorf("failed to get GetClusterCreds, %v", err) + // } + strdata["GIT_USER_NAME"] = []byte("username") + strdata["GIT_TOKEN"] = []byte("token") strdata["GIT_PROJECT_URL"] = []byte(req.CredentialIdentifiers[agentmodel.ExtraGitProject].Url) - strdata["APP_CONFIG_PATH"] = []byte(filepath.Join(cp.crossplanConfig.ClusterEndpointUpdates.DefaultAppValuesPath, req.CredentialIdentifiers[agentmodel.ManagedCluster].Url)) - strdata["CLUSTER_CA"] = []byte(kubeCa) - strdata["CLUSTER_ENDPOINT"] = []byte(kubeEndpoint) - strdata["CLUSTER_CONFIG"] = []byte(kubeConfig) - + strdata["APP_CONFIG_PATH"] = []byte(filepath.Join(cp.crossplanConfig.ClusterEndpointUpdates.ClusterDefaultAppValuesPath, req.CredentialIdentifiers[agentmodel.ManagedCluster].Url, "apps")) + strdata["CLUSTER_CA"] = []byte("kubeCa") + strdata["CLUSTER_ENDPOINT"] = []byte("kubeEndpoint") + strdata["CLUSTER_CONFIG"] = []byte("kubeConfig") if err := k8sclient.CreateOrUpdateSecret(ctx, pipelineNamespace, secName, v1.SecretTypeOpaque, strdata, nil); err != nil { return fmt.Errorf("failed to create/update k8s secret, %v", err) @@ -512,10 +518,8 @@ func updatePipelineTemplate(valuesFileName, pipelineName, domainName string) err return err } - // GET dashboard and ingress domain suffix. - tektonPipelineConfig.IngressDomainName = model.TektonHostName + "." + domainName + tektonPipelineConfig.IngressDomainName = domainName tektonPipelineConfig.PipelineName = pipelineName - tektonPipelineConfig.TektonDashboard = "http://" + tektonPipelineConfig.IngressDomainName secretName := []SecretNames{} for _, secret := range secrets {