fix(api): mark Sandbox.spec.volumeClaimTemplates immutable via CEL#858
fix(api): mark Sandbox.spec.volumeClaimTemplates immutable via CEL#858mesutoezdil wants to merge 2 commits into
Conversation
✅ Deploy Preview for agent-sandbox canceled.
|
|
|
|
Welcome @mesutoezdil! |
|
Hi @mesutoezdil. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
a93d3cb to
a625000
Compare
a625000 to
49297c9
Compare
There was a problem hiding this comment.
Pull request overview
This PR makes Sandbox.spec.volumeClaimTemplates immutable after creation by adding a CEL XValidation rule (self == oldSelf). This aligns Sandbox behavior with Kubernetes’ StatefulSet immutability expectations and prevents silent drift between Sandbox spec and already-created PVCs.
Changes:
- Added a kubebuilder
XValidationCEL rule to enforce immutability ofSandboxSpec.VolumeClaimTemplates. - Regenerated CRDs in both
k8s/crds/andhelm/crds/to include the resultingx-kubernetes-validationsstanza. - Updated the API reference docs to mention the immutability behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/v1beta1/sandbox_types.go | Adds CEL immutability validation for spec.volumeClaimTemplates. |
| k8s/crds/agents.x-k8s.io_sandboxes.yaml | Regenerated CRD reflecting x-kubernetes-validations for the field. |
| helm/crds/agents.x-k8s.io_sandboxes.yaml | Same regenerated CRD change for the Helm chart. |
| docs/api.md | Documents that volumeClaimTemplates is immutable after creation. |
barney-s
left a comment
There was a problem hiding this comment.
- While this is a step in the right direction to align with
StatefulSetexpectations, the current CEL rule configuration on an optional field leaves gaps that allow transitions from unset to set (and vice versa) on update. To ensure strict immutability, the validation rule should be defined at the parent struct level. - Additionally, there are no tests included to verify this validation behavior.
The previous rule was placed on the optional field itself, so Kubernetes skipped it when the field was absent in old or new object. Moving the rule to SandboxSpec covers all three transitions: set-to-modified-set, unset-to-set, and set-to-unset. Regenerated CRDs via go generate ./... and docs/api.md via make generate-api-docs. Added e2e tests for all three rejection cases. Fixes: barney-s review on kubernetes-sigs#858 Closes kubernetes-sigs#727 Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mesutoezdil The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
8161d28 to
7fde87d
Compare
Move the XValidation rule to SandboxSpec so the API server enforces immutability for all transitions: set to modified set, unset to set, and set to unset. The previous rule on the optional field was skipped when the field was absent in either the old or new object. Regenerated CRDs via go generate ./... and docs via make generate-api-docs. Added e2e tests covering all three rejection cases. Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
7fde87d to
c51e561
Compare
|
Thanks @barney-s. Both points are addressed in the latest commit. |
|
/lgtm |
|
/lgtm |
1 similar comment
|
/lgtm |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
…mmutable # Conflicts: # api/v1beta1/sandbox_types.go
|
New changes are detected. LGTM label has been removed. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mesutoezdil The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughAdds a CEL-based immutability validation rule for ChangesvolumeClaimTemplates immutability
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This PR has been open since May 23, and in true fast-moving-monorepo fashion the codebase moved on without me. To be honest, six weeks for a small, self-contained CEL rule change is a long time to sit in review, long enough that the base branch drifted out from under it and turned a trivial merge into an archaeology exercise. It would help to get eyes on small API PRs like this sooner, before the diff itself becomes stale. @janetkuo @soltysh @barney-s @SHRUTI6991, tagging everyone who has already weighed in so this doesn't sit unnoticed again. Ready for another pass whenever you have time, hopefully without another multi-week wait and another round of drift to untangle. |
Move the XValidation rule from the optional `volumeClaimTemplates` field to the `SandboxSpec` parent struct so the API server enforces immutability for all three transitions: set to modified set, unset to set, and set to unset. The previous rule on the optional field was skipped when the field was absent in either the old or new object, leaving two gaps.
This aligns Sandbox with the StatefulSet immutability contract and prevents controller reconciliation failures or orphaned PVCs caused by post-creation mutations.
Related issue: 727
Changes
Summary by CodeRabbit
volumeClaimTemplatesafter a Sandbox is created.volumeClaimTemplatesis immutable after creation, while the matching template field remains editable.