controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

client in validating webhook not works well

Open yangxggo opened this issue 3 years ago • 1 comments

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.

yangxggo avatar Sep 27 '22 02:09 yangxggo

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 ?

yangxggo avatar Sep 27 '22 02:09 yangxggo

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) 

zbindenren avatar Nov 22 '22 07:11 zbindenren

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Feb 20 '23 08:02 k8s-triage-robot

Nowadays you can also implement a CustomValidator.

I think we can close this issue

sbueringer avatar Feb 20 '23 09:02 sbueringer

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Mar 22 '23 10:03 k8s-triage-robot

/close given comment above

sbueringer avatar Mar 23 '23 03:03 sbueringer

@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.

k8s-ci-robot avatar Mar 23 '23 03:03 k8s-ci-robot