diff --git a/pkg/api/resources/cache.go b/pkg/api/resources/cache.go index cf812f62..60c0225c 100644 --- a/pkg/api/resources/cache.go +++ b/pkg/api/resources/cache.go @@ -101,8 +101,6 @@ func NewCache(ctx context.Context, clients *client.Clients) (*Cache, error) { } c.dynamicFactory = dynamicInformer.NewFilteredDynamicSharedInformerFactory(dynamicClient, time.Minute*10, metaV1.NamespaceAll, nil) - c.setupUDSCRDInformer() - c.bindCoreResources() c.bindWorkloadResources() c.bindUDSResources() @@ -146,7 +144,9 @@ func (c *Cache) bindCoreResources() { Version: "v1", Resource: "customresourcedefinitions", } - c.CRDs = NewResourceList(c.dynamicFactory.ForResource(crdGVR).Informer(), crdGVK) + crdInformer := c.dynamicFactory.ForResource(crdGVR).Informer() + c.CRDs = NewResourceList(crdInformer, crdGVK) + c.addExistsListeners(crdInformer) } func (c *Cache) bindWorkloadResources() { diff --git a/pkg/api/resources/crds.go b/pkg/api/resources/crds.go index b7fdaf88..a51ded14 100644 --- a/pkg/api/resources/crds.go +++ b/pkg/api/resources/crds.go @@ -23,14 +23,8 @@ func NewCRDs() *CRDs { } } -func (c *Cache) setupUDSCRDInformer() { - crdGVR := schema.GroupVersionResource{ - Group: "apiextensions.k8s.io", - Version: "v1", - Resource: "customresourcedefinitions", - } - crdInformer := c.dynamicFactory.ForResource(crdGVR).Informer() - _, err := crdInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ +func (c *Cache) addExistsListeners(informer cache.SharedIndexInformer) { + _, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { c.UDSCRDs.addCRD(obj) notifyDynamicResources(c)