-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid calling k8s api for each resource kind on the cluster #1712
Conversation
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
aee96ae
to
e8fbb16
Compare
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #1712 +/- ##
==========================================
+ Coverage 87.71% 87.74% +0.02%
==========================================
Files 98 98
Lines 5958 5972 +14
==========================================
+ Hits 5226 5240 +14
Misses 556 556
Partials 176 176
Continue to review full report at Codecov.
|
pkg/autodetect/main.go
Outdated
@@ -109,8 +111,29 @@ func (b *Background) autoDetectCapabilities() { | |||
b.cleanDeployments(ctx) | |||
} | |||
|
|||
func (b *Background) isInListenedGroups(group *metav1.APIGroup) bool { | |||
for _, groupName := range groupsListened { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
might be more efficient here. The code checks if a given group should be handled or not.
pkg/autodetect/main.go
Outdated
@@ -109,8 +111,29 @@ func (b *Background) autoDetectCapabilities() { | |||
b.cleanDeployments(ctx) | |||
} | |||
|
|||
func (b *Background) isInListenedGroups(group *metav1.APIGroup) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing group by value seems better here
pkg/autodetect/main.go
Outdated
if b.isInListenedGroups(&sg) { | ||
groupAPIList, err := b.dcl.ServerResourcesForGroupVersion(sg.PreferredVersion.GroupVersion) | ||
if err != nil { | ||
return apiLists, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would either return empty apiList
or accumulate errors and return the error with gathered groups once all calls are done.
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas ruben.vp8510@gmail.com
Which problem is this PR solving?
PreferedServerResources
does a lot of calls to the API when the cluster has a lot of different resource Kinds.Short description of the changes
ServerGroups
and then only get the resources for our interested Groups.Note: I still see one line in the log with the error "Waited Xs.." but one single time, I don't see the same error repeating in logs each N seconds. so I think this can be considered a fix.