You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
0 commit comments