Skip to content

📖 update example to pass in the client #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/builtins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func main() {
hookServer := mgr.GetWebhookServer()

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

entryLog.Info("starting manager")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
Expand Down
11 changes: 1 addition & 10 deletions examples/builtins/mutatingwebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// podAnnotator annotates Pods
type podAnnotator struct {
client client.Client
Client client.Client
decoder *admission.Decoder
}

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

// podAnnotator implements inject.Client.
// A client will be automatically injected.

// InjectClient injects the client.
func (a *podAnnotator) InjectClient(c client.Client) error {
a.client = c
return nil
}

// podAnnotator implements admission.DecoderInjector.
// A decoder will be automatically injected.

Expand Down
11 changes: 1 addition & 10 deletions examples/builtins/validatingwebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// podValidator validates Pods
type podValidator struct {
client client.Client
Client client.Client
decoder *admission.Decoder
}

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

// podValidator implements inject.Client.
// A client will be automatically injected.

// InjectClient injects the client.
func (v *podValidator) InjectClient(c client.Client) error {
v.client = c
return nil
}

// podValidator implements admission.DecoderInjector.
// A decoder will be automatically injected.

Expand Down