Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip validation errors in mutating webhooks #2865

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

zmerlynn
Copy link
Collaborator

Request processing by kube-apiserver is roughly:
{ mutating webhooks } => { OpenAPI schema validation } => { validating webhooks }

In this PR, we disable validation errors (at least, JSON unmarshalling validation errors) during mutating webhook processing. It seems counter-intuitive not to return an error in mutating webhooks for a serious violation such as invalid JSON, but doing so allows OpenAPI schema validation to proceed. Schema validation gives us nice errors, so e.g.:

instead of:

The Fleet "" is invalid

we get:

The Fleet "fleet-example" is invalid: spec.template.spec.sdkServer.grpcPort: Invalid value: 33332229357: spec.template.spec.sdkServer.grpcPort in body should be less than or equal to 65535

This will become all the more important if we eventually move to CEL based validations.

I'm also changing the error in #2863 to an internal error - after this PR, any hard error from a handler (vs a cause) is unexpected.

Fixes #1770

Request processing by kube-apiserver is roughly:
  { mutating webhooks } => { OpenAPI schema validation } => { validating webhooks }

In this PR, we disable validation errors (at least, JSON unmarshalling
validation errors) during mutating webhook processing. It seems
counter-intuitive not to return an error in mutating webhooks for a
serious violation such as invalid JSON, but doing so allows OpenAPI
schema validation to proceed. Schema validation gives us nice errors,
so e.g.:

instead of:

```
The Fleet "" is invalid
```

we get:

```
The Fleet "fleet-example" is invalid: spec.template.spec.sdkServer.grpcPort: Invalid value: 33332229357: spec.template.spec.sdkServer.grpcPort in body should be less than or equal to 65535
```

This will become all the more important if we eventually move to CEL
based validations.

I'm also changing the error in googleforgames#2863 to an internal error - after this
PR, any hard error from a handler (vs a cause) is unexpected.

Fixes googleforgames#1770
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: d50534e4-375c-4107-a4fa-2b84c7d367af

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/2865/head:pr_2865 && git checkout pr_2865
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.tag=1.29.0-fdca3f3-amd64

@zmerlynn zmerlynn requested review from markmandel and gongmax and removed request for aLekSer and dzlier-gcp December 12, 2022 21:40
@gongmax
Copy link
Collaborator

gongmax commented Dec 13, 2022

Code LGTM. Is there any downside to not fall fast on an invalid request? Maybe not a big deal but potential increasing latency for those request?

@zmerlynn
Copy link
Collaborator Author

Is there any downside to not fall fast on an invalid request? Maybe not a big deal but potential increasing latency for those request?

Yes, there's a minor latency difference, I suspect. In theory there's also a minor load difference on the Kubernetes Control Plane. But, importantly, it only effects the error case, which is uncommon to optimize for.

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gongmax, zmerlynn
Once this PR has been reviewed and has the lgtm label, please assign roberthbailey for approval by writing /assign @roberthbailey in a comment. For more information see the Kubernetes Code Review Process.

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

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

@zmerlynn zmerlynn merged commit 60b48ec into googleforgames:main Dec 13, 2022
@zmerlynn zmerlynn deleted the better-webhook-error branch December 13, 2022 00:10
@Kalaiselvi84 Kalaiselvi84 added this to the 1.29.0 milestone Jan 17, 2023
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.

GameServerTemplate validation: no description when used big port values
4 participants