Skip to content
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 46 additions & 1 deletion hack/tools/fetch-images/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
}
Loading