Skip to content

fix(framework): default unset JobSet volumeClaimPolicies retentionPolicy - #4500

Open
aarushitandon0 wants to merge 1 commit into
kubeflow:masterfrom
aarushitandon0:fix/jobset-vcp-retention-default
Open

aarushitandon0 wants to merge 1 commit into
kubeflow:masterfrom
aarushitandon0:fix/jobset-vcp-retention-default

Conversation

@aarushitandon0

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

TrainJobs that use the TorchTune runtimes cannot be suspended or resumed. The JobSet update is rejected with spec.volumeClaimPolicies: Invalid value: Value is immutable, so the TrainJob and its JobSet go out of sync. For example, the TrainJob shows suspend: true while the JobSet keeps running, or the TrainJob is resumed while the JobSet stays suspended.

Root cause. In JobSet v0.13.0 (the version in go.mod):

  • The JobSet mutating webhook runs only on create. When volumeClaimPolicies[].retentionPolicy is unset, it sets it to {whenDeleted: Delete}.
  • volumeClaimPolicies is immutable (self == oldSelf, +listType=atomic).

The TorchTune runtimes define volumeClaimPolicies without a retentionPolicy, and Build() in the JobSet plugin passed that through as-is. The JobSet was stored with the webhook's default, but later server-side applies sent the policy without it. The API server then rejected those updates, including the ones for suspend and resume.

Fix. Build() now applies the same default that the webhook applies on create (whenDeleted: Delete) to any volumeClaimPolicies entry whose retentionPolicy is nil. The applied spec then matches the stored spec. An explicitly set retentionPolicy is left unchanged. The change is 10 lines in pkg/runtime/framework/plugins/jobset/jobset.go, plus one new TestBuild case. It makes no API or CRD changes.

Testing

Unit and static checks:

  • New case TestBuild/volumeClaimPolicies get the JobSet default retentionPolicy when it is unset covers two policies, one unset and one set to Retain. It checks that only the unset one is defaulted.
  • go test -count=1 ./pkg/runtime/framework/plugins/jobset/: 100 PASS, 0 FAIL.
  • make test: 27 packages ok, 0 FAIL.
  • gofmt, go vet: clean.
  • golangci-lint v2.14.0: 0 issues. on the package and on the whole repo.
  • Controller integration tests (test/integration/controller, envtest 1.37.0): 60 of 61 specs passed. The one failure is an [AfterAll] teardown timeout ("timeout waiting for process kube-apiserver to stop"), with no volumeClaimPolicies errors in the log. I did not run it against master.

Live test on kind (Kubernetes v1.37.0, Trainer Helm chart 2.4.0 with the default runtimes, JobSet v0.13.0, Kueue v0.20.7):

  • Each TrainJob replaced the trainer container with busybox sleep 3600 and used a tiny public model for the model initializer. The runtimes' volumeClaimPolicies were left untouched.
  • "Errors" means the number of volumeClaimPolicies ... immutable reconcile errors in the controller log for that TrainJob.
Scenario Controller Runs Result
Created suspended, then resumed (torchtune-llama3.2-1b) v2.4.0 ×2 TrainJob suspend=false, JobSet suspend=true, 0 pods, 5 and 3 errors
this PR ×2 for each of the 3 TorchTune runtimes JobSet suspend=false, 2 pods, 0 errors
Running, then suspended v2.4.0 ×2 for each of the 3 TorchTune runtimes TrainJob suspend=true, JobSet suspend=false, 1 pod still running, 15 errors
this PR ×2 for each of the 3 TorchTune runtimes JobSet suspend=true, 0 pods, 0 errors
Kueue: queued behind a job holding the GPU quota, then admitted v2.4.0 ×1 Admitted, but JobSet stayed suspend=true with 0 pods, 4 errors after admission (12 while queued)
this PR ×2 JobSet suspend=false, 1 pod, 0 errors
Runtime with an explicit retentionPolicy: {whenDeleted: Retain} v2.4.0 ×1 Works, 0 errors
this PR ×2 Works, 0 errors, JobSet keeps Retain
Runtime with retentionPolicy: {} (the API server stores whenDeleted: Delete) this PR ×2 Works, 0 errors
Upgrade: TrainJob stuck on v2.4.0, controller then switched to this PR v2.4.0 → this PR ×2 JobSet resumed with pods and 0 errors. TrainJob and JobSet UIDs unchanged
torch-distributed (no volumeClaimPolicies): run, suspend, resume v2.4.0 ×1, this PR ×2 Works on both, 0 errors

Related: #4441 is a different JobSet immutability problem, in spec.replicatedJobs after a v2.3 to v2.4 upgrade. This PR doesn't change it.

Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):
Fixes #4494

Checklist:

  • Docs included if any changes are user facing

The JobSet mutating webhook (verbs=create only) sets an unset
volumeClaimPolicies[].retentionPolicy to {whenDeleted: Delete}, and
volumeClaimPolicies is immutable (self == oldSelf). The JobSet plugin's
Build() left retentionPolicy unset, so later server-side applies of the
JobSet (seen on suspend, resume, and resume after Kueue admission) sent
a volumeClaimPolicies value that differed from the stored one. The API
server rejected those updates with "spec.volumeClaimPolicies: Invalid
value: Value is immutable". TorchTune runtimes, which define
volumeClaimPolicies without a retentionPolicy, therefore could not be
suspended or resumed.

Build() now applies the same default the webhook applies on create, so
the applied spec matches the stored spec. An explicitly set
retentionPolicy is left unchanged.

Fixes kubeflow#4494

Signed-off-by: Aarushi Tandon <aarushi.tandon0@gmail.com>
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign terrytangyuan for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • JobSet volume claims without an explicit retention policy are now deleted when the JobSet is deleted. Explicitly configured retention policies, including policies that retain claims, remain unchanged. This makes the default cleanup behavior consistent for volume claims that do not specify what should happen when their JobSet is removed.

JobSet Build now sets WhenDeleted: Delete on volume claim policies without a retention policy. Tests verify the default and confirm that an explicit WhenDeleted: Retain policy remains unchanged.

Changes: JobSet volume claim retention

Layer / File(s) Summary
Default retention and build validation
pkg/runtime/framework/plugins/jobset/jobset.go, pkg/runtime/framework/plugins/jobset/jobset_test.go
Build sets WhenDeleted: Delete when a volume claim policy has no retention policy. The test verifies the default and preservation of an explicit Retain policy.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • kubeflow/trainer#4441 — This change addresses retention-policy drift in JobSet updates, but does not address the issue’s separate replicatedJobs environment variable trigger.

Suggested reviewers: andreyvelich

Merge Risk: Minimal · up to d42bd

This change makes suspend and resume work again for TorchTune runtimes by applying the same retention default that JobSet sets at creation. It leaves explicit settings alone and has a targeted test. No merge-blocking risk remains.

Security architecture risk: Minimal · up to d42bd

The new default matches JobSet’s existing creation-time behavior and preserves explicitly configured retention policies. The inspected change does not establish increased privileges, broader resource access, or newly destructive cleanup behavior.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The default applies to every omitted retention policy processed by this plugin, not only TorchTune runtimes. Its direct scope is the generated JobSet policy list; existing construction and PVC creation retain the TrainJob and JobSet namespace boundaries.

Trust Boundaries and Controls

  • observed — The new loop does not select a different resource identity or override an explicit retention decision. The existing immutable-list validation remains the control against changing an established JobSet volume-claim policy.

Resilience and Maintainability Implications

  • observed — The inspected PVC reconciliation path treats AlreadyExists as a successful no-op rather than rewriting an existing PVC’s owner reference. Repeated reconciliation therefore does not retroactively transfer PVC ownership through this path.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Build() in the JobSet framework plugin now defaults unset volumeClaimPolicies retentionPolicy, matching the change in jobset.go and the new TestBuild case. It is speci…
Description check Passed The description explains the TorchTune suspend/resume failure, its root cause (create-only JobSet webhook default versus immutable volumeClaimPolicies), the fix in Build(), the tests run, and the link…
Linked Issues check Passed [#4494] The issue asks that suspend and resume reach the JobSet for the TorchTune runtimes. Its root cause is that the JobSet webhook defaults an unset volumeClaimPolicies[].retentionPolicy only on cr…
Out of Scope Changes check Passed The whole-PR changes are a 10-line defaulting loop in Build() in pkg/runtime/framework/plugins/jobset/jobset.go and a new TestBuild case in jobset_test.go. The loop is the fix for #4494. The test supp…
Full details: Title check

Explanation

The title names the main change: Build() in the JobSet framework plugin now defaults unset volumeClaimPolicies retentionPolicy, matching the change in jobset.go and the new TestBuild case. It is specific, one sentence, and matches the linked issue's fix.

Full details: Description check

Explanation

The description explains the TorchTune suspend/resume failure, its root cause (create-only JobSet webhook default versus immutable volumeClaimPolicies), the fix in Build(), the tests run, and the linked issue #4494. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

[#4494] The issue asks that suspend and resume reach the JobSet for the TorchTune runtimes. Its root cause is that the JobSet webhook defaults an unset volumeClaimPolicies[].retentionPolicy only on create, while Build() applies the runtime policy without it, so later applies fail the immutability check. The diff at head adds a loop in Build() in pkg/runtime/framework/plugins/jobset/jobset.go. For each volume claim policy with a nil RetentionPolicy, it sets WhenDeleted to RetentionPolicyDelete. This matches the proposed fix in the issue. Explicit retention policies are not changed. The PR also adds a TestBuild case that covers the unset and explicit cases. The applied spec now matches the stored spec, so already-stuck JobSets can recover on the next apply. The PR description reports live kind tests for suspend, resume, Kueue admission, and upgrade. I did not re-run those tests. The core requirement is covered by source evidence. Runtimes without volumeClaimPolicies are unaffected, as the issue expects.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes are a 10-line defaulting loop in Build() in pkg/runtime/framework/plugins/jobset/jobset.go and a new TestBuild case in jobset_test.go. The loop is the fix for #4494. The test supports that fix. The PR description states it makes no API or CRD changes, and the diff confirms no changes outside this plugin and its test. The PR does not touch #4441, which the issue lists as a separate problem and the PR description excludes. No unrelated changes were found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ae27d3f and d42bd52.

Files selected for processing: 2

  • pkg/runtime/framework/plugins/jobset/jobset.go
  • pkg/runtime/framework/plugins/jobset/jobset_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

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

Labels

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

TorchTune TrainJobs cannot be suspended or resumed: JobSet update fails with "spec.volumeClaimPolicies: Invalid value: Value is immutable"

1 participant