fix(builder): keep explicitly-set false/0 values when merging CR templates - #253
Open
AndreyZa wants to merge 1 commit into
Open
fix(builder): keep explicitly-set false/0 values when merging CR templates#253AndreyZa wants to merge 1 commit into
AndreyZa wants to merge 1 commit into
Conversation
AndreyZa
requested review from
SkylerMalinowski,
alanmutsch,
catblade,
vivian-hafener and
wickberg
as code owners
September 2, 2026 07:58
…lates removeEmpty() pruned every JSON value equal to the zero value of its Go type, so an explicitly-set `false` or `0` in a CR pod/container template was dropped from the strategic merge patch and never reached the built workload. The most visible effect: `spec.login.securityContext.allowPrivilegeEscalation: false` on a LoginSet is stored in the CR but absent from the Deployment, so the login container runs with NoNewPrivs=0 and cannot satisfy the restricted Pod Security Standard. `privileged: false`, `runAsUser: 0`, `automountServiceAccountToken: false` and `terminationGracePeriodSeconds: 0` are lost the same way, in every builder that merges a user template. These fields are pointers with omitempty in the Kubernetes API types, so they are only present in the marshalled patch when the user set them explicitly; pruning them discarded configuration rather than noise. Nulls, empty strings, empty objects and empty lists are still pruned, so unset non-pointer fields keep their previous behaviour. Add a regression test covering both container- and pod-level zero values. Signed-off-by: Andrey Zavilgelsky <zamazo38@gmail.com> Changelog: Fixed - explicitly-set false/0 values in CR templates (e.g. allowPrivilegeEscalation: false) are no longer dropped from the built workload
AndreyZa
force-pushed
the
fix/keep-explicit-zero-values
branch
from
September 2, 2026 08:18
a092051 to
cdc1e83
Compare
Contributor
|
Please update this PR to use the provided Pull Request Template: https://github.com/SlinkyProject/slurm-operator/blob/main/.github/pull_request_template.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
removeEmpty()pruned every JSON value equal to the zero value of its Go type, so an explicitly-setfalseor0in a CR pod/container template was dropped from the strategic merge patch and never reached the built workload.The fields at risk are
*bool/*int64withomitemptyin the Kubernetes API types: they are marshalled only when the user set them, so pruning them discarded configuration rather than noise. Nulls, empty strings, empty objects and empty lists are still pruned, so unset non-pointer fields keep their previous behaviour.Concretely,
spec.login.securityContext.allowPrivilegeEscalation: falseon aLoginSetis stored in the CR but absent from the Deployment, so the login container runs withNoNewPrivs: 0and aLoginSetcannot satisfy therestrictedPod Security Standard. The chart's own default (loginsetDefaults.login.securityContext.privileged: false) is lost the same way, as arereadOnlyRootFilesystem: false,runAsUser: 0andterminationGracePeriodSeconds: 0. The helper is shared byBuildContainerandBuildPodTemplate, so every builder is affected.Closes #252.
Checklist
CONTRIBUTING.md
and the
Code of Conduct.
Breaking Changes
None intended. Values that users set explicitly to
false/0now reach the workload; anything left unset is pruned exactly as before. A deployment that relied on an explicitfalsebeing silently ignored would change, but that would be the bug itself.Testing Notes
internal/utils/structutils/kube_test.gogains a subtest that merges a patch carrying container-levelprivileged: false/allowPrivilegeEscalation: falseand pod-levelautomountServiceAccountToken: false,terminationGracePeriodSeconds: 0,securityContext.runAsUser: 0. It fails onmainand passes with this change.make testis green (50 packages).Verified on a cluster (Kubernetes v1.35.8 / k0s, charts
slurm-operator-1.2.1/slurm-1.2.1, oneLoginSetdeclaring all five fields; only the operator image swapped):Before (
ghcr.io/slinkyproject/slurm-operator:1.2.1):After (this branch):
and in the login pod:
NoNewPrivs: 1.Additional Context
Found while trying to run a
LoginSetunder therestrictedPod Security Standard.