diff --git a/internal/store/builder.go b/internal/store/builder.go index 5c38857d7b..b538305eaf 100644 --- a/internal/store/builder.go +++ b/internal/store/builder.go @@ -195,6 +195,14 @@ func (b *Builder) DefaultGenerateCustomResourceStoresFunc() ksmtypes.BuildCustom // WithCustomResourceStoreFactories returns configures a custom resource stores factory func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.RegistryFactory) { + obsoleteCustomResource := map[string]bool{} + for k := range availableStores { + if notCustomResource(k) { + continue + } + obsoleteCustomResource[k] = true + } + for i := range fs { f := fs[i] gvr := util.GVRFromType(f.Name(), f.ExpectedType()) @@ -207,6 +215,7 @@ func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.Registry if _, ok := availableStores[gvrString]; ok { klog.InfoS("Updating store", "GVR", gvrString) } + obsoleteCustomResource[f.Name()] = false availableStores[gvrString] = func(b *Builder) []cache.Store { return b.buildCustomResourceStoresFunc( f.Name(), @@ -217,6 +226,11 @@ func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.Registry ) } } + for k, v := range obsoleteCustomResource { + if v { + delete(availableStores, k) + } + } } // allowList validates the given map and checks if the resources exists. @@ -616,3 +630,7 @@ func cacheStoresToMetricStores(cStores []cache.Store) []*metricsstore.MetricsSto return mStores } + +func notCustomResource(name string) bool { + return resourceExists(name) +}