diff --git a/charts/matrix-stack/configs/element-web/config.json.tpl b/charts/matrix-stack/configs/element-web/config.json.tpl index b1458f26..2ae977e1 100644 --- a/charts/matrix-stack/configs/element-web/config.json.tpl +++ b/charts/matrix-stack/configs/element-web/config.json.tpl @@ -38,7 +38,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{- with .additional }} {{- range $key := (. | keys | uniq | sortAlpha) }} {{- $prop := index $root.Values.elementWeb.additional $key }} -{{- $_ := (merge $config ((tpl $prop $root) | fromJson)) -}} +{{- $_ := (mergeOverwrite ((tpl $prop $root) | fromJson) $config) -}} {{- end }} {{- end }} {{- toPrettyJson $config -}} diff --git a/charts/matrix-stack/configs/synapse/synapse-log-config.yaml.tpl b/charts/matrix-stack/configs/synapse/synapse-log-config.yaml.tpl index cfb6b209..ca5e5a36 100644 --- a/charts/matrix-stack/configs/synapse/synapse-log-config.yaml.tpl +++ b/charts/matrix-stack/configs/synapse/synapse-log-config.yaml.tpl @@ -22,7 +22,7 @@ Increasing synapse.storage.SQL past INFO will log access tokens. Putting in the nuked if an override is set and then if the root level is increased to debug, the access tokens will be logged. Putting here means it is an explicit customer choice to override it. */}} -{{- range $logger, $level := merge dict $root.Values.synapse.logging.levelOverrides (dict "synapse.storage.SQL" "INFO") }} +{{- range $logger, $level := mergeOverwrite (dict "synapse.storage.SQL" "INFO") $root.Values.synapse.logging.levelOverrides dict }} {{ $logger }}: level: "{{ $level }}" {{- end }} diff --git a/charts/matrix-stack/templates/ess-library/_credentials.tpl b/charts/matrix-stack/templates/ess-library/_credentials.tpl index 9a9afdea..57ac975a 100644 --- a/charts/matrix-stack/templates/ess-library/_credentials.tpl +++ b/charts/matrix-stack/templates/ess-library/_credentials.tpl @@ -9,7 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{- $root := .root -}} {{- with required "element-io.ess-library.value-from-values-path missing context" .context -}} {{- $path := . -}} -{{- $navigatedToPart := merge (dict) (mustDeepCopy $root.Values) -}} +{{- $navigatedToPart := mergeOverwrite (mustDeepCopy $root.Values) (dict) -}} {{- range (mustRegexSplit "\\." $path -1) -}} {{- if $navigatedToPart -}} {{- $navigatedToPart = dig . nil $navigatedToPart -}} diff --git a/charts/matrix-stack/templates/ess-library/_ingress.tpl b/charts/matrix-stack/templates/ess-library/_ingress.tpl index 940af638..0383e6d1 100644 --- a/charts/matrix-stack/templates/ess-library/_ingress.tpl +++ b/charts/matrix-stack/templates/ess-library/_ingress.tpl @@ -13,10 +13,10 @@ SPDX-License-Identifier: AGPL-3.0-only {{- if and (not $tlsSecret) $root.Values.certManager -}} {{- with $root.Values.certManager -}} {{- with .clusterIssuer -}} -{{- $annotations = merge $annotations (dict "cert-manager.io/cluster-issuer" .) -}} +{{- $annotations = mergeOverwrite (dict "cert-manager.io/cluster-issuer" .) $annotations -}} {{- end -}} {{- with .issuer -}} -{{- $annotations = merge $annotations (dict "cert-manager.io/issuer" .) -}} +{{- $annotations = mergeOverwrite (dict "cert-manager.io/issuer" .) $annotations -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/matrix-stack/templates/ess-library/_serviceAccounts.tpl b/charts/matrix-stack/templates/ess-library/_serviceAccounts.tpl index 0dd27e97..6dc54636 100644 --- a/charts/matrix-stack/templates/ess-library/_serviceAccounts.tpl +++ b/charts/matrix-stack/templates/ess-library/_serviceAccounts.tpl @@ -21,7 +21,7 @@ SPDX-License-Identifier: AGPL-3.0-only apiVersion: v1 kind: ServiceAccount metadata: - {{- with (merge dict .serviceAccount.annotations $extraAnnotations) }} + {{- with (mergeOverwrite $extraAnnotations .serviceAccount.annotations dict) }} annotations: {{- toYaml . | nindent 4 }} {{- end }} diff --git a/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl b/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl index 03b39e06..cf12c6af 100644 --- a/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl +++ b/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl @@ -72,7 +72,7 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" . {{- $_ := set $resultEnv $envEntry.name $envEntry.value -}} {{- end -}} {{- $overrideEnv := dict "MAS_CONFIG" "/config.yaml" -}} -{{- $resultEnv := merge $resultEnv $overrideEnv -}} +{{- $resultEnv := mergeOverwrite $overrideEnv $resultEnv -}} {{- range $key, $value := $resultEnv }} - name: {{ $key | quote }} value: {{ $value | quote }} diff --git a/charts/matrix-stack/templates/matrix-rtc/_helpers.tpl b/charts/matrix-stack/templates/matrix-rtc/_helpers.tpl index 1f96bc7b..e38b5471 100644 --- a/charts/matrix-stack/templates/matrix-rtc/_helpers.tpl +++ b/charts/matrix-stack/templates/matrix-rtc/_helpers.tpl @@ -126,7 +126,7 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" . {{- with required "element-io.matrix-rtc-sfu.config missing context" .context -}} {{- $config := (tpl ($root.Files.Get "configs/matrix-rtc/sfu/config.yaml.tpl") (dict "root" $root "context" .)) | fromYaml }} config.yaml: | -{{- toYaml (merge (.additional | fromYaml) $config) | nindent 2 }} +{{- toYaml (mergeOverwrite $config (.additional | fromYaml)) | nindent 2 }} {{- if not ($root.Values.matrixRTC.livekitAuth).keysYaml }} keys-template.yaml: | {{- (tpl ($root.Files.Get "configs/matrix-rtc/sfu/keys-template.yaml.tpl") dict) | nindent 2 }} diff --git a/charts/matrix-stack/templates/postgres/_helpers.tpl b/charts/matrix-stack/templates/postgres/_helpers.tpl index 2f383419..328d2f6a 100644 --- a/charts/matrix-stack/templates/postgres/_helpers.tpl +++ b/charts/matrix-stack/templates/postgres/_helpers.tpl @@ -114,7 +114,7 @@ true "LC_COLLATE" "C" "LC_CTYPE" "C" -}} -{{- $resultEnv := merge $resultEnv $overrideEnv -}} +{{- $resultEnv := mergeOverwrite $overrideEnv $resultEnv -}} {{- range $key, $value := $resultEnv }} - name: {{ $key | quote }} value: {{ $value | quote }} diff --git a/charts/matrix-stack/templates/synapse/_helpers.tpl b/charts/matrix-stack/templates/synapse/_helpers.tpl index 10695660..058b2528 100644 --- a/charts/matrix-stack/templates/synapse/_helpers.tpl +++ b/charts/matrix-stack/templates/synapse/_helpers.tpl @@ -190,7 +190,7 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" . {{- /*02 files are user provided in Helm values and end up in the Secret*/}} {{- /*03 files are user provided as secrets rather than directly in Helm*/}} 04-homeserver-overrides.yaml: | -{{- (tpl ($root.Files.Get "configs/synapse/synapse-04-homeserver-overrides.yaml.tpl") (dict "root" $root "context" (merge dict $root.Values.synapse (dict "isHook" $isHook)))) | nindent 2 }} +{{- (tpl ($root.Files.Get "configs/synapse/synapse-04-homeserver-overrides.yaml.tpl") (dict "root" $root "context" (mergeOverwrite (dict "isHook" $isHook) $root.Values.synapse dict))) | nindent 2 }} 05-main.yaml: | {{- (tpl ($root.Files.Get "configs/synapse/synapse-05-process-specific.yaml.tpl") (dict "root" $root "context" (dict "processType" "main"))) | nindent 2 }} {{- if not $isHook }} diff --git a/charts/matrix-stack/templates/synapse/synapse_check_config_job_hook.yaml b/charts/matrix-stack/templates/synapse/synapse_check_config_job_hook.yaml index d65f1c27..2c7d0617 100644 --- a/charts/matrix-stack/templates/synapse/synapse_check_config_job_hook.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_check_config_job_hook.yaml @@ -8,7 +8,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{- if and .enabled .checkConfigHook.enabled -}} {{- $enabledWorkers := (include "element-io.synapse.enabledWorkers" (dict "root" $)) | fromJson }} {{- $processType := "check-config-hook" }} -{{- $perProcessRoot := merge (dict "processType" $processType "isHook" true) (.checkConfigHook | deepCopy) ($.Values.synapse | deepCopy) }} +{{- $perProcessRoot := mergeOverwrite ($.Values.synapse | deepCopy) (.checkConfigHook | deepCopy) (dict "processType" $processType "isHook" true) }} apiVersion: batch/v1 kind: Job metadata: diff --git a/charts/matrix-stack/templates/synapse/synapse_service.yaml b/charts/matrix-stack/templates/synapse/synapse_service.yaml index 0525a6ce..36a6b4c5 100644 --- a/charts/matrix-stack/templates/synapse/synapse_service.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_service.yaml @@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{- with .Values.synapse -}} {{- if .enabled -}} {{- range $processType := prepend (keys ((include "element-io.synapse.enabledWorkers" (dict "root" $)) | fromJson)) "main" }} -{{- $perProcessRoot := merge (dict "processType" $processType "isHook" false) $.Values.synapse }} +{{- $perProcessRoot := mergeOverwrite $.Values.synapse (dict "processType" $processType "isHook" false) }} apiVersion: v1 kind: Service metadata: diff --git a/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml b/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml index b22b5d06..636c96e9 100644 --- a/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml @@ -7,9 +7,9 @@ SPDX-License-Identifier: AGPL-3.0-only {{- with .Values.synapse -}} {{- if .enabled -}} {{- $enabledWorkers := (include "element-io.synapse.enabledWorkers" (dict "root" $)) | fromJson }} -{{- range $processType, $unmergedProcessDetails := merge $enabledWorkers (dict "main" dict) }} -{{- $perProcessRoot := merge (dict "processType" $processType "isHook" false) $.Values.synapse }} -{{- with (merge dict ($unmergedProcessDetails | deepCopy) ($.Values.synapse | deepCopy)) }} +{{- range $processType, $unmergedProcessDetails := mergeOverwrite (dict "main" dict) $enabledWorkers }} +{{- $perProcessRoot := mergeOverwrite $.Values.synapse (dict "processType" $processType "isHook" false) }} +{{- with (mergeOverwrite ($.Values.synapse | deepCopy) ($unmergedProcessDetails | deepCopy) dict) }} apiVersion: apps/v1 kind: StatefulSet metadata: diff --git a/charts/matrix-stack/templates/well-known/_helpers.tpl b/charts/matrix-stack/templates/well-known/_helpers.tpl index 79aad7d6..1996ffea 100644 --- a/charts/matrix-stack/templates/well-known/_helpers.tpl +++ b/charts/matrix-stack/templates/well-known/_helpers.tpl @@ -51,7 +51,7 @@ k8s.element.io/target-instance: {{ $root.Release.Name }}-haproxy {{- $_ := set $config "org.matrix.msc4143.rtc_foci" (list (dict "type" "livekit" "livekit_service_url" (printf "https://%s" $root.Values.matrixRTC.ingress.host))) -}} {{- end -}} {{- $additional := .additional.client | fromJson -}} -{{- tpl (toPrettyJson (merge $config $additional)) $root -}} +{{- tpl (toPrettyJson (mergeOverwrite $additional $config)) $root -}} {{- end -}} {{- end }} @@ -65,7 +65,7 @@ k8s.element.io/target-instance: {{ $root.Release.Name }}-haproxy {{- end -}} {{- end -}} {{- $additional := .additional.server | fromJson -}} -{{- tpl (toPrettyJson (merge $config $additional)) $root -}} +{{- tpl (toPrettyJson (mergeOverwrite $additional $config)) $root -}} {{- end -}} {{- end }} @@ -74,7 +74,7 @@ k8s.element.io/target-instance: {{ $root.Release.Name }}-haproxy {{- with required "element-io.well-known-delegation.element missing context" .context -}} {{- $config := dict -}} {{- $additional := .additional.element | fromJson -}} -{{- tpl (toPrettyJson (merge $config $additional)) $root -}} +{{- tpl (toPrettyJson (mergeOverwrite $additional $config)) $root -}} {{- end -}} {{- end }} @@ -83,7 +83,7 @@ k8s.element.io/target-instance: {{ $root.Release.Name }}-haproxy {{- with required "element-io.well-known-delegation.support missing context" .context -}} {{- $config := dict -}} {{- $additional := .additional.support | fromJson -}} -{{- tpl (toPrettyJson (merge $config $additional)) $root -}} +{{- tpl (toPrettyJson (mergeOverwrite $additional $config)) $root -}} {{- end -}} {{- end }} diff --git a/newsfragments/395.fixed.md b/newsfragments/395.fixed.md new file mode 100644 index 00000000..ecd4dc36 --- /dev/null +++ b/newsfragments/395.fixed.md @@ -0,0 +1 @@ +Fix merging of boolean in configurations. diff --git a/scripts/ct-lint.sh b/scripts/ct-lint.sh index 6e5c0320..ea9fb63b 100644 --- a/scripts/ct-lint.sh +++ b/scripts/ct-lint.sh @@ -10,10 +10,14 @@ temp_output_file=$(mktemp) error=1 -find . -type f -name '*.tpl' -exec grep -E '\{\{[^}]*\$[^a-zA-Z0-9_][^}]*\}\}' {} + && { +find . -type f -name '*.tpl' -exec grep -nE '\{\{[^}]*\$[^a-zA-Z0-9_][^}]*\}\}' {} + && { echo 'Error: $ is used in a .tpl files, but helm passes the local context to the special variable $ in included templates.'; exit 1 } || echo "OK." +find . '(' -type f -name '*.tpl' -o -name '*.yaml' ')' -exec grep -nE '\{\{[^}]*merge\s[^}]*\}\}' {} + && { + echo 'Error: `merge` function is used in a .yaml or .tpl files, but helm does not merge boolean properly : https://github.com/helm/helm/issues/5238. Use mergeOverwrite instead.'; exit 1 +} || echo "OK." + # Call the ct lint command and stream the output to stdout if ct lint "$@" 2>&1 | tee "$temp_output_file" then