Skip to content

Commit

Permalink
Update docs for using decoder with core type webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Searcy <joe@twr.io>
  • Loading branch information
phenixblue committed Sep 11, 2023
1 parent a9ba582 commit 1756efe
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions docs/book/src/reference/webhook-for-core-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ func (a *podAnnotator) Handle(ctx context.Context, req admission.Request) admiss
}
```

If you need a client, just pass in the client at struct construction time.

If you add the `InjectDecoder` method for your handler, a decoder will be
injected for you.

```go
func (a *podAnnotator) InjectDecoder(d *admission.Decoder) error {
a.decoder = d
return nil
}
```

**Note**: in order to have controller-gen generate the webhook configuration for
you, you need to add markers. For example,
`// +kubebuilder:webhook:path=/mutate-v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=mpod.kb.io`
Expand All @@ -64,6 +52,19 @@ mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{Handler: &p

You need to ensure the path here match the path in the marker.

### Client/Decoder

If you need a client and/or decoder, just pass them in at struct construction time.

```go
mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{
Handler: &podAnnotator{
Client: mgr.GetClient(),
Decoder: admission.NewDecoder(mgr.GetScheme()),
},
})
```

## Deploy

Deploying it is just like deploying a webhook server for CRD. You need to
Expand Down

0 comments on commit 1756efe

Please sign in to comment.