Skip to content

fix(api): reject TrainJob env names and resources that Pods cannot accept - #4293

Open
harshrajdebug wants to merge 1 commit into
kubeflow:masterfrom
harshrajdebug:fix/trainjob-pod-field-validation
Open

harshrajdebug wants to merge 1 commit into
kubeflow:masterfrom
harshrajdebug:fix/trainjob-pod-field-validation

Conversation

@harshrajdebug

Copy link
Copy Markdown

What this PR does / why we need it:

A TrainJob with an env var name containing =, or with resource requests above its limits, is admitted today. JobSet then fails to create its Jobs (JobCreationFailed event only), and the TrainJob never starts and gets no condition. Details and the kind reproduction are in #4292.

This PR adds validatePodFields to the TrainJob validating webhook. It checks the env names and resource requirements the user sets directly:

  • spec.trainer.env and spec.trainer.resourcesPerNode
  • spec.initializer.dataset.env and spec.initializer.model.env
  • env and resources of containers and init containers in spec.runtimePatches

Env names use validation.IsRelaxedEnvVarName, so only names that are invalid on every supported Kubernetes version are rejected. For resources, a request above the limit of the same resource is rejected; a request with no limit is still accepted.

On update the check runs only if the old object passes it, the same pattern used for the DRA feature gate fields. A TrainJob admitted before this check existed can still be suspended or have its patches changed, while an update that adds an invalid runtime patch is rejected.

The check does not look at values merged from the runtime template, for example a TrainJob request above a limit that only the runtime sets. That case needs the merged Pod spec and is left out of this change.

Tests:

  • Unit: TestValidateCreate covers every field with an invalid value and checks the field paths, plus a case where requests equal limits or have no limit. TestValidateUpdate covers an update that adds an invalid patch and an update of an already-invalid TrainJob.
  • Integration (test/integration/webhooks): trainer env A=B, requests above limits, and dataset initializer env A=B are rejected; valid names including my.config-1 and equal requests and limits are accepted. The three rejection entries fail on master.
  • go test ./pkg/..., the webhook (92) and controller (54) integration suites, and golangci-lint run ./... pass locally.

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

Checklist:

  • Docs included if any changes are user facing

…ot accept

Signed-off-by: Harsh Raj <harshrajdebug@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 astefanutti 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

@harshrajdebug harshrajdebug changed the title fix(webhooks): reject TrainJob env names and resources that Pods cannot accept fix(api): reject TrainJob env names and resources that Pods cannot accept Oct 23, 2026

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.

TrainJob accepts env names and resource requests that its Pods cannot use, and then never starts

1 participant