Skip to content

chore: Use watch APIs to list k8s resources #716

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

andrii-korotkov
Copy link

Use watch APIs to list resources instead of paginated regular APIs.

@andrii-korotkov andrii-korotkov requested a review from a team as a code owner May 4, 2025 18:39
Signed-off-by: Andrii Korotkov <[email protected]>
Copy link

codecov bot commented May 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.69%. Comparing base (8849c3f) to head (d6d89f4).
Report is 41 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #716      +/-   ##
==========================================
- Coverage   54.26%   53.69%   -0.57%     
==========================================
  Files          64       64              
  Lines        6164     6488     +324     
==========================================
+ Hits         3345     3484     +139     
- Misses       2549     2727     +178     
- Partials      270      277       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Andrii Korotkov <[email protected]>
Copy link

@blakepettersson
Copy link
Member

blakepettersson commented May 13, 2025

Is there some way this can be benchmarked? Like what are the expected performance improvements with this method (I imagine they are large, but ballpark numbers)?

@andrii-korotkov
Copy link
Author

Is there some way this can be benchmarket? Like what are the expected performance improvements with this method (I imagine they are large, but ballpark numbers)?

I'll try to think of something.

Comment on lines +607 to +609
if opts.ResourceVersion == "" {
opts.ResourceVersion = "0"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required by the list options construction function's code, otherwise it would return false as success.

Comment on lines +254 to +255
listResourcesUsingWatchAPI atomic.Int32
listResourcesUsingRegularAPI atomic.Int32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we shouldn't do this, because listResources gets called a lot over the lifetime of a controller run (i.e. every time the cache expires or there's a retry due to an error). I don't think it's worth it just for the test. And maybe we can find a different way to test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that it's not ideal, I'll think how to test better.

t.Run(tc.name, func(t *testing.T) {
if tc.listUsingWatchAPIs {
// Enable WatchListClient in particular. Setting via env variable here is too late.
clientfeatures.ReplaceFeatureGates(AlwaysEnabledGates{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this enables every feature gate that can be enabled. Can we instead enable just the watch-list gate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit more complicated, and it's just for this test, so I'd rather keep this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although shouldn't be too hard to construct gates more precisely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants