Skip to content

Commit

Permalink
Remove obsolete CR metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
CatherineF-dev committed Dec 6, 2023
1 parent 98b38ba commit 1685de5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(),
Expand All @@ -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.
Expand Down Expand Up @@ -616,3 +630,7 @@ func cacheStoresToMetricStores(cStores []cache.Store) []*metricsstore.MetricsSto

return mStores
}

func notCustomResource(name string) bool {
return resourceExists(name)
}

0 comments on commit 1685de5

Please sign in to comment.