Skip to content

Commit

Permalink
feat: environment token (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Feb 20, 2024
1 parent 426d4da commit 90cc38a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func CreateService(cl *pkgtypes.Cluster, serviceName string, appDef *pkgtypes.Gi
secretStoreRef := "vault-kv-secret"
project := "default"
clusterDestination := "in-cluster"
environment := "mgmt"

if req.WorkloadClusterName != "" {
clusterName = req.WorkloadClusterName
secretStoreRef = fmt.Sprintf("%s-vault-kv-secret", req.WorkloadClusterName)
project = clusterName
clusterDestination = clusterName
environment = req.Environment
}

registryPath := getRegistryPath(clusterName, cl.CloudProvider, req.IsTemplate)
Expand Down Expand Up @@ -165,7 +167,7 @@ func CreateService(cl *pkgtypes.Cluster, serviceName string, appDef *pkgtypes.Gi

if !req.IsTemplate {
//Create Tokens
gitopsKubefirstTokens := utils.CreateTokensFromDatabaseRecord(cl, registryPath, secretStoreRef, project, clusterDestination)
gitopsKubefirstTokens := utils.CreateTokensFromDatabaseRecord(cl, registryPath, secretStoreRef, project, clusterDestination, environment)

//Detokenize App Template
err = providerConfigs.DetokenizeGitGitops(catalogServiceFolder, gitopsKubefirstTokens, cl.GitProtocol, cl.CloudflareAuth.OriginCaIssuerKey != "")
Expand Down Expand Up @@ -227,7 +229,7 @@ func CreateService(cl *pkgtypes.Cluster, serviceName string, appDef *pkgtypes.Gi
return err
}

if excludeArgoSync {
if excludeArgoSync || req.IsTemplate {
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/providerConfigs/detokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func detokenizeGitops(path string, tokens *GitopsDirectoryValues, gitProtocol st
newContents = strings.Replace(newContents, "<SECRET_STORE_REF>", tokens.SecretStoreRef, -1)
newContents = strings.Replace(newContents, "<PROJECT>", tokens.Project, -1)
newContents = strings.Replace(newContents, "<CLUSTER_DESTINATION>", tokens.ClusterDestination, -1)
newContents = strings.Replace(newContents, "<ENVIRONMENT>", tokens.Environment, -1)

//origin issuer defines which annotations should be on ingresses
if useCloudflareOriginIssuer {
Expand Down
1 change: 1 addition & 0 deletions pkg/providerConfigs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type GitopsDirectoryValues struct {
SecretStoreRef string
Project string
ClusterDestination string
Environment string

AwsIamArnAccountRoot string
AwsKmsKeyId string
Expand Down
1 change: 1 addition & 0 deletions pkg/types/gitopsCatalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type GitopsCatalogAppCreateRequest struct {
SecretKeys []GitopsCatalogAppKeys `bson:"secret_keys,omitempty" json:"secret_keys,omitempty"`
ConfigKeys []GitopsCatalogAppKeys `bson:"config_keys,omitempty" json:"config_keys,omitempty"`
WorkloadClusterName string `bson:"workload_cluster_name" json:"workload_cluster_name"`
Environment string `bson:"environment" json:"environment"`
}

type GitopsCatalogAppDeleteRequest struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/thanhpk/randstr"
)

func CreateTokensFromDatabaseRecord(cl *pkgtypes.Cluster, registryPath string, secretStoreRef string, project string, clusterDestination string) *providerConfigs.GitopsDirectoryValues {
func CreateTokensFromDatabaseRecord(cl *pkgtypes.Cluster, registryPath string, secretStoreRef string, project string, clusterDestination string, environment string) *providerConfigs.GitopsDirectoryValues {
env, _ := env.GetEnv(constants.SilenceGetEnv)

fullDomainName := ""
Expand Down Expand Up @@ -93,6 +93,7 @@ func CreateTokensFromDatabaseRecord(cl *pkgtypes.Cluster, registryPath string, s
SecretStoreRef: secretStoreRef,
Project: project,
ClusterDestination: clusterDestination,
Environment: environment,

GitDescription: fmt.Sprintf("%s hosted git", cl.GitProvider),
GitNamespace: "N/A",
Expand Down

0 comments on commit 90cc38a

Please sign in to comment.