Skip to content

Commit 582d248

Browse files
Fix the bug in the helm template for operator envs vars when they are numeric (#552)
# Summary We had a bug in our helm templating function when we set the env vars `INIT_DATABASE_VERSION`, `DATABASE_VERSION`, `INIT_OPS_MANAGER_VERSION`, and `INIT_APPDB_VERSION` using the helm values that are passed for the helm fields `.Values.initDatabase.version`, `.Values.database.version`, `.Values.initOpsManager.version` and `.Values.initAppDb.version` respectively. Below is the snippet from our `oprator.yaml`. ``` {{- $initDatabaseVersion := print .Values.initDatabase.version (.Values.build | default "") -}} env: - name: INIT_DATABASE_VERSION value: {{ $initDatabaseVersion }} ``` If the values are alphanumeric (`1.2.3`, `jlk345`, `lkjsdf`) that value is set to the env var properly and the deployment manifest is rendered successfully, but it fails when we pass plain numeric values for the helm field `initDatabase.version`. And fails because value of env var in deployment manifest is expected to be string. The way operator is installed in our E2E tests is we build the images first using the master commit sha (**starting 8 chars**) as tag and then pass that tag as values for above mentioned helm fields. Now if the commit sha that is generated is alpha numeric, everything works as expected, but if a commit sha doesn't have any alphabets and just has numbers the rendering for operator deployment fails. We got two commits ([1](0089223), [2](0617759)) in master that just had numbers (**starting 8 charts**) and we passed those numbers to operator to set as env var, the `helm install` failed. This PR fixes that by making sure that we always quote the passed versions to make them string. ## Proof of Work Unit test to make sure the values are quoted. And manual tests. Also CI runs in this PR. Newly added `Environment Variable Quoting Check` helm test passes: ``` [2025/10/27 12:49:24.664] ### Chart [ mongodb-kubernetes ] helm_chart [2025/10/27 12:49:24.673] PASS Environment Variable Quoting Check helm_chart/tests/operator_env_vars_type_test.yaml [2025/10/27 12:49:24.715] PASS test operator security context settings for values.yaml helm_chart/tests/operator_security_context_test.yaml [2025/10/27 12:49:24.717] PASS test webhook consistent clusterrole and binding helm_chart/tests/webhook_clusterrole_test.yaml [2025/10/27 12:49:24.717] Charts: 1 passed, 1 total [2025/10/27 12:49:24.717] Test Suites: 3 passed, 3 total [2025/10/27 12:49:24.717] Tests: 13 passed, 13 total [2025/10/27 12:49:24.717] Snapshot: 0 passed, 0 total [2025/10/27 12:49:24.717] Time: 56.760126ms ``` ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details --------- Co-authored-by: Maciej Karaś <[email protected]>
1 parent 7dae9c2 commit 582d248

File tree

6 files changed

+81
-23
lines changed

6 files changed

+81
-23
lines changed

config/manager/manager.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ spec:
6969
- name: INIT_DATABASE_IMAGE_REPOSITORY
7070
value: quay.io/mongodb/mongodb-kubernetes-init-database
7171
- name: INIT_DATABASE_VERSION
72-
value: 1.5.0
72+
value: "1.5.0"
7373
- name: DATABASE_VERSION
74-
value: 1.5.0
74+
value: "1.5.0"
7575
# Ops Manager
7676
- name: OPS_MANAGER_IMAGE_REPOSITORY
7777
value: quay.io/mongodb/mongodb-enterprise-ops-manager-ubi
7878
- name: INIT_OPS_MANAGER_IMAGE_REPOSITORY
7979
value: quay.io/mongodb/mongodb-kubernetes-init-ops-manager
8080
- name: INIT_OPS_MANAGER_VERSION
81-
value: 1.5.0
81+
value: "1.5.0"
8282
# AppDB
8383
- name: INIT_APPDB_IMAGE_REPOSITORY
8484
value: quay.io/mongodb/mongodb-kubernetes-init-appdb
8585
- name: INIT_APPDB_VERSION
86-
value: 1.5.0
86+
value: "1.5.0"
8787
- name: OPS_MANAGER_IMAGE_PULL_POLICY
8888
value: Always
8989
- name: AGENT_IMAGE
@@ -208,7 +208,7 @@ spec:
208208
value: "quay.io/mongodb/mongodb-enterprise-ops-manager-ubi:8.0.14"
209209
- name: RELATED_IMAGE_OPS_MANAGER_IMAGE_REPOSITORY_8_0_15
210210
value: "quay.io/mongodb/mongodb-enterprise-ops-manager-ubi:8.0.15"
211-
# since the official server images end with a different suffix we can re-use the same $mongodbImageEnv
211+
# since the official server images end with a different suffix we can re-use the same $mongodbImageEnv
212212
- name: RELATED_IMAGE_MONGODB_IMAGE_4_4_0_ubi8
213213
value: "quay.io/mongodb/mongodb-enterprise-server:4.4.0-ubi8"
214214
- name: RELATED_IMAGE_MONGODB_IMAGE_4_4_1_ubi8

helm_chart/templates/operator.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,21 @@ spec:
172172
- name: {{ $initDatabaseImageRepositoryEnv }}
173173
value: {{ .Values.registry.initDatabase }}/{{ .Values.initDatabase.name }}
174174
- name: INIT_DATABASE_VERSION
175-
value: {{ $initDatabaseVersion }}
175+
value: {{ $initDatabaseVersion | quote }}
176176
- name: DATABASE_VERSION
177-
value: {{ $databaseVersion }}
177+
value: {{ $databaseVersion | quote }}
178178
# Ops Manager
179179
- name: {{ $opsManagerImageRepositoryEnv }}
180180
value: {{ .Values.registry.opsManager }}/{{ .Values.opsManager.name }}
181181
- name: {{ $initOpsManagerImageRepositoryEnv }}
182182
value: {{ .Values.registry.initOpsManager }}/{{ .Values.initOpsManager.name }}
183183
- name: INIT_OPS_MANAGER_VERSION
184-
value: {{ $initOpsManagerVersion }}
184+
value: {{ $initOpsManagerVersion | quote }}
185185
# AppDB
186186
- name: {{ $initAppDbImageRepositoryEnv }}
187187
value: {{ .Values.registry.initAppDb }}/{{ .Values.initAppDb.name }}
188188
- name: INIT_APPDB_VERSION
189-
value: {{ $initAppDbVersion }}
189+
value: {{ $initAppDbVersion | quote }}
190190
- name: OPS_MANAGER_IMAGE_PULL_POLICY
191191
value: {{ .Values.registry.pullPolicy }}
192192
- name: {{ $agentImageEnv }}
@@ -260,7 +260,7 @@ spec:
260260
- name: RELATED_IMAGE_{{ $opsManagerImageRepositoryEnv }}_{{ $version | replace "." "_" | replace "-" "_" }}
261261
value: "{{ $.Values.registry.opsManager }}/{{ $.Values.opsManager.name }}:{{ $version }}"
262262
{{- end }}
263-
# since the official server images end with a different suffix we can re-use the same $mongodbImageEnv
263+
# since the official server images end with a different suffix we can re-use the same $mongodbImageEnv
264264
{{- range $version := .Values.relatedImages.mongodb }}
265265
- name: RELATED_IMAGE_{{ $mongodbImageEnv }}_{{ $version | replace "." "_" | replace "-" "_" }}
266266
value: "{{ $.Values.mongodb.repo }}/{{ $.Values.mongodb.name }}:{{ $version }}"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
suite: Environment Variable Quoting Check
2+
templates:
3+
- operator.yaml
4+
tests:
5+
- it: should correctly quote the value for the env vars for container images
6+
set:
7+
initDatabase.version: 1234
8+
database.version: 12d3f4
9+
initOpsManager.version: 1.2.3
10+
initAppDb.version: abc
11+
asserts:
12+
- contains:
13+
path: spec.template.spec.containers[0].env
14+
content:
15+
name: INIT_DATABASE_VERSION
16+
value: "1234"
17+
- contains:
18+
path: spec.template.spec.containers[0].env
19+
content:
20+
name: DATABASE_VERSION
21+
value: "12d3f4"
22+
- contains:
23+
path: spec.template.spec.containers[0].env
24+
content:
25+
name: INIT_OPS_MANAGER_VERSION
26+
value: "1.2.3"
27+
- contains:
28+
path: spec.template.spec.containers[0].env
29+
content:
30+
name: INIT_APPDB_VERSION
31+
value: "abc"
32+
- it: should correctly quote the value for the env vars for container images even when they are passed quoted
33+
set:
34+
initDatabase.version: "1234"
35+
database.version: "12d3f4"
36+
initOpsManager.version: "1.2.3"
37+
initAppDb.version: "abc"
38+
asserts:
39+
- contains:
40+
path: spec.template.spec.containers[0].env
41+
content:
42+
name: INIT_DATABASE_VERSION
43+
value: "1234"
44+
- contains:
45+
path: spec.template.spec.containers[0].env
46+
content:
47+
name: DATABASE_VERSION
48+
value: "12d3f4"
49+
- contains:
50+
path: spec.template.spec.containers[0].env
51+
content:
52+
name: INIT_OPS_MANAGER_VERSION
53+
value: "1.2.3"
54+
- contains:
55+
path: spec.template.spec.containers[0].env
56+
content:
57+
name: INIT_APPDB_VERSION
58+
value: "abc"

public/mongodb-kubernetes-multi-cluster.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,21 @@ spec:
380380
- name: INIT_DATABASE_IMAGE_REPOSITORY
381381
value: quay.io/mongodb/mongodb-kubernetes-init-database
382382
- name: INIT_DATABASE_VERSION
383-
value: 1.5.0
383+
value: "1.5.0"
384384
- name: DATABASE_VERSION
385-
value: 1.5.0
385+
value: "1.5.0"
386386
# Ops Manager
387387
- name: OPS_MANAGER_IMAGE_REPOSITORY
388388
value: quay.io/mongodb/mongodb-enterprise-ops-manager-ubi
389389
- name: INIT_OPS_MANAGER_IMAGE_REPOSITORY
390390
value: quay.io/mongodb/mongodb-kubernetes-init-ops-manager
391391
- name: INIT_OPS_MANAGER_VERSION
392-
value: 1.5.0
392+
value: "1.5.0"
393393
# AppDB
394394
- name: INIT_APPDB_IMAGE_REPOSITORY
395395
value: quay.io/mongodb/mongodb-kubernetes-init-appdb
396396
- name: INIT_APPDB_VERSION
397-
value: 1.5.0
397+
value: "1.5.0"
398398
- name: OPS_MANAGER_IMAGE_PULL_POLICY
399399
value: Always
400400
- name: AGENT_IMAGE

public/mongodb-kubernetes-openshift.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,21 @@ spec:
375375
- name: INIT_DATABASE_IMAGE_REPOSITORY
376376
value: quay.io/mongodb/mongodb-kubernetes-init-database
377377
- name: INIT_DATABASE_VERSION
378-
value: 1.5.0
378+
value: "1.5.0"
379379
- name: DATABASE_VERSION
380-
value: 1.5.0
380+
value: "1.5.0"
381381
# Ops Manager
382382
- name: OPS_MANAGER_IMAGE_REPOSITORY
383383
value: quay.io/mongodb/mongodb-enterprise-ops-manager-ubi
384384
- name: INIT_OPS_MANAGER_IMAGE_REPOSITORY
385385
value: quay.io/mongodb/mongodb-kubernetes-init-ops-manager
386386
- name: INIT_OPS_MANAGER_VERSION
387-
value: 1.5.0
387+
value: "1.5.0"
388388
# AppDB
389389
- name: INIT_APPDB_IMAGE_REPOSITORY
390390
value: quay.io/mongodb/mongodb-kubernetes-init-appdb
391391
- name: INIT_APPDB_VERSION
392-
value: 1.5.0
392+
value: "1.5.0"
393393
- name: OPS_MANAGER_IMAGE_PULL_POLICY
394394
value: Always
395395
- name: AGENT_IMAGE
@@ -512,7 +512,7 @@ spec:
512512
value: "quay.io/mongodb/mongodb-enterprise-ops-manager-ubi:8.0.14"
513513
- name: RELATED_IMAGE_OPS_MANAGER_IMAGE_REPOSITORY_8_0_15
514514
value: "quay.io/mongodb/mongodb-enterprise-ops-manager-ubi:8.0.15"
515-
# since the official server images end with a different suffix we can re-use the same $mongodbImageEnv
515+
# since the official server images end with a different suffix we can re-use the same $mongodbImageEnv
516516
- name: RELATED_IMAGE_MONGODB_IMAGE_4_4_0_ubi8
517517
value: "quay.io/mongodb/mongodb-enterprise-server:4.4.0-ubi8"
518518
- name: RELATED_IMAGE_MONGODB_IMAGE_4_4_1_ubi8

public/mongodb-kubernetes.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,21 @@ spec:
376376
- name: INIT_DATABASE_IMAGE_REPOSITORY
377377
value: quay.io/mongodb/mongodb-kubernetes-init-database
378378
- name: INIT_DATABASE_VERSION
379-
value: 1.5.0
379+
value: "1.5.0"
380380
- name: DATABASE_VERSION
381-
value: 1.5.0
381+
value: "1.5.0"
382382
# Ops Manager
383383
- name: OPS_MANAGER_IMAGE_REPOSITORY
384384
value: quay.io/mongodb/mongodb-enterprise-ops-manager-ubi
385385
- name: INIT_OPS_MANAGER_IMAGE_REPOSITORY
386386
value: quay.io/mongodb/mongodb-kubernetes-init-ops-manager
387387
- name: INIT_OPS_MANAGER_VERSION
388-
value: 1.5.0
388+
value: "1.5.0"
389389
# AppDB
390390
- name: INIT_APPDB_IMAGE_REPOSITORY
391391
value: quay.io/mongodb/mongodb-kubernetes-init-appdb
392392
- name: INIT_APPDB_VERSION
393-
value: 1.5.0
393+
value: "1.5.0"
394394
- name: OPS_MANAGER_IMAGE_PULL_POLICY
395395
value: Always
396396
- name: AGENT_IMAGE

0 commit comments

Comments
 (0)