-
Notifications
You must be signed in to change notification settings - Fork 1k
Optimize binding controllers with fine-grained event filtering to reduce redundant reconciliations #6784
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
base: master
Are you sure you want to change the base?
Optimize binding controllers with fine-grained event filtering to reduce redundant reconciliations #6784
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Summary of ChangesHello @rohan-019, 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 enhances the performance of 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 a custom predicate ResourceBindingPredicate
to optimize the binding controllers by filtering events, which is a great way to reduce unnecessary reconciliations and improve performance. The implementation is clear and covers both ResourceBinding
and ClusterResourceBinding
. The logic correctly handles create, delete, and update events based on meaningful changes.
I have a couple of suggestions to improve code maintainability and test coverage. One is to refactor a duplicated code block in binding_predicate.go
, and the other is to enhance the unit tests for ClusterResourceBinding
to be more comprehensive.
Overall, this is a solid improvement. Please see my detailed comments.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6784 +/- ##
==========================================
+ Coverage 45.74% 45.87% +0.13%
==========================================
Files 689 691 +2
Lines 57161 57346 +185
==========================================
+ Hits 26149 26310 +161
- Misses 29383 29406 +23
- Partials 1629 1630 +1
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:
|
Hey, @XiShanYongYe-Chang |
Thanks a lot |
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.
Thanks~
Can you help fix the lint error?
I tried several times to fix lint errors using |
Hi @rohan-019, since this PR is the first one in our series, I have quite a few review comments. ^-^ |
Hi @XiShanYongYe-Chang , Thanks again for taking the time to review. |
Hi @rohan-019, the newly added ut has failed. |
Hey @XiShanYongYe-Chang , The reason is that once we override UpdateFunc with custom logic, the default GenerationChangedPredicate is no longer applied automatically. This means spec-only changes are not triggering reconciliation unless we explicitly handle the generation change inside our predicate. To keep the behavior correct and align with the current tests, I’ve restored the != generation check in UpdateFunc. |
This test case is problematic because it is unlikely that only the generation will change while other fields remain unchanged. Therefore, it needs to be redesigned or removed. |
There's no need to do this. |
That makes sense, as the Generation changes are handled globally, so this predicate doesn't need to check for them. |
Hey @XiShanYongYe-Chang, |
Hi @XiShanYongYe-Chang as suggested, but this change caused failures in the e2e tests (e.g., migration_and_rollback_test.go timing out). The reason is that the simplified form triggers reconciliation not only when deletion starts So it seems we need to keep the original, more restrictive check to ensure reconciliation only fires once at the beginning of deletion. |
Once the timestamp is set, it will not be modified again. The E2E error should be just an occasional issue and likely not introduced by the current changes. Let's ignore it for now. Can you help fix the lint errors and compress the commits into one? |
8ba789f
to
6ef33ba
Compare
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.
There are still some minor issues, but everything else is basically fine. 👍
375bf2f
to
127e00c
Compare
d44400a
to
7346443
Compare
Signed-off-by: rohan-019 <[email protected] Signed-off-by: rohan-019 <[email protected]>
7346443
to
62be891
Compare
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.
Thanks a lot~ 👍
/lgtm
I guess this PR is part of #6780, so I updated the |
Optimize binding controllers with custom event predicate
Summary
Introduces a custom predicate for binding controllers to filter events and reduce unnecessary reconciliations:
.spec
fields)Result: Better performance with no behavior changes.
Motivation
Current controllers watch resources with broad predicates, causing redundant reconciliations. Filtering irrelevant events reduces CPU/memory usage, API calls, and cache churn while preserving finalizer cleanup.
Changes
ResourceBindingPredicate
Predicate Logic
.spec
fields change (requiredBy
,clusters
,resource
,gracefulEvictionTasks
,suspension
,preserveResourcesOnDeletion
,conflictResolution
)Event Behavior
Files Changed
Added:
pkg/controllers/binding/binding_predicate.go
pkg/controllers/binding/binding_predicate_test.go
Modified:
pkg/controllers/binding/binding_controller.go
pkg/controllers/binding/cluster_resource_binding_controller.go
Testing
.spec
changes trigger reconciliationBackward Compatibility
Performance Impact
Linked Issue
Part of: #6780
Checklist