Skip to content

fix: strip enabled key from securityContext before rendering#166

Open
DarpaSehgal wants to merge 2 commits into
valkey-io:mainfrom
DarpaSehgal:fix/omit-enabled-from-securitycontext
Open

fix: strip enabled key from securityContext before rendering#166
DarpaSehgal wants to merge 2 commits into
valkey-io:mainfrom
DarpaSehgal:fix/omit-enabled-from-securitycontext

Conversation

@DarpaSehgal
Copy link
Copy Markdown

Summary

The podSecurityContext and securityContext values support an enabled field as a helm-level toggle (common in Bitnami-style charts). However, enabled is not a valid Kubernetes PodSecurityContext or SecurityContext field. When rendered verbatim into the manifest, Kubernetes silently strips it on storage, causing the actual stored state to differ from what Helm rendered. This breaks drift detection in GitOps tools (ArgoCD, Rancher Fleet, etc.), reporting resources as perpetually out-of-sync.

Changes

Used omit to strip the enabled key before piping to toYaml in all security context rendering locations across both templates:

  • valkey/templates/deploy_valkey.yaml (4 spots: pod, init container, main container, metrics exporter)
  • valkey/templates/statefulset.yaml (4 spots: same)

Testing

Render the chart with podSecurityContext.enabled=true and verify enabled does not appear in the output YAML:

helm template valkey valkey --repo https://valkey.io/valkey-helm/ \
  --show-only templates/deploy_valkey.yaml | grep -A 4 "securityContext:"

The podSecurityContext, securityContext, and metrics exporter
securityContext values support an 'enabled' field as a helm-level toggle.
However, this field is not a valid Kubernetes PodSecurityContext or
SecurityContext field. When rendered verbatim, Kubernetes silently strips
it, causing GitOps tools like ArgoCD and Rancher Fleet to report
resources as perpetually out-of-sync.

Use omit to strip the 'enabled' key before piping to toYaml in both
deploy_valkey.yaml and statefulset.yaml templates.

Fixes: valkey-io#139
Signed-off-by: Darpa Sehgal <6688157+DarpaSehgal@users.noreply.github.com>
@sgissi
Copy link
Copy Markdown
Collaborator

sgissi commented May 2, 2026

Thanks @DarpaSehgal, that would close #139. Can you please add a test case?

Add helm-unittest cases for all four securityContext locations
(pod, init container, main container, metrics exporter) in both
deploy_valkey.yaml and statefulset.yaml templates.

Each test sets enabled: true alongside valid fields and asserts
that enabled does not appear in the rendered output while the
other fields render correctly.

Signed-off-by: Darpa Sehgal <6688157+DarpaSehgal@users.noreply.github.com>
@DarpaSehgal DarpaSehgal force-pushed the fix/omit-enabled-from-securitycontext branch from 8c20789 to 8f26c1a Compare May 4, 2026 17:56
@DarpaSehgal
Copy link
Copy Markdown
Author

Added test cases covering all four securityContext locations (pod, init container, main container, metrics exporter) in both deployment_test.yaml and statefulset_test.yaml.

Each test:

  • Sets enabled: true alongside valid K8s fields
  • Asserts enabled is not present in the rendered output
  • Asserts the other valid fields render correctly

Thanks @DarpaSehgal, that would close #139. Can you please add a test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podSecurityContext.enabled and containerSecurityContext.enabled are passed through to rendered manifests

2 participants