Conversation
a092051 to
cdc1e83
Compare
|
Please update this PR to use the provided Pull Request Template: https://github.com/SlinkyProject/slurm-operator/blob/main/.github/pull_request_template.md |
|
Hi @vivian-hafener — thanks for the pointer, and sorry for the silence here: I rewrote the description to follow the template the same day (Sep 8), but never said so in the thread. The body now has the template's Summary / Checklist / Breaking Changes / Testing Notes / Additional Context sections. No code changes since it was opened — the branch is ready for review whenever you have a moment. |
…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`, `readOnlyRootFilesystem: 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 and empty objects are still pruned, and lists keep the behaviour they had before, so nothing beyond booleans and numbers changes. Add a regression test covering both roots the builders merge at: a pod template (BuildPodTemplate) and a container (BuildContainer). 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
cdc1e83 to
7275462
Compare
|
Force-pushed a revised commit ( Two things beyond the review, both found while re-checking the patch: The test was half-decorative. Its container assertions lived inside The
|
|
Thanks for the fixes! Please rebase against |
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 and empty objects are still pruned, and lists are left exactly asmainleaves them — an explicitly empty array is preserved — so nothing beyond booleans and numbers changes.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.One clarification on the scope, since the helper is shared by
BuildContainerandBuildPodTemplate: the loss happens at the root of the merge — the container itself forBuildContainer, and pod-level fields forBuildPodTemplate.removeEmptynever descended into lists, so a container sitting insidespec.containers[]already came through intact onmain.Closes #252.
Checklist
CONTRIBUTING.md
and the
Code of Conduct.
Breaking Changes
No API or schema change, but the fix is retroactive, and that is worth stating plainly: a
falseor0already sitting in a CR or in chart values is inert today and becomes effective the moment the operator image is replaced. No CR is edited, no chart value changes, nothing shows up in a diff — the same configuration simply starts being honoured.Mostly that is the point, and it hardens:
allowPrivilegeEscalation: false,privileged: falseandhostUsers: falsestart reaching the pod. Two directions deserve a look before upgrading:runAsNonRoot: truewith a non-root uid; an explicitrunAsNonRoot: falseorrunAsUser: 0in a CR now overrides that, where before the operator silently won;terminationGracePeriodSeconds: 0now reaches the pod, which removes the window the slurmdpreStophook uses to drain the node.A grep for zero-valued
securityContextfields and forterminationGracePeriodSecondsacross CRs and values is enough to see whether a given deployment is affected. 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 at both roots the builders use. A pod template carryingautomountServiceAccountToken: false,terminationGracePeriodSeconds: 0andsecurityContext.runAsUser: 0, and a container — the rootBuildContainermerges at — carryingprivileged: false,allowPrivilegeEscalation: falseandreadOnlyRootFilesystem: falseover a base that sets themtrue. Both halves fail onmainand pass with this change.make testis green (50 packages) andgolangci-lint run ./internal/...reports nothing from these files.List handling is deliberately untouched:
removeEmptyhas no list branch at all, so an explicitly empty array survives here exactly as it does onmain.A known limit this does not change: non-pointer
boolfields such ashostNetwork,hostPIDandhostIPC, and non-pointer empty strings, are dropped byomitemptyduringjson.Marshal, beforeremoveEmptyever sees them. No base spec sets those totruetoday, so there is nothing to override, but the class is not fully gone.Verified on a cluster (Kubernetes v1.35.8, 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.