diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db71a262a..34f797ed0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -62,6 +62,12 @@ repos: language: system files: "hack/addons/helm-chart-bundler/repos.yaml" pass_filenames: false + - id: check-list-images + name: check-list-images + entry: make --no-print-directory list-images + language: system + files: "^(charts/cluster-api-runtime-extensions-nutanix/|hack/tools/fetch-images/main.go$)" + pass_filenames: false - id: check-devbox-lock name: check-devbox-lock entry: devbox install diff --git a/hack/tools/fetch-images/main.go b/hack/tools/fetch-images/main.go index 1fa03e208..6c8b93f83 100644 --- a/hack/tools/fetch-images/main.go +++ b/hack/tools/fetch-images/main.go @@ -253,7 +253,25 @@ func getHelmValues(carenChartDirectory string) (map[string]interface{}, error) { func getValuesFileForChartIfNeeded(chartName, carenChartDirectory string) (string, error) { switch chartName { case "nutanix-csi-storage": - return filepath.Join(carenChartDirectory, "addons", "csi", "nutanix", defaultHelmAddonFilename), nil + // The Helm template expects the Secrets to already exist. + // Read the default value file and append override values to workaround this. + sourceValuesFile := filepath.Join(carenChartDirectory, "addons", "csi", "nutanix", defaultHelmAddonFilename) + overrideValues := ` +createPrismCentralSecret: true +pcUsername: admin +pcPassword: admin +prismCentralEndPoint: endpoint +createSecret: true +username: admin +password: admin +prismEndPoint: endpoint +` + updatedValuesFile, err := getUpdatedValuesFile(sourceValuesFile, overrideValues) + if err != nil { + return "", fmt.Errorf("failed to modify values file: %w", err) + } + + return updatedValuesFile.Name(), nil case "node-feature-discovery": return filepath.Join(carenChartDirectory, "addons", "nfd", defaultHelmAddonFilename), nil case "snapshot-controller": @@ -442,3 +460,30 @@ func getImagesFromYAMLFiles(files []string) ([]string, error) { } return images, nil } + +// getUpdatedValuesFile reads the default values file and returns a new file with the override values appended. +func getUpdatedValuesFile(valuesFilePath, overrideValues string) (*os.File, error) { + defaultValuesFile, err := os.Open(valuesFilePath) + if err != nil { + return nil, fmt.Errorf("failed to open default values file: %w", err) + } + defer defaultValuesFile.Close() + + tempFile, err := os.CreateTemp("", "") + if err != nil { + return nil, fmt.Errorf("failed to create temp file: %w", err) + } + defer tempFile.Close() + + _, err = io.Copy(tempFile, defaultValuesFile) + if err != nil { + return nil, fmt.Errorf("failed to copy default values file to temp file: %w", err) + } + + _, err = tempFile.WriteString(overrideValues) + if err != nil { + return nil, fmt.Errorf("failed to write to temp file: %w", err) + } + + return tempFile, nil +}