mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 02:18:15 +00:00
Fix multiple crd slowness issue (#4275)
Signed-off-by: Vyankatesh vyankateshkd@gmail.com * fix multiple crd issue
This commit is contained in:
parent
c3e91fb357
commit
c7bcd5fadf
2 changed files with 20 additions and 3 deletions
|
@ -86,9 +86,8 @@ func (c *crdSync) Run(workers int, stopCh <-chan struct{}) {
|
|||
}
|
||||
// Sync CRD before kyverno starts
|
||||
c.sync()
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
go wait.Until(c.sync, 15*time.Second, stopCh)
|
||||
go wait.Until(c.CheckSync, 15*time.Second, stopCh)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,3 +248,18 @@ func addingDefaultFieldsToSchema(crdName string, schemaRaw []byte) ([]byte, erro
|
|||
|
||||
return schemaWithDefaultFields, nil
|
||||
}
|
||||
|
||||
func (c *crdSync) CheckSync() {
|
||||
crds, err := c.client.GetDynamicInterface().Resource(runtimeSchema.GroupVersionResource{
|
||||
Group: "apiextensions.k8s.io",
|
||||
Version: "v1",
|
||||
Resource: "customresourcedefinitions",
|
||||
}).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
log.Log.Error(err, "could not fetch crd's from server")
|
||||
return
|
||||
}
|
||||
if len(c.controller.crdList) != len(crds.Items) {
|
||||
c.sync()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ func Validate(policy kyvernov1.PolicyInterface, client dclient.Interface, mock b
|
|||
spec := policy.GetSpec()
|
||||
background := spec.BackgroundProcessingEnabled()
|
||||
onPolicyUpdate := spec.GetMutateExistingOnPolicyUpdate()
|
||||
if !mock {
|
||||
openapi.NewCRDSync(client, openAPIController).CheckSync()
|
||||
}
|
||||
|
||||
var errs field.ErrorList
|
||||
specPath := field.NewPath("spec")
|
||||
|
@ -1061,7 +1064,7 @@ func validateKinds(kinds []string, mock bool, client dclient.Interface, p kyvern
|
|||
if !mock && !kubeutils.SkipSubResources(k) && !strings.Contains(kind, "*") {
|
||||
_, _, err := client.Discovery().FindResource(gv, k)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to convert GVK to GVR for kinds %s, err: %s", kinds, err)
|
||||
return fmt.Errorf("unable to convert GVK to GVR for kinds %s, err: %s", k, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue