Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy: ApplyParams: do not write params.env if there are no updates #1186

Merged
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
23 changes: 21 additions & 2 deletions pkg/deploy/envParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ func writeParamsToTmp(params map[string]string, tmpDir string) (string, error) {
return tmp.Name(), nil
}

// updateMap returns the number of updates made (it operates on 1 field, so 0 or 1 only).
func updateMap(m *map[string]string, key, val string) int {
old := (*m)[key]
if old == val {
return 0
}

(*m)[key] = val
return 1
}

/*
overwrite values in components' manifests params.env file
This is useful for air gapped cluster
Expand All @@ -75,22 +86,30 @@ func ApplyParams(componentPath string, imageParamsMap map[string]string, extraPa
return err
}

// will be used as a boolean (0 or non-0) and accumulate result of updates of every field
// Could use sum, but safe from hypothetically integer overflow
updated := 0

// 1. Update images with env variables
// e.g "odh-kuberay-operator-controller-image": "RELATED_IMAGE_ODH_KUBERAY_OPERATOR_CONTROLLER_IMAGE",
for i := range paramsEnvMap {
relatedImageValue := os.Getenv(imageParamsMap[i])
if relatedImageValue != "" {
paramsEnvMap[i] = relatedImageValue
updated |= updateMap(&paramsEnvMap, i, relatedImageValue)
}
}

// 2. Update other fileds with extraParamsMap which are not carried from component
for _, extraParamsMap := range extraParamsMaps {
for eKey, eValue := range extraParamsMap {
paramsEnvMap[eKey] = eValue
updated |= updateMap(&paramsEnvMap, eKey, eValue)
}
}

if updated == 0 {
return nil
}

tmp, err := writeParamsToTmp(paramsEnvMap, componentPath)
if err != nil {
return err
Expand Down
Loading