Skip to content

Commit 3f6bfda

Browse files
committed
build: handle missing creds Secrets listing CSI images
1 parent cd2bbc0 commit 3f6bfda

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

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":
@@ -442,3 +460,30 @@ func getImagesFromYAMLFiles(files []string) ([]string, error) {
442460
}
443461
return images, nil
444462
}
463+
464+
// getUpdatedValuesFile reads the default values file and returns a new file with the override values appended.
465+
func getUpdatedValuesFile(valuesFilePath, overrideValues string) (*os.File, error) {
466+
defaultValuesFile, err := os.Open(valuesFilePath)
467+
if err != nil {
468+
return nil, fmt.Errorf("failed to open default values file: %w", err)
469+
}
470+
defer defaultValuesFile.Close()
471+
472+
tempFile, err := os.CreateTemp("", "")
473+
if err != nil {
474+
return nil, fmt.Errorf("failed to create temp file: %w", err)
475+
}
476+
defer tempFile.Close()
477+
478+
_, err = io.Copy(tempFile, defaultValuesFile)
479+
if err != nil {
480+
return nil, fmt.Errorf("failed to copy default values file to temp file: %w", err)
481+
}
482+
483+
_, err = tempFile.WriteString(overrideValues)
484+
if err != nil {
485+
return nil, fmt.Errorf("failed to write to temp file: %w", err)
486+
}
487+
488+
return tempFile, nil
489+
}

0 commit comments

Comments
 (0)