Skip to content

Commit 5f91432

Browse files
committed
Support extraEnv on every workload
1 parent beadb5c commit 5f91432

File tree

13 files changed

+173
-55
lines changed

13 files changed

+173
-55
lines changed

charts/matrix-stack/source/haproxy.json

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"annotations": {
1717
"$ref": "file://common/workloadAnnotations.json"
1818
},
19+
"extraEnv": {
20+
"$ref": "file://common/extraEnv.json"
21+
},
1922
"containersSecurityContext": {
2023
"$ref": "file://common/containersSecurityContext.json"
2124
},

charts/matrix-stack/source/init-secrets.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"annotations": {
2121
"$ref": "file://common/workloadAnnotations.json"
2222
},
23+
"extraEnv": {
24+
"$ref": "file://common/extraEnv.json"
25+
},
2326
"containersSecurityContext": {
2427
"$ref": "file://common/containersSecurityContext.json"
2528
},

charts/matrix-stack/source/postgres.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
"image": {
1010
"$ref": "file://common/image.json"
1111
},
12-
"extraEnv": {
13-
"$ref": "file://common/extraEnv.json"
14-
},
1512
"postgresExporter": {
1613
"type": "object",
1714
"properties": {
1815
"image": {
1916
"$ref": "file://common/image.json"
2017
},
18+
"extraEnv": {
19+
"$ref": "file://common/extraEnv.json"
20+
},
2121
"containersSecurityContext": {
2222
"$ref": "file://common/containersSecurityContext.json"
2323
},
@@ -49,6 +49,9 @@
4949
"annotations": {
5050
"$ref": "file://common/workloadAnnotations.json"
5151
},
52+
"extraEnv": {
53+
"$ref": "file://common/extraEnv.json"
54+
},
5255
"containersSecurityContext": {
5356
"$ref": "file://common/containersSecurityContext.json"
5457
},

charts/matrix-stack/source/synapse.json

+3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@
249249
"annotations": {
250250
"$ref": "file://common/workloadAnnotations.json"
251251
},
252+
"extraEnv": {
253+
"$ref": "file://common/extraEnv.json"
254+
},
252255
"containersSecurityContext": {
253256
"$ref": "file://common/containersSecurityContext.json"
254257
},

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

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ spec:
8484
{{- with .containersSecurityContext }}
8585
securityContext:
8686
{{- toYaml . | nindent 10 }}
87+
{{- end }}
88+
{{- with .extraEnv }}
89+
env:
90+
{{- toYaml . | nindent 10 }}
8791
{{- end }}
8892
ports:
8993
{{- if $.Values.synapse.enabled }}

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

+17
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,20 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" $
8484
{{- end }}
8585
{{- end }}
8686
{{- end }}
87+
88+
{{- define "element-io.init-secrets.env" }}
89+
{{- $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 -}}
102+
{{- end -}}
103+
{{- end -}}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ spec:
5858
{{- toYaml . | nindent 10 }}
5959
{{- end }}
6060
env:
61-
- name: NAMESPACE
62-
value: {{ $.Release.Namespace }}
61+
{{- include "element-io.init-secrets.env" (dict "root" $ "context" .) | nindent 8 }}
6362
command:
6463
- "/matrix-tools"
6564
- "generate-secrets"

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

+18
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ true
122122
{{- end -}}
123123
{{- end -}}
124124

125+
{{- define "element-io.postgres.exporter-env" }}
126+
{{- $root := .root -}}
127+
{{- with required "element-io.postgres.exporter-env missing context" .context -}}
128+
{{- $resultEnv := dict -}}
129+
{{- range $envEntry := .extraEnv -}}
130+
{{- $_ := set $resultEnv $envEntry.name $envEntry.value -}}
131+
{{- end -}}
132+
{{- $overrideEnv := dict "DATA_SOURCE_URI" "localhost?sslmode=disable"
133+
"DATA_SOURCE_USER" "postgres"
134+
-}}
135+
{{- $resultEnv := mustMergeOverwrite $resultEnv $overrideEnv -}}
136+
{{- range $key, $value := $resultEnv }}
137+
- name: {{ $key | quote }}
138+
value: {{ $value | quote }}
139+
{{- end -}}
140+
{{- end -}}
141+
{{- end -}}
142+
125143

126144
{{- define "element-io.postgres.configmap-data" -}}
127145
{{- $root := .root -}}

charts/matrix-stack/templates/postgres/statefulset.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ spec:
191191
- name: metrics
192192
containerPort: 9187
193193
env:
194-
- name: DATA_SOURCE_URI
195-
value: "localhost?sslmode=disable"
196-
- name: DATA_SOURCE_USER
197-
value: "postgres"
194+
{{- include "element-io.postgres.exporter-env" (dict "root" $ "context" .) | nindent 8 }}
198195
startupProbe:
199196
httpGet:
200197
path: /metrics

charts/matrix-stack/templates/synapse/redis_deployment.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ spec:
5757
{{- with .containersSecurityContext }}
5858
securityContext:
5959
{{- toYaml . | nindent 10 }}
60+
{{- end }}
61+
{{- with .extraEnv }}
62+
env:
63+
{{- toYaml . | nindent 10 }}
6064
{{- end }}
6165
ports:
6266
- containerPort: 6379

charts/matrix-stack/values.schema.json

+95-19
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,25 @@
298298
"type": "string"
299299
}
300300
},
301+
"extraEnv": {
302+
"type": "array",
303+
"items": {
304+
"type": "object",
305+
"required": [
306+
"name",
307+
"value"
308+
],
309+
"properties": {
310+
"name": {
311+
"type": "string"
312+
},
313+
"value": {
314+
"type": "string"
315+
}
316+
},
317+
"additionalProperties": false
318+
}
319+
},
301320
"containersSecurityContext": {
302321
"properties": {
303322
"allowPrivilegeEscalation": {
@@ -1961,6 +1980,25 @@
19611980
"type": "string"
19621981
}
19631982
},
1983+
"extraEnv": {
1984+
"type": "array",
1985+
"items": {
1986+
"type": "object",
1987+
"required": [
1988+
"name",
1989+
"value"
1990+
],
1991+
"properties": {
1992+
"name": {
1993+
"type": "string"
1994+
},
1995+
"value": {
1996+
"type": "string"
1997+
}
1998+
},
1999+
"additionalProperties": false
2000+
}
2001+
},
19642002
"containersSecurityContext": {
19652003
"properties": {
19662004
"allowPrivilegeEscalation": {
@@ -2986,25 +3024,6 @@
29863024
},
29873025
"additionalProperties": false
29883026
},
2989-
"extraEnv": {
2990-
"type": "array",
2991-
"items": {
2992-
"type": "object",
2993-
"required": [
2994-
"name",
2995-
"value"
2996-
],
2997-
"properties": {
2998-
"name": {
2999-
"type": "string"
3000-
},
3001-
"value": {
3002-
"type": "string"
3003-
}
3004-
},
3005-
"additionalProperties": false
3006-
}
3007-
},
30083027
"postgresExporter": {
30093028
"type": "object",
30103029
"properties": {
@@ -3049,6 +3068,25 @@
30493068
},
30503069
"additionalProperties": false
30513070
},
3071+
"extraEnv": {
3072+
"type": "array",
3073+
"items": {
3074+
"type": "object",
3075+
"required": [
3076+
"name",
3077+
"value"
3078+
],
3079+
"properties": {
3080+
"name": {
3081+
"type": "string"
3082+
},
3083+
"value": {
3084+
"type": "string"
3085+
}
3086+
},
3087+
"additionalProperties": false
3088+
}
3089+
},
30523090
"containersSecurityContext": {
30533091
"properties": {
30543092
"allowPrivilegeEscalation": {
@@ -3221,6 +3259,25 @@
32213259
"type": "string"
32223260
}
32233261
},
3262+
"extraEnv": {
3263+
"type": "array",
3264+
"items": {
3265+
"type": "object",
3266+
"required": [
3267+
"name",
3268+
"value"
3269+
],
3270+
"properties": {
3271+
"name": {
3272+
"type": "string"
3273+
},
3274+
"value": {
3275+
"type": "string"
3276+
}
3277+
},
3278+
"additionalProperties": false
3279+
}
3280+
},
32243281
"containersSecurityContext": {
32253282
"properties": {
32263283
"allowPrivilegeEscalation": {
@@ -6374,6 +6431,25 @@
63746431
"type": "string"
63756432
}
63766433
},
6434+
"extraEnv": {
6435+
"type": "array",
6436+
"items": {
6437+
"type": "object",
6438+
"required": [
6439+
"name",
6440+
"value"
6441+
],
6442+
"properties": {
6443+
"name": {
6444+
"type": "string"
6445+
},
6446+
"value": {
6447+
"type": "string"
6448+
}
6449+
},
6450+
"additionalProperties": false
6451+
}
6452+
},
63776453
"containersSecurityContext": {
63786454
"properties": {
63796455
"allowPrivilegeEscalation": {

tests/manifests/__init__.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class DeployableDetails(abc.ABC):
6565

6666
has_db: bool = field(default=False, hash=False)
6767
has_image: bool = field(default=None, hash=False) # type: ignore[assignment]
68-
has_extra_env: bool = field(default=None, hash=False) # type: ignore[assignment]
6968
has_ingress: bool = field(default=True, hash=False)
7069
has_workloads: bool = field(default=True, hash=False)
7170
has_service_monitor: bool = field(default=None, hash=False) # type: ignore[assignment]
@@ -80,8 +79,6 @@ def __post_init__(self):
8079
self.helm_keys = (self.name,)
8180
if self.has_image is None:
8281
self.has_image = self.has_workloads
83-
if self.has_extra_env is None:
84-
self.has_extra_env = self.has_workloads
8582
if self.has_service_monitor is None:
8683
self.has_service_monitor = self.has_workloads
8784
if self.has_topology_spread_constraints is None:
@@ -275,22 +272,19 @@ def owns_manifest_named(self, manifest_name: str) -> bool:
275272
helm_keys=("initSecrets",),
276273
has_image=False,
277274
has_ingress=False,
278-
has_extra_env=False,
279275
has_service_monitor=False,
280276
has_topology_spread_constraints=False,
281277
is_shared_component=True,
282278
),
283279
ComponentDetails(
284280
name="haproxy",
285281
has_ingress=False,
286-
has_extra_env=False,
287282
is_shared_component=True,
288283
skip_path_consistency_for_files=("haproxy.cfg", "429.http", "path_map_file", "path_map_file_get"),
289284
),
290285
ComponentDetails(
291286
name="postgres",
292287
has_ingress=False,
293-
has_extra_env=False,
294288
has_storage=True,
295289
sidecars=(
296290
SidecarDetails(
@@ -300,7 +294,6 @@ def owns_manifest_named(self, manifest_name: str) -> bool:
300294
# No manifests of its own, so no labels to set
301295
PropertyType.Labels: None,
302296
},
303-
has_extra_env=False,
304297
has_ingress=False,
305298
has_service_monitor=False,
306299
),
@@ -359,23 +352,23 @@ def owns_manifest_named(self, manifest_name: str) -> bool:
359352
name="synapse-redis",
360353
helm_keys=("synapse", "redis"),
361354
has_ingress=False,
362-
has_extra_env=False,
363355
has_service_monitor=False,
364356
has_topology_spread_constraints=False,
365357
),
366358
SubComponentDetails(
367359
name="synapse-check-config-hook",
368360
helm_keys=("synapse", "checkConfigHook"),
369361
helm_keys_overrides={
370-
# has_extra_env but comes from synapse.extraEnv
362+
# has_workloads but comes from synapse.extraEnv
371363
PropertyType.Env: None,
372364
# has_workloads and so comes from synapse.image
373365
PropertyType.Image: None,
374366
# has_workloads and so podSecurityContext but comes from synapse.podSecurityContext
375367
PropertyType.PodSecurityContext: None,
376368
# has_workloads and so tolerations but comes from synapse.tolerations
377369
PropertyType.Tolerations: None,
378-
# has_workloads and so topologySpreadConstraints but comes from synapse.topologySpreadConstraints
370+
# has_topology_spread_constraints and so topologySpreadConstraints
371+
# but comes from synapse.topologySpreadConstraints
379372
PropertyType.TopologySpreadConstraints: None,
380373
},
381374
has_ingress=False,

0 commit comments

Comments
 (0)