You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
@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.
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.
The text was updated successfully, but these errors were encountered: