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 04ab402
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 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,51 @@ func cacheStoresToMetricStores(cStores []cache.Store) []*metricsstore.MetricsSto

return mStores
}


var nonCustomResourceStores = map[string]bool{
"certificatesigningrequests": true,
"clusterroles": true,
"configmaps": true,
"clusterrolebindings": true,
"cronjobs": true,
"daemonsets": true,
"deployments": true,
"endpoints": true,
"endpointslices": true,
"horizontalpodautoscalers": true,
"ingresses": true,
"ingressclasses": true,
"jobs": true,
"leases": true,
"limitranges": true,
"mutatingwebhookconfigurations": true,
"namespaces": true,
"networkpolicies": true,
"nodes": true,
"persistentvolumeclaims": true,
"persistentvolumes": true,
"poddisruptionbudgets": true,
"pods": true,
"replicasets": true,
"replicationcontrollers": true,
"resourcequotas": true,
"roles": true,
"rolebindings": true,
"secrets": true,
"serviceaccounts": true,
"services": true,
"statefulsets": true,
"storageclasses": true,
"validatingwebhookconfigurations": true,
"volumeattachments": true,
"verticalpodautoscalers": true,
}

func notCustomResource(name string) bool {
if val, ok := nonCustomResourceStores[name]; ok && val {
return true
}
return false
}

0 comments on commit 04ab402

Please sign in to comment.