1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-28 02:18:15 +00:00

fix crd sync issue (#2634)

This commit is contained in:
Vyankatesh Kudtarkar 2021-11-22 19:22:45 +05:30 committed by GitHub
parent ea3529f2d0
commit 4c28540f83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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