You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to be able to get access to all or some of the http.Request.Context from within an Admission webhook handler. This could be for getting the path, parameters, adding tracing information, etc. This should be something you can opt into since it could bloat the context if we just added the entire request object.
Proposal
Modify admission.Webhook struct to include optional WithContextFunc which allows the controller builder to implement their own context mutation:
type Webhook struct {
// Handler actually processes an admission request returning whether it was allowed or denied,
// and potentially patches to apply to the handler.
Handler Handler
// WithContextFunc will allow you to take the http.Request.Context() and
// add any additional information such as passing the request path or
// headers thus allowing you to read them from within the handler
WithContextFunc func(context.Context, *http.Request) context.Context
// decoder is constructed on receiving a scheme and passed down to then handler
decoder *Decoder
log logr.Logger
}
With that defined we can then change the ServeHTTP func to call this func before passing the context to the Handler.
I would like to be able to get access to all or some of the http.Request.Context from within an Admission webhook handler. This could be for getting the path, parameters, adding tracing information, etc. This should be something you can opt into since it could bloat the context if we just added the entire request object.
Proposal
Modify admission.Webhook struct to include optional
WithContextFunc
which allows the controller builder to implement their own context mutation:With that defined we can then change the
ServeHTTP
func to call this func before passing the context to theHandler
.Usage
Typically in
main.go
this would setup the webhook server and add the path to the context, we can then return this value and take any action we need.Webhook implementation:
The text was updated successfully, but these errors were encountered: