Skip to content

fix(webhook): separate CronJob validation errors with "; " - #5610

Merged
volcano-sh-bot merged 1 commit into
volcano-sh:masterfrom
aeron-gh:fix/cronjob-validate-error-separator
Jul 9, 2026
Merged

fix(webhook): separate CronJob validation errors with "; "#5610
volcano-sh-bot merged 1 commit into
volcano-sh:masterfrom
aeron-gh:fix/cronjob-validate-error-separator

Conversation

@aeron-gh

@aeron-gh aeron-gh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

/kind bug

When a CronJob fails more than one check at once (say a bad schedule and a name over the length limit), the webhook joined the messages with no separator, so the rejection came out as one run-on line. This trims each validator message and joins the non-empty ones with "; " so each error reads on its own.

It's the CronJob version of the PodGroup fix in #5487 (same collect-and-join, with the leading/trailing whitespace trimmed for a clean result). Going by @hajnalmt's grep on that PR, this was the last spot left with the pattern. It's one validateCronJob helper shared by the create and update paths, plus a couple of tests.

Scoped to the CronJob webhook. The admit_job.go cleanup the issue mentions uses a different convention (its own leading-space / trailing-; style), so it's better kept as a separate change.

Thanks @anxkhn for starting this off in #5533. I opened this since it's issue (#5489) and I already had the same pattern from #5487.

Fixes #5489

NONE

Copilot AI review requested due to automatic review settings July 8, 2026 18:34
@volcano-sh-bot volcano-sh-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 8, 2026
@volcano-sh-bot volcano-sh-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the CronJob validation logic by introducing a helper function validateCronJob that aggregates validation errors and joins them with a semicolon separator, along with adding corresponding unit tests. The review feedback suggests trimming leading and trailing whitespace from the individual validation messages before joining them to ensure clean, consistent error formatting, and updating the unit tests accordingly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/webhooks/admission/cronjobs/validate/admit_cronjob.go
Comment thread pkg/webhooks/admission/cronjobs/validate/admit_cronjob_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes CronJob admission webhook validation output so that when multiple validators fail, their error messages are separated by "; " instead of being concatenated into a run-on string. This improves readability of rejection messages while keeping single-error messages unchanged.

Changes:

  • Introduced a shared validateCronJob helper that collects non-empty validator messages and joins them with "; ".
  • Updated both create and update validation paths to use the shared helper.
  • Added regression tests for multi-error separation and single-error unchanged behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/webhooks/admission/cronjobs/validate/admit_cronjob.go Adds validateCronJob helper and routes create/update validation through it, joining multiple error messages with "; ".
pkg/webhooks/admission/cronjobs/validate/admit_cronjob_test.go Adds tests asserting multi-error messages include "; " and single-error messages are unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When a CronJob failed more than one check, the messages were joined with
no separator and ran together in one line. Trim each validator message
and join the non-empty ones with "; " so they read as separate items.

Signed-off-by: aeron-gh <agab0323@gmail.com>
@aeron-gh
aeron-gh force-pushed the fix/cronjob-validate-error-separator branch from 1d8c2a2 to 6d60d92 Compare July 8, 2026 18:53
@aeron-gh

aeron-gh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

e2e-shard / E2E Agent Scheduler Soft looks like an unrelated flake The rest is green. Re-running to confirm.

@aeron-gh aeron-gh closed this Jul 9, 2026
@aeron-gh aeron-gh reopened this Jul 9, 2026

@hajnalmt hajnalmt 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.

/area webhooks
/approve
/lgtm

Thank you for the contribution!

func TestValidateCronJobSeparatesMultipleErrors(t *testing.T) {
cronjob := &v1alpha1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: strings.Repeat("a", 53),

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.

I really like these funny touches in our tests 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks @hajnalmt! Glad the tests landed well 😄 Appreciate the quick review.

@volcano-sh-bot volcano-sh-bot added area/webhooks lgtm Indicates that a PR is ready to be merged. labels Jul 9, 2026
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hajnalmt

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

The pull request process is described 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

@volcano-sh-bot volcano-sh-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 9, 2026
@volcano-sh-bot
volcano-sh-bot merged commit 34b8029 into volcano-sh:master Jul 9, 2026
58 of 59 checks passed
@aeron-gh
aeron-gh deleted the fix/cronjob-validate-error-separator branch July 10, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/webhooks kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CronJob validation webhook concatenates multiple errors without a separator

4 participants