Skip to content

feat(webhook): report validation failures as structured field errors - #3147

Open
rjgoyln wants to merge 1 commit into
kubeflow:masterfrom
rjgoyln:feat/webhook-structured-validation-errors
Open

rjgoyln wants to merge 1 commit into
kubeflow:masterfrom
rjgoyln:feat/webhook-structured-validation-errors

Conversation

@rjgoyln

@rjgoyln rjgoyln commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Webhook validators currently reject invalid resources with hand-written error messages that do not identify the offending field. As a result, kubectl prints an opaque error and clients cannot determine which part of the spec needs to be fixed.

Emitting k8s.io/apimachinery field errors allows the API server to return structured, per-field validation causes.

Closes #3131.

Change

  • Validators now return field.ErrorList, which is wrapped with apierrors.NewInvalid at the admission entry points.
  • SparkConfKeyDeniedError is replaced with field.Forbidden on the offending spec.sparkConf key.
  • An exhausted ResourceQuota is returned with NewForbidden, while a failed quota lookup is returned with NewInternalError, since neither represents an invalid field.

Fail-fast behavior is preserved, so causes normally contains one entry; error aggregation is tracked separately in #3133.

SparkApplication still does not validate spec.driver.memory or spec.executor.memory, so an unparseable value is not reported with a field path. Adding this validation would reject specs that are currently accepted, so it is left for a follow-up.

Behavior change

Validation rejections that identify a bad field now return 422 Invalid with per-field details.causes. Previously, all webhook rejections were returned as 403 Forbidden with a single error message.

An exhausted ResourceQuota remains 403 Forbidden.

Change Category

  • Bugfix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that could affect existing functionality)
  • Documentation update

Checklist

  • I have conducted a self-review of my own code.
  • I have updated documentation accordingly.
  • I have added tests that prove my changes are effective or that my feature works.
  • Existing unit tests pass locally with my changes.

🤖 Generated with Claude Code

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

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

🎉 Welcome to the Kubeflow Spark Operator! 🎉

Thanks for opening your first PR! We're happy to have you as part of our community 🚀

Here's what happens next:

Join the community:

Feel free to ask questions in the comments if you need any help or clarification!
Thanks again for contributing to Kubeflow! 🙏

@rjgoyln
rjgoyln force-pushed the feat/webhook-structured-validation-errors branch 3 times, most recently from df25f16 to 3168eed Compare September 8, 2026 07:28
@rjgoyln
rjgoyln marked this pull request as ready for review September 8, 2026 07:28
Copilot AI balanced review requested due to automatic review settings September 8, 2026 07:28

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tariq-hasan

Copy link
Copy Markdown
Member

/ok-to-test
/retest

Rejections reach users as flat, hand-written sentences that name no field, so
kubectl prints one opaque line and clients cannot tell which part of the spec
to fix. Emitting apimachinery field errors lets the API server render a
per-field cause list, and gives the follow-up aggregation work a list to
accumulate into.

Signed-off-by: rjgoyln <pt40419@gmail.com>
@rjgoyln
rjgoyln force-pushed the feat/webhook-structured-validation-errors branch from 3168eed to 10c6f29 Compare September 14, 2026 12:00

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

None yet

Development

Successfully merging this pull request may close these issues.

Use Kubernetes structured validation machinery in webhook validators

4 participants