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

fix(byok): Correctly remove qovery section from base helm values #375

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
go test -tags testing ./...
32 changes: 18 additions & 14 deletions pkg/cluster/selfmanaged/install_self_managed_cluster_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/qovery/qovery-cli/pkg/cluster"
Expand Down Expand Up @@ -153,31 +154,26 @@ func (service *InstallSelfManagedClusterService) InstallCluster() (*string, erro
if err != nil {
return nil, err
}
clusterHelmValuesContent := *resultClusterHelmValuesContent
helmValues := *resultClusterHelmValuesContent

// inject the email for Cert Manager
clusterHelmValuesContent = strings.ReplaceAll(clusterHelmValuesContent, "[email protected]", email)

finalClusterHelmValuesContent := fmt.Sprintf("%s\n", clusterHelmValuesContent)
helmValues = strings.ReplaceAll(helmValues, "[email protected]", email)
helmValues = fmt.Sprintf("%s\n", helmValues)

// trim lines if they start with "qovery:" or if they contain "set-by-customer"
content, err := service.selfManagedClusterService.GetBaseHelmValuesContent(cloudProviderType)
qoveryHelmValues, err := service.selfManagedClusterService.GetBaseHelmValuesContent(cloudProviderType)
if err != nil {
return nil, err
}
for _, line := range strings.Split(*content, "\n") {
if strings.HasPrefix(line, "qovery:") || strings.Contains(line, "set-by-customer") {
continue
}
finalClusterHelmValuesContent += line + "\n"
}

helmValues += stripQoverySection(*qoveryHelmValues)

if strings.Contains(kubernetesType, "Azure") {
contentWithAKSValues, err := injectAzureAKSValues(finalClusterHelmValuesContent)
contentWithAKSValues, err := injectAzureAKSValues(helmValues)
if err != nil {
return nil, err
}
finalClusterHelmValuesContent = *contentWithAKSValues
helmValues = *contentWithAKSValues
}

// generate the helm values file and output it to the user to ./values-<cluster-name>.yaml
Expand All @@ -198,7 +194,7 @@ func (service *InstallSelfManagedClusterService) InstallCluster() (*string, erro
return nil, err
}

err = service.fileWriterService.WriteFile(helmValuesFileName, []byte(finalClusterHelmValuesContent), 0644)
err = service.fileWriterService.WriteFile(helmValuesFileName, []byte(helmValues), 0644)

if err != nil {
return nil, err
Expand All @@ -209,6 +205,14 @@ func (service *InstallSelfManagedClusterService) InstallCluster() (*string, erro
return nil, nil
}

func stripQoverySection(qoveryHelmValues string) string {
// Erase the qovery: yaml section to replace it with correct fetched values for this cluster
// We can't use yaml parser here, because the yaml file contains anchor (&toto *toto) and parsing it will cause those
// anchors to be replaced with the incorrect values...
re := regexp.MustCompile("(?m)^qovery:\n( .*\n)+")
return re.ReplaceAllString(qoveryHelmValues, "")
}

func outputCommandsToInstallQoveryOnCluster(helmValuesFileName string) {
// give instruction to the user to install the cluster
utils.Println("")
Expand Down
140 changes: 140 additions & 0 deletions pkg/cluster/selfmanaged/install_self_managed_cluster_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,143 @@ func TestReuseExistingCluster(t *testing.T) {
assert.Nil(t, err)
})
}

func TestStripQoverySection(t *testing.T) {
helmValues := `
services:
qovery:
qovery-cluster-agent:
enabled: true
qovery-shell-agent:
enabled: true
qovery-engine:
enabled: true
qovery-priority-class:
enabled: true
ingress:
ingress-nginx:
enabled: true
dns:
external-dns:
enabled: true
logging:
loki:
enabled: true
promtail:
enabled: true
certificates:
cert-manager:
enabled: true
cert-manager-configs:
enabled: true
qovery-cert-manager-webhook:
enabled: true
observability:
metrics-server:
enabled: true
aws:
q-storageclass-aws:
enabled: true
aws-ebs-csi-driver:
enabled: false
aws-load-balancer-controller:
enabled: false
gcp:
q-storageclass-gcp:
enabled: false
scaleway:
q-storageclass-scaleway:
enabled: false
qovery:
clusterId: &clusterId set-by-customer
clusterShortId: &clusterShortId set-by-customer
organizationId: &organizationId set-by-customer
jwtToken: &jwtToken set-by-customer
rootDomain: &rootDomain set-by-customer
domain: &domain set-by-customer
domainWildcard: &domainWildcard set-by-customer
qoveryDnsUrl: &qoveryDnsUrl set-by-customer
agentGatewayUrl: &agentGatewayUrl set-by-customer
engineGatewayUrl: &engineGatewayUrl set-by-customer
lokiUrl: &lokiUrl set-by-customer
promtailLokiUrl: &promtailLokiUrl set-by-customer
acmeEmailAddr: &acmeEmailAddr set-by-customer
externalDnsPrefix: &externalDnsPrefix set-by-customer
architectures: &architectures set-by-customer
engineVersion: &engineVersion set-by-customer
shellAgentVersion: &shellAgentVersion set-by-customer
clusterAgentVersion: &clusterAgentVersion set-by-customer
qovery-cluster-agent:
fullnameOverride: qovery-shell-agent
image:
tag: *clusterAgentVersion
environmentVariables:
CLUSTER_ID: *clusterId
CLUSTER_JWT_TOKEN: *jwtToken
GRPC_SERVER: *agentGatewayUrl
LOKI_URL: *lokiUrl
ORGANIZATION_ID: *organizationId
useSelfSignCertificate: true
`
resultHelmValues := `
services:
qovery:
qovery-cluster-agent:
enabled: true
qovery-shell-agent:
enabled: true
qovery-engine:
enabled: true
qovery-priority-class:
enabled: true
ingress:
ingress-nginx:
enabled: true
dns:
external-dns:
enabled: true
logging:
loki:
enabled: true
promtail:
enabled: true
certificates:
cert-manager:
enabled: true
cert-manager-configs:
enabled: true
qovery-cert-manager-webhook:
enabled: true
observability:
metrics-server:
enabled: true
aws:
q-storageclass-aws:
enabled: true
aws-ebs-csi-driver:
enabled: false
aws-load-balancer-controller:
enabled: false
gcp:
q-storageclass-gcp:
enabled: false
scaleway:
q-storageclass-scaleway:
enabled: false
qovery-cluster-agent:
fullnameOverride: qovery-shell-agent
image:
tag: *clusterAgentVersion
environmentVariables:
CLUSTER_ID: *clusterId
CLUSTER_JWT_TOKEN: *jwtToken
GRPC_SERVER: *agentGatewayUrl
LOKI_URL: *lokiUrl
ORGANIZATION_ID: *organizationId
useSelfSignCertificate: true
`
t.Run("Should strip qovery section for yanl file", func(t *testing.T) {
ret := stripQoverySection(helmValues)
assert.Equal(t, resultHelmValues, ret)
})
}
Loading