From 4c28540f838618f8cd2da6ebd17d678e088fd831 Mon Sep 17 00:00:00 2001 From: Vyankatesh Kudtarkar Date: Mon, 22 Nov 2021 19:22:45 +0530 Subject: [PATCH] fix crd sync issue (#2634) --- pkg/openapi/crdSync.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/openapi/crdSync.go b/pkg/openapi/crdSync.go index efd89fed5e..4e3cbddf33 100644 --- a/pkg/openapi/crdSync.go +++ b/pkg/openapi/crdSync.go @@ -77,16 +77,16 @@ func (c *crdSync) Run(workers int, stopCh <-chan struct{}) { if err != nil { log.Log.Error(err, "Could not set custom OpenAPI document") } - // Sync CRD before kyverno starts c.sync() for i := 0; i < workers; i++ { - go wait.Until(c.sync, 15*time.Minute, stopCh) + go wait.Until(c.sync, 15*time.Second, stopCh) } } func (c *crdSync) sync() { + c.client.DiscoveryClient.DiscoveryCache().Invalidate() crds, err := c.client.GetDynamicInterface().Resource(runtimeSchema.GroupVersionResource{ Group: "apiextensions.k8s.io", Version: "v1", @@ -106,6 +106,16 @@ func (c *crdSync) sync() { if err := c.updateInClusterKindToAPIVersions(); err != nil { log.Log.Error(err, "sync failed, unable to update in-cluster api versions") } + + newDoc, err := c.client.DiscoveryClient.DiscoveryCache().OpenAPISchema() + if err != nil { + log.Log.Error(err, "cannot get OpenAPI schema") + } + + err = c.controller.useOpenAPIDocument(newDoc) + if err != nil { + log.Log.Error(err, "Could not set custom OpenAPI document") + } } func (c *crdSync) updateInClusterKindToAPIVersions() error {