-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: introduce asyncPriorityWorker in resourceDetector Processor #6919
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
Conversation
Summary of ChangesHello @zach593, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces priority queue support for the self-developed asyncWorker and enables it in the resourceDetector to improve the responsiveness of controllers. The changes are well-structured, introducing a new AsyncPriorityWorker interface and conditionally using a priority queue based on a feature gate. My review focuses on improving test mocks for better verification, ensuring consistent rate-limiter behavior, and enhancing the robustness of the new worker logic.
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.
Pull Request Overview
This PR introduces priority queue support for async workers in Karmada controllers, controlled by the ControllerPriorityQueue feature gate. The main purpose is to allow controllers to prioritize processing recent cluster changes during startup while deferring items without recent updates to the end of the queue.
Key changes:
- Added priority queue support to the async worker implementation with new
AsyncPriorityWorkerinterface andAddWithOpts/EnqueueWithOptsmethods - Integrated priority queue into
ResourceDetectorto assign low priority to items from initial list sync and policy changes - Extracted rate limiter default setting logic into a
SetDefaults()method for reusability
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/util/worker.go | Added priority queue support with new interfaces, methods, and conditional queue initialization based on UsePriorityQueue option |
| pkg/util/worker_test.go | Added comprehensive tests for priority queue functionality including new test cases for AddWithOpts and EnqueueWithOpts |
| pkg/detector/detector.go | Integrated priority queue feature with low priority assignment for initial list items and policy-triggered changes |
| pkg/detector/detector_test.go | Updated test mocks to implement new AsyncPriorityWorker interface methods |
| pkg/util/fedinformer/handlers.go | Updated handler signature to support isInitialList parameter for detecting initial sync events |
| pkg/util/fedinformer/handlers_test.go | Updated test to match new handler signature |
| pkg/sharedcli/ratelimiterflag/ratelimiterflag.go | Extracted default setting logic into SetDefaults() method |
| pkg/sharedcli/ratelimiterflag/ratelimiterflag_test.go | Added tests for the new SetDefaults() method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6919 +/- ##
==========================================
+ Coverage 46.46% 46.51% +0.05%
==========================================
Files 698 698
Lines 47824 47876 +52
==========================================
+ Hits 22220 22269 +49
Misses 23933 23933
- Partials 1671 1674 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1e32269 to
ca97883
Compare
Yes, that's suspicious. You just updated one resource template, right? Can we add a log before enqueuing the items? So that we can know what items are in the queue. |
Reason: After creating the cluster using karmada/pkg/detector/policy.go Lines 105 to 107 in 463fcca
The karmada/vendor/sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue/priorityqueue.go Lines 144 to 156 in 463fcca
As seen in the karmada/vendor/sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue/priorityqueue.go Lines 367 to 382 in 27ca690
Therefore, although these items are placed at the end of the queue, their priority is 0. This results in a situation where, after modifying an object, it is immediately processed by the detector, but the queue metrics still appear to show a backlog of items with a priority of 0. After #6929, this has already been fixed in the code shown below. After rebasing, the problem has not occurred again. karmada/vendor/sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue/priorityqueue.go Lines 421 to 436 in 463fcca
|
ca97883 to
c8c3a1f
Compare
Signed-off-by: zach593 <[email protected]>
c8c3a1f to
afd04e9
Compare
|
/retest |
1 similar comment
|
/retest |
Nice! |
Signed-off-by: zach593 <[email protected]>
RainbowMango
left a comment
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.
/lgtm
/gemini review
/retest |
RainbowMango
left a comment
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.
/approve
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |



What type of PR is this?
/kind feature
What this PR does / why we need it:
In the previous work, we added the priority queue featuregate for controllers driven by controller-runtime.
However, this capability could not take full effect, because some key controllers in controller-manager are driven by our self-developed asyncWorker.
Therefore, we need to implement the same mechanism in asyncWorker to achieve full coverage of the "priority queue" feature.
This PR adds priority queue support to asyncWorker and introduces the related capability in resourceDetector for processing resourceTemplate (activated via the priorityQueue featuregate).
This feature will be progressively rolled out to other controllers in upcoming updates.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
test report:
I temporarily added time.Sleep(time.Second) in the detector and limited its concurrency to 1 to control the processing speed.
After adding 5,000 deployments and their corresponding propagation policies and completing synchronization, I restarted the controller.
It can be observed that while there was still a backlog in the queue, after manually modifying the corresponding object, the detector processed it very quickly.
As for the backlog of the
priority: 0queue, it shouldn’t be that large — I suspect there might be an issue here, and I’ll check it later.Does this PR introduce a user-facing change?: