Skip to content

Commit e74949d

Browse files
committed
Consistently handle user provided extraEnv versus chart configured env
1 parent 7df2c58 commit e74949d

25 files changed

Lines changed: 210 additions & 210 deletions

File tree

charts/matrix-stack/templates/deployment-markers/_helpers.tpl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,11 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" $
7777
{{- end }}
7878
{{- end }}
7979

80-
{{- define "element-io.deployment-markers.env" }}
80+
{{- define "element-io.deployment-markers.overrideEnv" }}
8181
{{- $root := .root -}}
82-
{{- with required "element-io.deployment-markers.env missing context" .context -}}
83-
{{- $resultEnv := dict -}}
84-
{{- range $envEntry := .extraEnv -}}
85-
{{- $_ := set $resultEnv $envEntry.name $envEntry.value -}}
86-
{{- end -}}
87-
{{- $overrideEnv := dict "NAMESPACE" $root.Release.Namespace
88-
-}}
89-
{{- $resultEnv := mustMergeOverwrite $resultEnv $overrideEnv -}}
90-
{{- range $key, $value := $resultEnv }}
91-
- name: {{ $key | quote }}
92-
value: {{ $value | quote }}
93-
{{- end -}}
82+
{{- with required "element-io.deployment-markers.overrideEnv missing context" .context -}}
83+
env:
84+
- name: "NAMESPACE"
85+
value: {{ $root.Release.Namespace | quote }}
9486
{{- end -}}
9587
{{- end -}}

charts/matrix-stack/templates/deployment-markers/job.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ spec:
5757
resources:
5858
{{- toYaml . | nindent 10 }}
5959
{{- end }}
60-
env:
61-
{{- include "element-io.deployment-markers.env" (dict "root" $ "context" .) | nindent 8 }}
60+
{{- include "element-io.ess-library.pods.env" (dict "root" $ "context" (dict "componentValues" . "componentName" "deployment-markers")) | nindent 8 }}
6261
command:
6362
- "/matrix-tools"
6463
- "deployment-markers"

charts/matrix-stack/templates/element-web/_helpers.tpl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,18 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" .
2626
{{- end }}
2727
{{- end }}
2828

29-
{{- define "element-io.element-web.env" -}}
29+
{{- define "element-io.element-web.overrideEnv" -}}
3030
{{- $root := .root -}}
31-
{{- with required "element-io.element-web.env missing context" .context -}}
32-
{{- $resultEnv := dict -}}
31+
{{- with required "element-io.element-web.overrideEnv missing context" .context -}}
3332
{{- /*
3433
https://github.com/nginxinc/docker-nginx/blob/1.26.1/entrypoint/20-envsubst-on-templates.sh#L31-L45
3534
If pods run with a GID of 0 this makes $output_dir to appear writable to sh, however
3635
due to running with a read-only FS the actual writing later fails. We short circuit this by using an
3736
invalid template directory and so templating as a whole is skipped by the script
3837
*/ -}}
39-
{{- $_ := set $resultEnv "NGINX_ENVSUBST_TEMPLATE_DIR" "/non-existant-so-that-this-works-with-read-only-root-filesystem" -}}
40-
{{- range $envEntry := .extraEnv -}}
41-
{{- $_ := set $resultEnv $envEntry.name $envEntry.value -}}
42-
{{- end -}}
43-
{{- range $key, $value := $resultEnv }}
44-
- name: {{ $key | quote }}
45-
value: {{ $value | quote }}
46-
{{- end -}}
38+
env:
39+
- name: "NGINX_ENVSUBST_TEMPLATE_DIR"
40+
value: "/non-existant-so-that-this-works-with-read-only-root-filesystem"
4741
{{- end -}}
4842
{{- end -}}
4943

charts/matrix-stack/templates/element-web/deployment.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ spec:
4343
imagePullPolicy: {{ .pullPolicy | default "Always" }}
4444
{{- end }}
4545
{{- end }}
46-
env:
47-
{{- include "element-io.element-web.env" (dict "root" $ "context" .) | nindent 10 }}
46+
{{- include "element-io.ess-library.pods.env" (dict "root" $ "context" (dict "componentValues" . "componentName" "element-web")) | nindent 8 }}
4847
{{- with .containersSecurityContext }}
4948
securityContext:
5049
{{- toYaml . | nindent 10 }}

charts/matrix-stack/templates/ess-library/_pods.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,27 @@ successThreshold: {{ . }}
118118
timeoutSeconds: {{ . }}
119119
{{- end }}
120120
{{- end }}
121+
122+
{{- define "element-io.ess-library.pods.env" -}}
123+
{{- $root := .root -}}
124+
{{- with required "element-io.ess-library.pods.env missing context" .context -}}
125+
{{- $componentValues := required "element-io.ess-library.pods.env missing context.componentValues" .componentValues -}}
126+
{{- $resultEnv := dict -}}
127+
{{- range $envEntry := $componentValues.extraEnv -}}
128+
{{- $_ := set $resultEnv $envEntry.name $envEntry -}}
129+
{{- end -}}
130+
{{- $componentName := required "element-io.ess-library.pods.env missing context.componentName" .componentName -}}
131+
{{- $overrideEnvType := .overrideEnvSuffix | default "overrideEnv" -}}
132+
{{- $overrideEnvDocument := include (printf "element-io.%s.%s" $componentName $overrideEnvType) (dict "root" $root "context" $componentValues) -}}
133+
{{- $overrideEnvYaml := $overrideEnvDocument | fromYaml -}}
134+
{{- range $envEntry := $overrideEnvYaml.env -}}
135+
{{- $_ := set $resultEnv $envEntry.name $envEntry -}}
136+
{{- end -}}
137+
{{- with $resultEnv }}
138+
env:
139+
{{- range $key, $fullEnvEntry := . }}
140+
- {{ $fullEnvEntry | toYaml | indent 2 | trim }}
141+
{{- end -}}
142+
{{- end -}}
143+
{{- end -}}
144+
{{- end -}}

charts/matrix-stack/templates/ess-library/_render_config.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ SPDX-License-Identifier: AGPL-3.0-only
5353
{{- range $overrides }}
5454
- /config-templates/{{ . }}
5555
{{- end }}
56-
env:
57-
{{- include (printf "element-io.%s.matrixToolsEnv" $nameSuffix) (dict "root" $root "context" .) | nindent 2 }}
58-
{{- include (printf "element-io.%s.env" $nameSuffix) (dict "root" $root "context" .) | nindent 2 }}
56+
{{- include "element-io.ess-library.pods.env" (dict "root" $root "context" (dict "componentValues" . "componentName" $nameSuffix "overrideEnvSuffix" "renderConfigOverrideEnv")) | nindent 2 }}
5957
{{- with .resources }}
6058
resources:
6159
{{- toYaml . | nindent 4 }}

charts/matrix-stack/templates/haproxy/_helpers.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- /*
2-
Copyright 2024 New Vector Ltd
2+
Copyright 2024-2025 New Vector Ltd
33
44
SPDX-License-Identifier: AGPL-3.0-only
55
*/ -}}
@@ -24,3 +24,7 @@ haproxy.cfg: |
2424
{{- (tpl ($root.Files.Get "configs/haproxy/429.http.tpl") dict) | nindent 2 }}
2525
{{- end -}}
2626
{{- end -}}
27+
28+
{{- define "element-io.haproxy.overrideEnv" }}
29+
env: []
30+
{{- end -}}

charts/matrix-stack/templates/haproxy/deployment.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ spec:
6363
securityContext:
6464
{{- toYaml . | nindent 10 }}
6565
{{- end }}
66-
{{- with .extraEnv }}
67-
env:
68-
{{- toYaml . | nindent 10 }}
69-
{{- end }}
66+
{{- include "element-io.ess-library.pods.env" (dict "root" $ "context" (dict "componentValues" . "componentName" "haproxy")) | nindent 8 }}
7067
ports:
7168
{{- if $.Values.synapse.enabled }}
7269
- containerPort: 8008

charts/matrix-stack/templates/init-secrets/_helpers.tpl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,11 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" $
8585
{{- end }}
8686
{{- end }}
8787

88-
{{- define "element-io.init-secrets.env" }}
88+
{{- define "element-io.init-secrets.overrideEnv" }}
8989
{{- $root := .root -}}
90-
{{- with required "element-io.init-secrets.env missing context" .context -}}
91-
{{- $resultEnv := dict -}}
92-
{{- range $envEntry := .extraEnv -}}
93-
{{- $_ := set $resultEnv $envEntry.name $envEntry.value -}}
94-
{{- end -}}
95-
{{- $overrideEnv := dict "NAMESPACE" $root.Release.Namespace
96-
-}}
97-
{{- $resultEnv := mustMergeOverwrite $resultEnv $overrideEnv -}}
98-
{{- range $key, $value := $resultEnv }}
99-
- name: {{ $key | quote }}
100-
value: {{ $value | quote }}
101-
{{- end -}}
90+
{{- with required "element-io.init-secrets.overrideEnv missing context" .context -}}
91+
env:
92+
- name: "NAMESPACE"
93+
value: {{ $root.Release.Namespace | quote }}
10294
{{- end -}}
10395
{{- end -}}

charts/matrix-stack/templates/init-secrets/job.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ spec:
5757
resources:
5858
{{- toYaml . | nindent 10 }}
5959
{{- end }}
60-
env:
61-
{{- include "element-io.init-secrets.env" (dict "root" $ "context" .) | nindent 8 }}
60+
{{- include "element-io.ess-library.pods.env" (dict "root" $ "context" (dict "componentValues" . "componentName" "init-secrets")) | nindent 8 }}
6261
command:
6362
- "/matrix-tools"
6463
- "generate-secrets"

0 commit comments

Comments
 (0)