fix crd sync issue
@@ -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 {
