Skip to content
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

Get client.Client in webhook admission #505

Closed
FillZpp opened this issue Dec 3, 2018 · 4 comments · Fixed by #533
Closed

Get client.Client in webhook admission #505

FillZpp opened this issue Dec 3, 2018 · 4 comments · Fixed by #533
Assignees
Labels
kind/documentation Categorizes issue or PR as related to documentation.

Comments

@FillZpp
Copy link

FillZpp commented Dec 3, 2018

Now i create webhook admission using kubebuilder alpha webhook ..., and then find the webhook
handler generated like this:

type MyResourceCreateUpdateHandler struct {
	// Client  client.Client

	// Decoder decodes objects
	Decoder types.Decoder
}

The Client which i need in webhook validating or mutating has been commented.
How could i get client or informer in webhook admission?

@mengqiy mengqiy added the kind/documentation Categorizes issue or PR as related to documentation. label Dec 4, 2018
@mengqiy
Copy link
Member

mengqiy commented Dec 4, 2018

This is a documentation issue. I will update it.

I will use the test project as an example to show you how to use a client:

  1. Define a client by uncommenting https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go#L39
  2. Enable the injection by uncommenting https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go#L68-L74
  3. Add "sigs.k8s.io/controller-runtime/pkg/client" in the import section.
  4. If the [import path] for your API type is not in the default path, adjust it. This scenario happens when the API is defined out of tree.

@FillZpp
Copy link
Author

FillZpp commented Dec 5, 2018

Thanks a lot @mengqiy
I never noticed (2) before.

@mohnishkodnani
Copy link

mohnishkodnani commented Dec 7, 2018

When I run the following command.
kubebuilder alpha webhook --group core --version v1 --kind Pod --type=mutating --operations=create,update

I get the following error :

make: *** [vet] Error 2```
Seems like webhook.go was not generated 
This only happens when the git repo is the same has other controllers created using kubebuilder as well. 
We have one git repo where we share controllers.

@mengqiy
Copy link
Member

mengqiy commented Dec 14, 2018

Seems like webhook.go was not generated

@mohnishkodnani I guess the project was created by an older kubebuilder that doesn't support scaffolding webhook. It currently assume webhook.go was generated at kubebuilder init step, which may not be always true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants