Skip to content

fix(api): validate OptimizationJob parameter names - #4062

Open
mimosapudical wants to merge 1 commit into
kubeflow:masterfrom
mimosapudical:fix-optimizationjob-parameter-name-validation-v2
Open

mimosapudical wants to merge 1 commit into
kubeflow:masterfrom
mimosapudical:fix-optimizationjob-parameter-name-validation-v2

Conversation

@mimosapudical

Copy link
Copy Markdown

What this PR does / why we need it:

Adds admission-time validation for OptimizationJob.spec.parameters[].name.

Parameter.Name is later used when generating environment variable names. Values such as weight/decay or n layers currently pass OptimizationJob admission but can fail later during TrainJob creation because they produce invalid environment variable names.

This PR adds the following kubebuilder validation pattern:

^[A-Za-z_][A-Za-z0-9_]*$

This allows names such as learning_rate, _lr, and batch_size2, while rejecting invalid names such as weight/decay, n layers, 1learning_rate, and learning-rate.

It also:

  • regenerates the OptimizationJob CRD manifests;
  • adds admission-level integration coverage for valid and invalid parameter names.

This is a follow-up to #3828, where this validation was intentionally split into a separate PR.

Which issue(s) this PR fixes:

N/A — follow-up to #3828.

Checklist:

@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 andreyvelich 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

@mimosapudical

Copy link
Copy Markdown
Author

@andreyvelich This is the follow-up to the Parameter.Name validation discussion in #3828. Thanks!

@saivedant169 saivedant169 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this locally at f74b781. The specs pass on the 1.37 envtest, and if I drop the pattern from the CRD the slash case fails, so the test is doing its job. CRDs regenerate with no diff, lint and KAL are clean. Couple of small things inline.

Comment thread test/integration/webhooks/optimizationjob_test.go
Comment thread pkg/apis/trainer/v1alpha1/optimizationjob_types.go
Comment thread test/integration/webhooks/optimizationjob_test.go Outdated
@mimosapudical
mimosapudical force-pushed the fix-optimizationjob-parameter-name-validation-v2 branch from 0671455 to 23a4324 Compare September 21, 2026 03:50
@mimosapudical

Copy link
Copy Markdown
Author

@saivedant169 Addressed all review comments in the latest commit, including the additional validation cases, clearer GoDoc, and the fixed test job name. Could you please take another look when you have a chance?

@saivedant169

Copy link
Copy Markdown
Member

looks good, thanks for turning it around so fast

@mimosapudical

Copy link
Copy Markdown
Author

@akshaychitneni @robert-bell The latest changes have been reviewed and all feedback has been addressed. Would one of you mind taking a look and adding /lgtm if everything looks good? Thanks!

@robert-bell robert-bell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mimosapudical! Just a small nit but otherwise looks good. Ptal.

"github.com/kubeflow/trainer/v2/test/integration/framework"
)

func makeOptimizationJob(namespace, name, parameterName string) *trainer.OptimizationJob {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we create a wrapper type in pkg/util/testing please?

func MakeJobSetWrapper(namespace, name string) *JobSetWrapper {
?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we create a wrapper type in pkg/util/testing please?

func MakeJobSetWrapper(namespace, name string) *JobSetWrapper {

?

Done — I added an OptimizationJobWrapper in pkg/util/testing/wrapper.go and updated the integration test to use it instead of the local helper. Thanks! @robert-bell

@robert-bell

Copy link
Copy Markdown
Member

/ok-to-test

@robert-bell robert-bell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @mimosapudical!

/lgtm

cc @andreyvelich for approval

@robert-bell

Copy link
Copy Markdown
Member

@mimosapudical can you please sign your commits?

@mimosapudical
mimosapudical force-pushed the fix-optimizationjob-parameter-name-validation-v2 branch from 3936e58 to 1e5b351 Compare September 25, 2026 21:26
@google-oss-prow google-oss-prow Bot removed the lgtm label Sep 25, 2026
@mimosapudical

Copy link
Copy Markdown
Author

@mimosapudical can you please sign your commits?

All commits are now signed and verified. The force-push only rewrote the commits to add signatures; there are no code changes. Could you please re-add /lgtm when you have a chance?

@mimosapudical

Copy link
Copy Markdown
Author

@robert-bell All commits are now signed and the requested changes are unchanged. Could you re-add /lgtm when you have a chance? Thanks!

@robert-bell

Copy link
Copy Markdown
Member

Thanks @mimosapudical!

/lgtm

@google-oss-prow google-oss-prow Bot added the lgtm label Oct 9, 2026
@robert-bell

Copy link
Copy Markdown
Member

@mimosapudical the DCO check is still failing. Can you please check your commits are signed? There's instructions on the DCO action. Thanks!

@mimosapudical
mimosapudical force-pushed the fix-optimizationjob-parameter-name-validation-v2 branch from 1e5b351 to eb7a9dc Compare October 10, 2026 05:44
@google-oss-prow google-oss-prow Bot removed the lgtm label Oct 10, 2026
@google-oss-prow

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@akshaychitneni

Copy link
Copy Markdown
Contributor

/milestone v2.4

@google-oss-prow google-oss-prow Bot added this to the v2.4 milestone Oct 22, 2026
@akshaychitneni

Copy link
Copy Markdown
Contributor

@mimosapudical could you please rebase and address conflicts?

Retain upstream OptimizationJob webhook cases and generated API changes
while adding parameter name admission validation and regression coverage.

Signed-off-by: mimosapudical <153621177+mimosapudical@users.noreply.github.com>
@mimosapudical
mimosapudical force-pushed the fix-optimizationjob-parameter-name-validation-v2 branch from 7c20b0e to f625380 Compare October 22, 2026 15:57
@google-oss-prow google-oss-prow Bot added size/M and removed size/L labels Oct 22, 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

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

4 participants