-
Notifications
You must be signed in to change notification settings - Fork 76
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
Dynamic type webhooks #62
Conversation
Signed-off-by: Xabier Larrakoetxea <[email protected]>
Signed-off-by: Xabier Larrakoetxea <[email protected]>
Signed-off-by: Xabier Larrakoetxea <[email protected]>
Signed-off-by: Xabier Larrakoetxea <[email protected]>
Looking forward for this PR. |
Hey @turkenh Sorry fo not merging it in 3 days, I normally merge once I make the PR and passes the CI, in this case I wanted to test it a little bit more, so I was setting up a production webhook with so I could test it for a while in a production environment, I've had the webhook ~32h hours mutating multiple types and seems to be ok, in mutation and in resource consumption, so I'll merge into master. If you start using it and detect problems or bugs, please open an issue so I can check and fix it. Thanks! Edit: I'll make a new release this weekend. Meanwhile, you can use |
@slok thanks a lot! Testing with a validating webhook for
Any ideas? |
Could this be related to not having request body for delete requests? |
if !ok { | ||
err := fmt.Errorf("could not type assert metav1.Object to runtime.Object") | ||
// Create a new object from the raw type. | ||
runtimeObj, err := w.objectCreator.NewObject(ar.Request.Object.Raw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use ar.Request.oldObject.Raw
is it is a delete operation?
Just tested and same webhook works for |
@slok yes, I can verify the issue is fixed on my side and I can now use dynamic type webhook with Thanks a lot for quick fix! |
Awesome! I'll publish a release this week with these changes. Many thanks for your help and feedback! |
Fixes #36
This PR adds the ability to use dynamic webhooks. This webhooks infer the type of the request based on the received review JSON data. If the type can't be inferred because is unknown then it will fallback to
runtime.Unstructured
object type.We consider unknown types (core objects that are not tracked by the webhook kubernetes libraries and CRDs).
These dynamic webhooks will be activated when the webhook factory receives a configuration without the
Obj
field set.The webhooks have been refactored internally to use a internal
ObjectCreator
that is the one responsible to create the object from the received raw JSON, so we have 2, aStatic
andDynamic
one.These webhooks should be also very helpful on multitype webhooks or webhooks that mutate/validate metadata fields like labels.