Skip to content

Commit 7b82323

Browse files
committed
backend: k8cache/cacheInvalidation: filter gvrList to reduce the number of go routines for informers
currently the number of go routines is spawning is around 400, because in CheckForChanges, there are 54 informers are there so because of it it is spawning to much go routines per context. so through this PR it is now filtering out the resources which are important or widely used such as secrets, nodes, pods etc.
1 parent 6080174 commit 7b82323

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

backend/pkg/k8cache/cacheInvalidation.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,43 @@ func returnGVRList(apiResourceLists []*metav1.APIResourceList) []schema.GroupVer
131131
}
132132
}
133133

134-
return gvrList
134+
// filtering the gvrList to make sure spawning go routines for only important
135+
// resources which are required to be watched and cached,
136+
// this will help to reduce the performance issue and resource utilization.
137+
filtered := filterImportantResources(gvrList)
138+
139+
return filtered
140+
}
141+
142+
// filterImportantResources filters the provided list of GroupVersionResources to
143+
// include only those that are deemed important for caching and watching.
144+
// This helps reduce the number of resources we watch and cache,
145+
// improving performance and resource utilization.
146+
func filterImportantResources(gvrList []schema.GroupVersionResource) []schema.GroupVersionResource {
147+
allowed := map[string]struct{}{
148+
"pods": {},
149+
"services": {},
150+
"deployments": {},
151+
"replicasets": {},
152+
"statefulsets": {},
153+
"daemonsets": {},
154+
"nodes": {},
155+
"configmaps": {},
156+
"secrets": {},
157+
"jobs": {},
158+
"cronjobs": {},
159+
}
160+
161+
filtered := make([]schema.GroupVersionResource, 0, len(allowed))
162+
163+
for _, gvr := range gvrList {
164+
if _, ok := allowed[gvr.Resource]; ok {
165+
filtered = append(filtered, gvr)
166+
}
167+
}
168+
169+
// return the filtered list of GroupVersionResources that are important for caching and watching
170+
return filtered
135171
}
136172

137173
// Corrected CheckForChanges.

0 commit comments

Comments
 (0)