client in validating webhook not works well
I create a CRD( name XYZ for example ) and add a validating webhook for it. I need to use kubernetes native client to get/list some resources in etcd, and then confirm approve it or not . When I apply the CR one by one, it works well. BUT, when I define multiple XYZ resource in one yaml file and apply it, the validating will not work well.
I think that multiple resources applied in one time, the client in webhook will get/list the same resources in etcd. Is there any way to limit the same resource submit one by one ?
Yes there is:
You can create a struct that contains your needed clients. The struct must implement the following interface:
type webhook interface {
Handle(ctx context.Context, req admission.Request) admission.Response
InjectDecoder(d *admission.Decoder) error
}
And then you can register your struct like:
hookServer := mgr.GetWebhookServer()
hookServer.Register("/validate-your-crd", &webhook.Admission{Handler: &yourHandlerStruct)
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
Nowadays you can also implement a CustomValidator.
I think we can close this issue
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
/close given comment above
@sbueringer: Closing this issue.
In response to this:
/close given comment above
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.