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

Return better error message when mutation webhook gets invalid JSON #2863

Merged
merged 1 commit into from
Dec 10, 2022

Conversation

zmerlynn
Copy link
Collaborator

I know this looks a little ridiculous since we're returning the error twice, but it looks nicer on the command line. If there's garbage in the manifest (in this case I changed portPolicy to true, it goes from:

The GameServer "" is invalid

To:

The GameServer "" is invalid: : error unmarshalling original GameServer json: {"apiVersion":"agones.dev/v1","kind":"GameServer","metadata":{"creationTimestamp":null,"generateName":"simple-game-server-","namespace":"default"},"spec":{"health":{"failureThreshold":6},"immutableReplicas":1,"ports":[{"containerPort":false,"name":"default","portPolicy":"Dyanmic"}],"template":{"spec":{"containers":[{"image":"gcr.io/agones-images/simple-game-server:0.14","name":"simple-game-server","resources":{"limits":{"cpu":"20m","memory":"64Mi"},"requests":{"cpu":"20m","memory":"64Mi"}}}]}}}}: json: cannot unmarshal bool into Go struct field GameServerPort.spec.ports.containerPort of type int32

I know this looks a little ridiculous since we're returning the error
twice, but it looks nicer on the command line. If there's garbage in
the manifest (in this case I changed `portPolicy` to `true`, it goes
from:

The GameServer "" is invalid

To:

The GameServer "" is invalid: : error unmarshalling original GameServer json: {"apiVersion":"agones.dev/v1","kind":"GameServer","metadata":{"creationTimestamp":null,"generateName":"simple-game-server-","namespace":"default"},"spec":{"health":{"failureThreshold":6},"immutableReplicas":1,"ports":[{"containerPort":false,"name":"default","portPolicy":"Dyanmic"}],"template":{"spec":{"containers":[{"image":"gcr.io/agones-images/simple-game-server:0.14","name":"simple-game-server","resources":{"limits":{"cpu":"20m","memory":"64Mi"},"requests":{"cpu":"20m","memory":"64Mi"}}}]}}}}: json: cannot unmarshal bool into Go struct field GameServerPort.spec.ports.containerPort of type int32
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 9894e0eb-b8f3-49f6-a67a-8f0b19dd37eb

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/2863/head:pr_2863 && git checkout pr_2863
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.tag=1.29.0-55107a1-amd64

@gongmax
Copy link
Collaborator

gongmax commented Dec 10, 2022

LGTM
The PR description seems not accurate. From the cli output, seems you changed containerPort to false, rather than portPolicy to true as stated in the description.

@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 markmandel for approval by writing /assign @markmandel 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

@google-oss-prow google-oss-prow bot added the lgtm label Dec 10, 2022
@gongmax gongmax merged commit 9831e6c into googleforgames:main Dec 10, 2022
zmerlynn added a commit that referenced this pull request Dec 13, 2022
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
chiayi pushed a commit to chiayi/agones that referenced this pull request Dec 13, 2022
…oogleforgames#2863)

I know this looks a little ridiculous since we're returning the error
twice, but it looks nicer on the command line. If there's garbage in
the manifest (in this case I changed `containerPort` to `false`, it goes
from:

The GameServer "" is invalid

To:

The GameServer "" is invalid: : error unmarshalling original GameServer json: {"apiVersion":"agones.dev/v1","kind":"GameServer","metadata":{"creationTimestamp":null,"generateName":"simple-game-server-","namespace":"default"},"spec":{"health":{"failureThreshold":6},"immutableReplicas":1,"ports":[{"containerPort":false,"name":"default","portPolicy":"Dyanmic"}],"template":{"spec":{"containers":[{"image":"gcr.io/agones-images/simple-game-server:0.14","name":"simple-game-server","resources":{"limits":{"cpu":"20m","memory":"64Mi"},"requests":{"cpu":"20m","memory":"64Mi"}}}]}}}}: json: cannot unmarshal bool into Go struct field GameServerPort.spec.ports.containerPort of type int32
@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.

4 participants