-
Notifications
You must be signed in to change notification settings - Fork 826
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
Conversation
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
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:
|
LGTM |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: gongmax, zmerlynn 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 |
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
…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
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
totrue
, it goes from:To: