Skip to content

Commit 9f844bd

Browse files
authored
Merge pull request #3613 from phenixblue/master
📖 Update docs for using Decoder with Core Type Webhook
2 parents 9eeeb45 + 1756efe commit 9f844bd

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

docs/book/src/reference/webhook-for-core-types.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ func (a *podAnnotator) Handle(ctx context.Context, req admission.Request) admiss
3838
}
3939
```
4040

41-
If you need a client, just pass in the client at struct construction time.
42-
43-
If you add the `InjectDecoder` method for your handler, a decoder will be
44-
injected for you.
45-
46-
```go
47-
func (a *podAnnotator) InjectDecoder(d *admission.Decoder) error {
48-
a.decoder = d
49-
return nil
50-
}
51-
```
52-
5341
**Note**: in order to have controller-gen generate the webhook configuration for
5442
you, you need to add markers. For example,
5543
`// +kubebuilder:webhook:path=/mutate-v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=mpod.kb.io`
@@ -64,6 +52,19 @@ mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{Handler: &p
6452

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

55+
### Client/Decoder
56+
57+
If you need a client and/or decoder, just pass them in at struct construction time.
58+
59+
```go
60+
mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{
61+
Handler: &podAnnotator{
62+
Client: mgr.GetClient(),
63+
Decoder: admission.NewDecoder(mgr.GetScheme()),
64+
},
65+
})
66+
```
67+
6768
## Deploy
6869

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

0 commit comments

Comments
 (0)