-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(byok): Correctly remove qovery section from base helm values (#375)
- Loading branch information
Showing
3 changed files
with
160 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test: | ||
go test -tags testing ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"gopkg.in/yaml.v3" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/qovery/qovery-cli/pkg/cluster" | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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("") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters