Files
trainer/pkg/runtime/framework/plugins
Sabari NarayanaandGitHub 844656a01d fix(api): allow atomic RuntimePatches update on unsuspend (#3469)
* fix(webhook): allow atomic RuntimePatches update on unsuspend

Change checkRuntimePatchesImmutability to check the *old* TrainJob's
suspend state instead of the new one. This lets external controllers
(notably Kueue, see kubernetes-sigs/kueue#8296) modify spec.runtimePatches
and set spec.suspend=false in a single API request, eliminating the
two-step update workaround and the race window between the calls.

Mirrors the Kubernetes core Job validation pattern:
https://github.com/kubernetes/kubernetes/blob/86b66f6f333a/pkg/registry/batch/job/strategy.go#L191

The downstream JobSet activity check (no active replicatedJobs) still
runs, so updates while pods are running remain forbidden.

Refs: #3043
Signed-off-by: Sabari Narayana <[email protected]>

* test(jobset): cover atomic suspend->unsuspend RuntimePatches update

Add a unit test that exercises the new atomic-update path: a single
TrainJob update that both clears spec.suspend and modifies
spec.runtimePatches must succeed when the previous state was suspended.

Refs: #3043
Signed-off-by: Sabari Narayana <[email protected]>

* test(integration): cover atomic unsuspend + RuntimePatches update

Extend the trainjob webhook update table with an entry that creates a
suspended TrainJob with RuntimePatches and then, in a single Update,
both unsuspends it and modifies the runtimePatches NodeSelector. This
exercises the relaxed validation against a real apiserver and protects
the suspended -> unsuspended transition path used by Kueue.

Refs: #3043
Signed-off-by: Sabari Narayana <[email protected]>

* fix(api): block RuntimePatches change only when both states are unsuspended

Per @mimowo's review, the previous condition (!oldSuspended) over-blocked
the (oldSuspended=false, newSuspended=true) transition — i.e. suspending
a running TrainJob while modifying spec.runtimePatches in the same call,
which is safe because the JobSet activity check still guards against
concurrent pod runs.

Change the predicate to !oldSuspended && !newSuspended so the webhook
only forbids RuntimePatches mutations when the TrainJob is staying fully
unsuspended. Reword the error message accordingly so callers see
explicitly that suspension at either side of the update is acceptable.

Refs: #3043, kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

* test: cover unsuspended->suspended atomic RuntimePatches transition

Per @mimowo's request, complete the transition table coverage:

- (false, false) -> blocked   (existing test)
- (true,  true)  -> allowed   (existing test)
- (true,  false) -> allowed   (added previously)
- (false, true)  -> allowed   (added here)

Mirrors the existing atomic-unsuspend cases — one unit case in
jobset_test.go and one webhook integration entry in trainjob_test.go.

Refs: #3043, kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

* docs(api): shorten RuntimePatches validation comment

Trim the comment block above checkRuntimePatchesImmutability to a 4-line
summary, per @kaisoz's review feedback (the comment was longer than the
change itself). Drops the kueue#8296 backreference and the k/k Job
validation link — both are already in the PR description and commit
history.

Refs: kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

* fix(api): use stdlib for suspend pointer checks in jobset webhook

Per @tenzen-y's review nit, swap the ptr.Equal(x, ptr.To(true)) idiom
for an inline nil-check + dereference. Equivalent semantics, no extra
generic-comparison hop, and stays in the stdlib for these two lines.

Refs: kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

* test(jobset): cover (false,true) transition with active jobSet

Per @tenzen-y's request, add a unit case where the old TrainJob is
unsuspended, the new one is being suspended with a runtimePatches
change, and the underlying JobSet still has an active replicatedJob.
The relaxed suspend predicate alone would let this through; the
JobSet activity check should still reject it.

Refs: kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

* test(integration): drop atomic transition cases duplicated by UTs

Per @tenzen-y's review, the two atomic-transition ginkgo entries
(unsuspend + RuntimePatches, suspend + RuntimePatches) duplicate the
unit cases in jobset_test.go that already exercise the same validator
path. The pre-existing "Should succeed to update runtimePatches when
suspend is true" entry stays as the integration smoke test for the
webhook chain.

Refs: kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

* fix(api): use new(true) for suspend pointer comparisons

@tenzen-y is right that the value-form `new()` builtin is valid Go 1.26,
which the repo already targets (`go 1.26.0` in go.mod). Apply his
original suggestion verbatim — keeps `ptr.Equal` for the two-pointer
comparison and replaces only `ptr.To(true)`, which is the smaller and
more idiomatic delta vs the inline nil-check + deref pattern I tried
in the previous commit.

Refs: kubeflow/trainer#3469 (review feedback)
Signed-off-by: Sabari Narayana <[email protected]>

---------

Signed-off-by: Sabari Narayana <[email protected]>
2026-05-05 04:52:26 +00:00
..