Skip to content

Commit cc53257

Browse files
author
Mengqi Yu
committed
📖 update example to pass in the client
1 parent 06a0bf3 commit cc53257

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

examples/builtins/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func main() {
7575
hookServer := mgr.GetWebhookServer()
7676

7777
entryLog.Info("registering webhooks to the webhook server")
78-
hookServer.Register("/mutate-v1-pod", &webhook.Admission{Handler: &podAnnotator{}})
79-
hookServer.Register("/validate-v1-pod", &webhook.Admission{Handler: &podValidator{}})
78+
hookServer.Register("/mutate-v1-pod", &webhook.Admission{Handler: &podAnnotator{Client: mgr.GetClient()}})
79+
hookServer.Register("/validate-v1-pod", &webhook.Admission{Handler: &podValidator{Client: mgr.GetClient()}})
8080

8181
entryLog.Info("starting manager")
8282
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {

examples/builtins/mutatingwebhook.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
// podAnnotator annotates Pods
3232
type podAnnotator struct {
33-
client client.Client
33+
Client client.Client
3434
decoder *admission.Decoder
3535
}
3636

@@ -56,15 +56,6 @@ func (a *podAnnotator) Handle(ctx context.Context, req admission.Request) admiss
5656
return admission.PatchResponseFromRaw(req.Object.Raw, marshaledPod)
5757
}
5858

59-
// podAnnotator implements inject.Client.
60-
// A client will be automatically injected.
61-
62-
// InjectClient injects the client.
63-
func (a *podAnnotator) InjectClient(c client.Client) error {
64-
a.client = c
65-
return nil
66-
}
67-
6859
// podAnnotator implements admission.DecoderInjector.
6960
// A decoder will be automatically injected.
7061

examples/builtins/validatingwebhook.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
// podValidator validates Pods
3232
type podValidator struct {
33-
client client.Client
33+
Client client.Client
3434
decoder *admission.Decoder
3535
}
3636

@@ -55,15 +55,6 @@ func (v *podValidator) Handle(ctx context.Context, req admission.Request) admiss
5555
return admission.Allowed("")
5656
}
5757

58-
// podValidator implements inject.Client.
59-
// A client will be automatically injected.
60-
61-
// InjectClient injects the client.
62-
func (v *podValidator) InjectClient(c client.Client) error {
63-
v.client = c
64-
return nil
65-
}
66-
6758
// podValidator implements admission.DecoderInjector.
6859
// A decoder will be automatically injected.
6960

0 commit comments

Comments
 (0)