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

Using a "client" in webhook interface handlers #1578

Closed
champak opened this issue Jun 29, 2020 · 3 comments
Closed

Using a "client" in webhook interface handlers #1578

champak opened this issue Jun 29, 2020 · 3 comments
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@champak
Copy link

champak commented Jun 29, 2020

I am wondering what is a good way to access the "client" in the context of the scaffolded webhook interfaces. One option is to fetch and add a client object in the generated SetupWebhookWithManager(). Instead, is it possible to access the client from the ValidateCreate(), ValidateUpdate() apis ? Something on the lines of the below would have been convenient:

func (r *someobj) ValidateCreate() error {
// TODO(user): fill in your validation logic upon object creation.
svc := &corev1.Service{}
err := client.Get{context, types.NamespacedName{ Namespace: "bar", Name: "foo" }, svc}
.....

A client could be used for sundry things like looking up other objects etc. Not sure if the client is meant to be accessible here and am yet to peek the validator interface which does not seem to make a client accessible by default. I did not see examples in the docs on what may be a good approach for using a client in a webhook with the validate/mutate interfaces. If anyone else has been down this path please opine. Thanks.

@champak champak added the kind/support Categorizes issue or PR as a support question. label Jun 29, 2020
@kishoregv
Copy link

Similar issue here, you might find answer here #1216

@champak
Copy link
Author

champak commented Jul 6, 2020

@kishoregv thanks that does seem to be the same issue. I do not see whether the alternate suggested approach to using the client via the apis in pkg/admission/webhook worked out. It was unclear how that would be used in the context of the handler api functions. Adding a client object in SetupWebhookWithManager() does work.

@champak
Copy link
Author

champak commented Jul 22, 2020

Did not find a better way. Closing.

@champak champak closed this as completed Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

2 participants