Skip to content

Commit cd71829

Browse files
authored
build: handle missing creds Secrets listing CSI images (#1359)
**What problem does this PR solve?**: The CSI bump #1320 introduced this change and broke our automation with: ``` PC secret 'nutanix-csi-credentials' in namespace '' not found when usePC is set to true. Please create the secret before installing or upgrading the chart. ``` This works around it by passing dummy values to the automation. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent d97e4a9 commit cd71829

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ repos:
6262
language: system
6363
files: "hack/addons/helm-chart-bundler/repos.yaml"
6464
pass_filenames: false
65+
- id: check-list-images
66+
name: check-list-images
67+
entry: make --no-print-directory list-images
68+
language: system
69+
files: "^(charts/cluster-api-runtime-extensions-nutanix/|hack/tools/fetch-images/main.go$)"
70+
pass_filenames: false
6571
- id: check-devbox-lock
6672
name: check-devbox-lock
6773
entry: devbox install

hack/tools/fetch-images/main.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,25 @@ func getHelmValues(carenChartDirectory string) (map[string]interface{}, error) {
253253
func getValuesFileForChartIfNeeded(chartName, carenChartDirectory string) (string, error) {
254254
switch chartName {
255255
case "nutanix-csi-storage":
256-
return filepath.Join(carenChartDirectory, "addons", "csi", "nutanix", defaultHelmAddonFilename), nil
256+
// The Helm template expects the Secrets to already exist.
257+
// Read the default value file and append override values to workaround this.
258+
sourceValuesFile := filepath.Join(carenChartDirectory, "addons", "csi", "nutanix", defaultHelmAddonFilename)
259+
overrideValues := `
260+
createPrismCentralSecret: true
261+
pcUsername: admin
262+
pcPassword: admin
263+
prismCentralEndPoint: endpoint
264+
createSecret: true
265+
username: admin
266+
password: admin
267+
prismEndPoint: endpoint
268+
`
269+
updatedValuesFile, err := getUpdatedValuesFile(sourceValuesFile, overrideValues)
270+
if err != nil {
271+
return "", fmt.Errorf("failed to modify values file: %w", err)
272+
}
273+
274+
return updatedValuesFile.Name(), nil
257275
case "node-feature-discovery":
258276
return filepath.Join(carenChartDirectory, "addons", "nfd", defaultHelmAddonFilename), nil
259277
case "snapshot-controller":
@@ -471,3 +489,30 @@ func getImagesFromYAMLFiles(files []string) ([]string, error) {
471489
}
472490
return images, nil
473491
}
492+
493+
// getUpdatedValuesFile reads the default values file and returns a new file with the override values appended.
494+
func getUpdatedValuesFile(valuesFilePath, overrideValues string) (*os.File, error) {
495+
defaultValuesFile, err := os.Open(valuesFilePath)
496+
if err != nil {
497+
return nil, fmt.Errorf("failed to open default values file: %w", err)
498+
}
499+
defer defaultValuesFile.Close()
500+
501+
tempFile, err := os.CreateTemp("", "")
502+
if err != nil {
503+
return nil, fmt.Errorf("failed to create temp file: %w", err)
504+
}
505+
defer tempFile.Close()
506+
507+
_, err = io.Copy(tempFile, defaultValuesFile)
508+
if err != nil {
509+
return nil, fmt.Errorf("failed to copy default values file to temp file: %w", err)
510+
}
511+
512+
_, err = tempFile.WriteString(overrideValues)
513+
if err != nil {
514+
return nil, fmt.Errorf("failed to write to temp file: %w", err)
515+
}
516+
517+
return tempFile, nil
518+
}

0 commit comments

Comments
 (0)