Repository navigation
feat(deploy/sbx): SBX_STORAGE_CLASS, one storage class for every claim SBX0 creates - #887
Conversation
…m SBX0 creates A cluster with no default StorageClass (one OpenShift rig this deployed on) leaves every PVC SBX0 creates Pending until an operator patches it by hand -- three times over once the template store and the egress credential store are on. SBX_STORAGE_CLASS writes one storageClassName into the redis StatefulSet's volumeClaimTemplates and each component's PVC, on the runs that render them: a patch naming an absent PVC fails the kustomize build, so the store's and the egress store's are emitted only with their components on. Fresh claims only: a claim that already exists keeps the class it was created with, so an upgrade from before this knob patches those once by hand. Unset changes nothing (the generated overlay is byte-identical). Low priority: a convenience knob, not a correctness fix. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: George Almasi <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
The knob works on fresh namespaces with the sandbox profile, and the tests cover that well: the refusal, the base and store+egress shapes, and the golden check that an unset value changes nothing. There are two gaps. (1) On a namespace that already exists, the apply is rejected because the StatefulSet's volumeClaimTemplates can't be changed in place. That's the upgrade case the header documents, and it's the rig this PR was written for. (2) The combined profile's moca-credentials PVC isn't patched. Also, SBX_STORAGE_CLASS isn't in the settings table in deploy/sbx/README.md, which lists the other optional knobs such as SBX_REDIS_IMAGE; it's worth adding a row.
Assisted-By: Claude Code
| # components are on. Fresh claims only -- a claim that already exists (an upgrade on a | ||
| # deployment from before this knob) keeps the class it was created with. | ||
| if [[ -n "${SBX_STORAGE_CLASS:-}" ]]; then | ||
| printf ' - target: { kind: StatefulSet, name: redis }\n patch: |-\n - { op: add, path: /spec/volumeClaimTemplates/0/spec/storageClassName, value: %s }\n' "$SBX_STORAGE_CLASS" |
There was a problem hiding this comment.
must-fix: existing namespaces can't apply this. Kubernetes won't let you change volumeClaimTemplates on a StatefulSet that already exists; only replicas, ordinals, template, updateStrategy, PVC retention policy and minReadySeconds can change. On a namespace deployed before this knob, setting SBX_STORAGE_CLASS adds storageClassName to the live redis template, so kc apply -k gets Forbidden and the run dies under set -e before the rollouts and bundles. It keeps failing on every run until the variable is unset.
The rig that motivated this PR is that exact case: deployed, with PVCs patched by hand. The header (lines 79-81) says "patches those once by hand (kubectl patch pvc)", but patching the PVC doesn't help, because the StatefulSet is what's rejected.
Suggested fix: a preflight like check_redis_image. Read the live StatefulSet's .spec.volumeClaimTemplates[0].spec.storageClassName, and if it's set and differs, or unset while SBX_STORAGE_CLASS is set, refuse with the fix: kubectl -n $NS delete sts redis --cascade=orphan, then re-run (the pod and data-redis-0 survive). Then fix the header to match.
| # deployment from before this knob) keeps the class it was created with. | ||
| if [[ -n "${SBX_STORAGE_CLASS:-}" ]]; then | ||
| printf ' - target: { kind: StatefulSet, name: redis }\n patch: |-\n - { op: add, path: /spec/volumeClaimTemplates/0/spec/storageClassName, value: %s }\n' "$SBX_STORAGE_CLASS" | ||
| if [[ -n "$STORE_ON" || -n "$COMBINED" ]]; then |
There was a problem hiding this comment.
must-fix: one claim is missed with SBX_PROFILE=combined. ocp-combined also renders pvc-credentials.yaml, the moca-credentials PVC for the harness's file credential store. The patch doesn't cover it, so on a cluster with no default class that claim stays Pending and moca-control-plane never rolls out. That contradicts "every claim SBX0 creates".
Fix: add [[ -z "$COMBINED" ]] || printf ...moca-credentials..., plus a combined-profile case in setup.test.sh §13c that asserts all three PVCs and the redis template.
| # components are on. Fresh claims only -- a claim that already exists (an upgrade on a | ||
| # deployment from before this knob) keeps the class it was created with. | ||
| if [[ -n "${SBX_STORAGE_CLASS:-}" ]]; then | ||
| printf ' - target: { kind: StatefulSet, name: redis }\n patch: |-\n - { op: add, path: /spec/volumeClaimTemplates/0/spec/storageClassName, value: %s }\n' "$SBX_STORAGE_CLASS" |
There was a problem hiding this comment.
nit: value: %s goes into the YAML unquoted. The regex accepts names that YAML reads as non-strings, like 123 or 1e3, and the render would then fail on a type error. Quote it as value: "%s" in all three printfs, the same way the settings-hash patches already do.
… quoted values Review #887, three required changes: - A live redis StatefulSet cannot take the knob: volumeClaimTemplates are immutable once the StatefulSet exists, so the patch made every later apply Forbidden and the run died under set -e before the rollouts and bundles -- the exact upgrade case the header documented, and the rig this knob was written for. check_storage_class now reads the live template's class and refuses a mismatching run (set and different, or unset while the knob is set) before anything is applied; a fresh namespace, a matching class and an unset knob pass. The header says what to do instead: leave the variable unset for that deployment, or recreate the StatefulSet and its claim. - Combined renders a third claim this knob missed (moca-credentials, the harness's file credential store, ocp-combined's pvc-credentials.yaml): on a no-default-class cluster it stayed Pending and the control plane never rolled out. The patch is emitted for it too, and a combined test case asserts all of redis's templates, the template store's PVC and moca-credentials. - The patch values are quoted ("%s"), like the settings hashes: a name the regex accepts but YAML would read as a non-string must fail the render, not silently change type. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: George Almasi <[email protected]>
|
All three required changes addressed in 1d41dd9:
Assisted-By: Claude Code |
pdettori
left a comment
There was a problem hiding this comment.
1d41dd9 resolves both earlier must-fixes (the existing-StatefulSet preflight, and combined's moca-credentials) and the quoting nit. One gap remains, the mirror image of the first must-fix: if a later run drops the knob, server-side apply removes the class it owns and gets the same Forbidden, and test 13c' asserts that this case passes. Also, the SBX_STORAGE_CLASS row in the deploy/sbx/README.md settings table (from the first review) is still missing. It's not blocking, but it's worth adding next to SBX_REDIS_IMAGE.
Assisted-By: Claude Code
| # of a Pending claim is allowed -- but a BOUND one keeps its class, so those are the operator's | ||
| # one-time kubectl patch, as the header says. | ||
| check_storage_class() { | ||
| [[ -n "${SBX_STORAGE_CLASS:-}" ]] || return 0 |
There was a problem hiding this comment.
must-fix: the reverse case is still Forbidden. This returns early when the knob is unset. But a live redis template with a class can only have come from an earlier knob run, because base/redis.yaml sets none. The apply is --server-side --field-manager=sbx-setup. If a later run drops SBX_STORAGE_CLASS (say the env file loses the line), SSA removes the storageClassName field that sbx-setup owns. That changes volumeClaimTemplates, so the apply gets the same Forbidden as the forward case, partway through the object stream.
Fix: when the knob is unset, still read the live template, and refuse if live is non-empty, naming the fix (set SBX_STORAGE_CLASS=<live>).
| { cat "$TMP/out" >&2; fail 'a matching class on an existing StatefulSet was refused'; } | ||
| reset_state | ||
| redis_sts_class 'ocs-storagecluster-ceph-rbd' | ||
| run_setup true || { cat "$TMP/out" >&2; fail 'the knob unset on an existing StatefulSet was refused'; } |
There was a problem hiding this comment.
must-fix (same issue as setup.sh:673): this case asserts that a live class with the knob unset passes. The mock doesn't model SSA dropping a field the manager no longer applies, so this locks in the behaviour that fails on a real cluster. It should expect a refusal that names the live class.
| [[ -n "$json" ]] || return 0 | ||
| live="$(jq -r '.spec.volumeClaimTemplates[0].spec.storageClassName // empty' <<<"$json")" | ||
| [[ "$live" == "$SBX_STORAGE_CLASS" ]] || | ||
| die "StatefulSet redis in $NS already exists with volumeClaimTemplates its API refuses to change in place (live class: '${live:-unset}'), so SBX_STORAGE_CLASS=$SBX_STORAGE_CLASS cannot be applied: leave it unset for this deployment (its claims keep the class they were created with), or recreate the StatefulSet (delete the data-redis-0 claim too -- redis data does not survive) and re-run" |
There was a problem hiding this comment.
suggestion: this recovery path deletes data when it doesn't need to ("delete the data-redis-0 claim too -- redis data does not survive"). kubectl -n $NS delete sts redis --cascade=orphan followed by a re-run keeps the pod and data-redis-0: the new StatefulSet adopts both, and the claim keeps the class it already has. On the rig this PR targets, those claims were already hand-patched to the right class. Suggest the orphan path here, and match the header text at line 85.
…e recovery Review #887, round 2: - The reverse case is as Forbidden as the forward one: a live redis template with a class can only have come from an earlier knob run (base/redis.yaml sets none), and the apply is server-side with one field manager -- a later run with the knob unset DROPS the storageClassName that manager owns, which changes volumeClaimTemplates and is refused partway through the object stream. check_storage_class no longer returns early when the knob is unset: a non-empty live class refuses, naming the fix (keep SBX_STORAGE_CLASS at the live class). - The test asserted the reverse case passes; the mock cannot model SSA dropping an unmanaged field, so it locked in the behaviour that fails on a real cluster. It now expects the refusal naming the class, with a separate no-live-class case (a deployment from before the knob) that still passes. - The recovery path deletes data it does not need to: kubectl delete sts redis --cascade=orphan, then a re-run, keeps the pod and the data-redis-0 claim -- the new StatefulSet adopts both, and the claim keeps the class it already has. The refusal and the header now say the orphan path instead of deleting the claim. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: George Almasi <[email protected]>
|
Round 2 addressed in 8d68ffa — you were right on all three, and the reverse case was a genuine hole in my preflight:
Assisted-By: Claude Code |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Re-review — the reverse case is fixed; the component claims still aren't preflighted
8d68ffaa is new since the 1d41dd9 draft I wrote on 2026-11-18 (never posted; this review replaces it). It fixes the round-2 must-fix and replaces the destructive recovery advice.
Fixed in this commit
- The reverse case is now refused.
check_storage_classruns unconditionally, reads the livestorageClassNameand refuses both directions: knob set and differing, and knob unset against a live class — naming the live class as the fix, which is the actionable form because a plain re-run with the knob at the live value is a no-op. The reasoning in the comment is right: the base sets no class, so a live class came from an earlier knob run, and SSA with one field manager would drop the field it no longer owns, which changesvolumeClaimTemplatesand is Forbidden. - The recovery advice is safe now.
kubectl delete sts redis --cascade=orphankeeps the pod and thedata-redis-0claim; the re-run's StatefulSet adopts both. The previous text told the operator to delete the claim too ("redis data does not survive"), which was unnecessary data loss. - Tests match: the reverse case asserts the refusal and that it names
SBX_STORAGE_CLASS=<live>, and a new case keeps "knob unset, no live class" passing — the common pre-knob deployment. CI is 16/16 green.
Still open (carried from the unposted draft)
- The component claims have the same failure and no preflight.
write_overlaypatches the class ontomoca-sbx-templates,moca-sbx-credentialsandmoca-credentials(setup.sh:1185-1194), andapply_manifestapplies with--server-side --field-manager=sbx-setup(:736,:999) — the same manager, so a run that drops or changesSBX_STORAGE_CLASSremoves the field from those claims too.PVC.spec.storageClassNameis immutable apart from nil→set, so that is the same Forbidden, one object later in the stream (redis passes, then the claim fails partway through the apply).check_storage_classreads onlystatefulset redis. Must-fix: read each claim this run renders and refuse the same two directions before applying. SBX_STORAGE_CLASSstill has no settings row. The knob is documented only in the header comment. On currentmainthe settings table isdocs/operate/sandbox-service/install.md(#916 moved it), so the row belongs there now.
Notes: the branch is ~100 commits behind main but merges cleanly (mergeable: MERGEABLE, no conflict in git merge-tree); CI at this head ran against the older base, so a re-run after a rebase would be worth having.
Author: pdettori (MEMBER — maintainer). Agent/IDE config: none. Commits: 3, all signed off.
| if [[ -n "${SBX_STORAGE_CLASS:-}" ]]; then | ||
| printf ' - target: { kind: StatefulSet, name: redis }\n patch: |-\n - { op: add, path: /spec/volumeClaimTemplates/0/spec/storageClassName, value: "%s" }\n' "$SBX_STORAGE_CLASS" | ||
| if [[ -n "$STORE_ON" || -n "$COMBINED" ]]; then | ||
| printf ' - target: { kind: PersistentVolumeClaim, name: moca-sbx-templates }\n patch: |-\n - { op: add, path: /spec/storageClassName, value: "%s" }\n' "$SBX_STORAGE_CLASS" |
There was a problem hiding this comment.
must-fix: these three claims get the class from the same field manager as the StatefulSet (apply_manifest uses --server-side --field-manager=sbx-setup, :736 and :999), but nothing preflights them. A run that drops or changes SBX_STORAGE_CLASS makes SSA remove storageClassName from moca-sbx-templates, moca-sbx-credentials (here) and moca-credentials (:1194), and PVC.spec.storageClassName is immutable apart from nil→set — the same Forbidden the redis check now refuses, only one object later in the stream: redis passes the preflight and the apply then fails partway through.
check_storage_class can cover them the same way, for each claim this run renders (STORE_ON/EGRESS_ON/COMBINED): kc get pvc <name> -n "$NS" --ignore-not-found -o json, then jq -r '.spec.storageClassName // empty', refusing a set-knob mismatch and an unset knob against a live class. Fresh deployments still pass, and it keeps the "refuse before anything is applied" property the header promises.
PVC.spec.storageClassName is immutable once set (the API allows only nil to set), and the render's patches apply with the same field manager as the redis one, so a run whose knob disagrees with a live claim this run renders was the same Forbidden one object later in the stream -- redis applied, then the claim failed partway through. check_storage_class now reads each claim this run renders (rendered_pvc_claims mirrors write_overlay's patch conditions, so an unrendered claim is neither patched nor read) and refuses both directions before anything is applied: set and differing, and unset against a class an earlier knob run set (server-side apply would drop the field its manager owns). A classless claim passes against a set knob -- nil to set is the one transition the API allows. Also the SBX_STORAGE_CLASS row in the settings table (docs/operate/sandbox-service/install.md, where #916 moved it from the README), and main merged in so the row lands where the table now lives. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: George Almasi <[email protected]>
|
Round 3 addressed in 265c747 (after merging current main in, so CI runs against the new base and the settings row lands where #916
Tests: a 13c''' matrix against seeded live PVCs (both refusals before any apply, matching and classless pass, and a claim the run Assisted-By: Claude Code |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review — fix(deploy/sbx): SBX_STORAGE_CLASS preflights the component claims too
The must-fix from the last round is addressed, in the shape I hoped for. rendered_pvc_claims mirrors write_overlay's three conditions exactly (STORE_ON || COMBINED → moca-sbx-templates, EGRESS_ON → moca-sbx-credentials, COMBINED → moca-credentials), check_claim_class runs in preflight before anything is applied, and nil → set is correctly the one allowed direction. The failure is refused on the same field manager and the same object stream as before, so the mid-apply Forbidden is gone.
- The tests cover both refusal directions on a claim, the matching and classless passes, combined's own
moca-credentials, the "claim this run does not render is neither patched nor read" case, and that a refusal applies nothing (the mock log check). The settings row now lives indocs/operate/sandbox-service/install.mdwhere #916 moved the table. - The merge of
mainis clean, and the earlier round's items (reverse case for redis, orphan-delete guidance) survive it. CI 18/18.
One suggestion inline about the reverse direction on a PVC: the live class is not necessarily one sbx-setup set, and the refusal (and its message) should be exact about whose field it is.
Author: galmasi (MEMBER — maintainer).
| [[ "$live" == "$SBX_STORAGE_CLASS" ]] || | ||
| die "PVC $1 in $NS already exists with storageClassName '$live', which the API refuses to change in place (PVC.spec.storageClassName is immutable, apart from nil to set), so SBX_STORAGE_CLASS=$SBX_STORAGE_CLASS cannot be applied: keep SBX_STORAGE_CLASS=$live for this deployment (the claim keeps the class it was created with), or, to change it, kubectl -n $NS delete pvc $1 (its contents do not survive) and re-run" | ||
| else | ||
| die "PVC $1 in $NS carries storageClassName '$live' an earlier SBX_STORAGE_CLASS run set, and this run has SBX_STORAGE_CLASS unset: the apply would remove the field (server-side apply drops what its field manager no longer owns), which the API refuses on a set class. Set SBX_STORAGE_CLASS=$live (the claim keeps that class either way)" |
There was a problem hiding this comment.
suggestion: this reverse direction assumes the live class is one sbx-setup set, which is not true for a PVC. The manifests leave storageClassName out, so on a cluster with a default StorageClass the admission plugin fills it at creation; and an operator who patched a Pending claim by hand (the remedy this header documented before the round-2 change) leaves the field owned by kubectl-patch or whichever tool patched it. Server-side apply drops only fields the applying manager previously owned and no longer specifies, so for a claim whose class belongs to another manager this refuses a run that would have succeeded — and the message's "an earlier SBX_STORAGE_CLASS run set" then names a cause that did not happen. metadata.managedFields on the live claim settles it exactly: refuse only when the entry with manager: sbx-setup owns f:spec/f:storageClassName (that is also the only case where the drop is real). A test with a foreign-owned class would pin the intended behaviour; if the strict refusal is deliberate instead, the message should say the class may come from the cluster's default StorageClass, not only from a knob run.
…r knob run applied With SBX_STORAGE_CLASS unset, check_claim_class refused any live claim that carried a storageClassName, as 'set by an earlier SBX_STORAGE_CLASS run'. On a cluster with a default StorageClass, the DefaultStorageClass admission plugin fills that class in when the claim is created, so every deployment set up before #887 was refused at its next setup.sh. The claims come from the overlay, which apply_stack applies client-side (kubectl apply -k); its three-way merge removes a field only when the last-applied-configuration annotation has it and the new config does not. A class admission filled in is on the claim but not in that annotation, so a knob-unset apply leaves it alone. Refuse only when the annotation carries the class (an earlier knob run applied it); log the kept class otherwise; and refuse, fail-closed, when the annotation is there but not valid JSON, since the run can't tell who set the class. A set knob that differs is still refused. The StatefulSet half is unchanged: admission does not fill volumeClaimTemplates. Closes #935 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
What
Low priority — a convenience knob for clusters with no default StorageClass.
On such a cluster (one OpenShift rig this was deployed on), every PVC SBX0 creates sits Pending until an operator patches it by hand — three times over once the template store and the egress credential store are enabled.
SBX_STORAGE_CLASSwrites onestorageClassNameinto:volumeClaimTemplates(always rendered)Details
setup.test.shproves it)-and.) so a typo is named before a pend isTests
Refusal for a bad name; positive runs asserting the class on the redis templates (base shape) and on both PVCs (store + egress on); the golden byte-identical check covers the unset shape.
setup.test.shgreen.Assisted-By: Claude Code