diff --git a/pkg/deploy/envParams.go b/pkg/deploy/envParams.go index a3eda173c1f..96ce3c7c577 100644 --- a/pkg/deploy/envParams.go +++ b/pkg/deploy/envParams.go @@ -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 @@ -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(¶msEnvMap, 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(¶msEnvMap, eKey, eValue) } } + if updated == 0 { + return nil + } + tmp, err := writeParamsToTmp(paramsEnvMap, componentPath) if err != nil { return err