Kushagra Kasbi
Kushagra Kasbi

Reputation: 155

How to access K8S Client in a Validating admission webhook (myCRD_Webhook.go) or within the api package of an operator-sdk based golang operator

I want to validate all the resources of a particular crd called MyCRD before it reaches to the etcd. The answer is a validating webhook. But as you can see my requirement is specific, I just don't want to validate the incoming CRD Resource, but I actually want to validate all the CRD Resources together everytime a new resources is added, updated or deleted. To do this I need to list all the resources of myCRD and then apply the validation logic within the ValidateCreate or ValidateUpdate function.

I already have a working operator, and a working webhook, What I want to figure out is how to inject a CLient to the webhook without breaking the controller gen tools.

I have tried to inject the K8s CLient in the MyCRD Struct during initialization, but make generate and make manifests commands fail with error. Apparently this is a known issue of the controller-gen-tools.

Any other alternatives or workaround for this problem?

Upvotes: 1

Views: 83

Answers (0)

Related Questions