Skip to content

Commit

Permalink
Merge pull request #3613 from phenixblue/master
Browse files Browse the repository at this point in the history
📖 Update docs for using Decoder with Core Type Webhook
  • Loading branch information
k8s-ci-robot authored Sep 12, 2023
2 parents 9eeeb45 + 1756efe commit 9f844bd
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 9f844bd

Please sign in to comment.