Skip to content

Conversation

@viveksinghggits
Copy link
Contributor

@viveksinghggits viveksinghggits commented Oct 24, 2025

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, 2) 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

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you added changelog file?

@viveksinghggits viveksinghggits requested a review from a team as a code owner October 24, 2025 15:43
@viveksinghggits viveksinghggits added the skip-changelog Use this label in Pull Request to not require new changelog entry file label Oct 24, 2025
@github-actions
Copy link

⚠️ (this preview might not be accurate if the PR is not rebased on current master branch)

MCK 1.6.0 Release Notes

New Features

  • MongoDBCommunity: Added support to configure custom cluster domain via newly introduced spec.clusterDomain resource field. If spec.clusterDomain is not set, environment variable CLUSTER_DOMAIN is used as cluster domain. If the environment variable CLUSTER_DOMAIN is also not set, operator falls back to cluster.local as default cluster domain.
  • Helm Chart: Introduced two new helm fields operator.podSecurityContext and operator.securityContext that can be used to configure securityContext for Operator deployment through Helm Chart.

Bug Fixes

  • Fixed parsing of the customEnvVars Helm value when values contain = characters.

Copy link
Collaborator

@MaciejKaras MaciejKaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

I'm approving the PR even though the unit tests and linters are failing with similar error:

Error: YAML parse error on mongodb-kubernetes/templates/operator.yaml: error converting YAML to JSON: yaml: line 121: did not find expected key

@MaciejKaras MaciejKaras merged commit 582d248 into master Oct 27, 2025
34 of 37 checks passed
@MaciejKaras MaciejKaras deleted the fix-helm-template-bug branch October 27, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use this label in Pull Request to not require new changelog entry file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants