Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cd test #384

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions capten/agent/internal/api/plugin_tekton_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion capten/common-pkg/plugins/argocd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
29 changes: 26 additions & 3 deletions capten/config-worker/internal/app_config/app_git_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
25 changes: 4 additions & 21 deletions capten/config-worker/internal/crossplane/config_cluster_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion capten/config-worker/internal/tekton/argocd_app_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
46 changes: 25 additions & 21 deletions capten/config-worker/internal/tekton/config_tekton_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<NAME>", req.PipelineName)), req.PipelineName, cp.cfg.DomainName)
strings.ReplaceAll(cp.pluginConfig.PipelineSyncUpdate.PipelineValues, "<NAME>", req.PipelineName)), req.PipelineName, gloablVal[appconfig.DomainName])
if err != nil {
return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to updatePipelineTemplate")
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading