feat: avoid redundant process because of claim metadata change#7103
feat: avoid redundant process because of claim metadata change#7103vie-serendipity wants to merge 1 commit intokarmada-io:masterfrom
Conversation
Summary of ChangesHello @vie-serendipity, 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 improves the efficiency of the resource detector by eliminating redundant processing. Previously, when an object's claim metadata was updated, it would trigger a full re-processing cycle even if no other changes occurred. The new changes introduce a flag to detect metadata-only updates, allowing the system to short-circuit the processing and rely on the subsequent update event to handle the object, thereby reducing unnecessary computational load and improving overall performance. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Code Review
This pull request introduces an optimization to avoid redundant processing when claim metadata is added to an object. By modifying ClaimPolicyForObject and ClaimClusterPolicyForObject to return a boolean indicating if a claim was newly added, the ApplyPolicy and ApplyClusterPolicy functions can now exit early, knowing that the object update will trigger a new reconciliation. This is a sensible performance improvement. My review focuses on ensuring the documentation is updated to reflect these signature changes, in accordance with the repository's style guide.
| // ClaimPolicyForObject set policy identifier which the object associated with. | ||
| // It will add policy labels and annotations to the object, and update the obj with the content returned by the Server, ensuring that the obj used when generating the binding is the latest. |
There was a problem hiding this comment.
The function signature for ClaimPolicyForObject has been updated to return a boolean value indicating whether a claim was newly made, but the function's comment has not been updated to reflect this change. According to the style guide, all exported functions must be documented with clear and concise comments describing their purpose and behavior, including return values.
| // ClaimPolicyForObject set policy identifier which the object associated with. | |
| // It will add policy labels and annotations to the object, and update the obj with the content returned by the Server, ensuring that the obj used when generating the binding is the latest. | |
| // ClaimPolicyForObject sets the policy identifier for an object by adding labels/annotations and updating it on the server. | |
| // It returns the policy ID, a boolean indicating if a claim was newly added, and an error. The update ensures the latest object version is used for binding generation. |
References
- All exported functions, methods, structs, and interfaces must be documented with clear and concise comments describing their purpose and behavior. (link)
| // ClaimClusterPolicyForObject set cluster identifier which the object associated with. | ||
| // It will add policy labels and annotations to the object, and update the obj with the content returned by the Server, ensuring that the obj used when generating the binding is the latest. |
There was a problem hiding this comment.
Similar to ClaimPolicyForObject, the function signature for ClaimClusterPolicyForObject has changed, but its comment has not been updated. Please update the comment to describe the new boolean return value, as required by the style guide.
| // ClaimClusterPolicyForObject set cluster identifier which the object associated with. | |
| // It will add policy labels and annotations to the object, and update the obj with the content returned by the Server, ensuring that the obj used when generating the binding is the latest. | |
| // ClaimClusterPolicyForObject sets the cluster policy identifier for an object by adding labels/annotations and updating it on the server. | |
| // It returns the policy ID, a boolean indicating if a claim was newly added, and an error. The update ensures the latest object version is used for binding generation. |
References
- All exported functions, methods, structs, and interfaces must be documented with clear and concise comments describing their purpose and behavior. (link)
fa89c9a to
b4e7309
Compare
RainbowMango
left a comment
There was a problem hiding this comment.
/assign
Nice catch! @vie-serendipity . Could you please look at the failing tests?
|
@RainbowMango I want it to be processed only once, so I proposed this PR. Only the objects with karmada labels and annotations will be processed. But in the scenario where ActivationPreference is lazy, if the first time it is not processed and resourceChangedByKarmada will be true on the second time, it will not be processed, so rb will not even be created. This is the reason why e2e test failed. If I want to achieve my goal right now, I can actually set ActivationPreference to Lazy. Right? |
Do you mean which E2E test?
No, I don't think so.
Please refer to the side effects from the |
Signed-off-by: vie-serendipity <[email protected]>
b4e7309 to
b9cf2d6
Compare
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No, I mean this one, which is about lazy_activation_policy_test. For karmadactl_test you refer to, I think that would be related to githu workflow environment. Because this time it passed. |
|
I see, will look at it. |
I see. Maybe, the claimed operation should be ignored(skip reconciliation), no matter considering |
|
This PR seems to be stuck—I'll take a look. |
|
There are generally two approaches to skip redundant processing:
|
This approach is worth exploring further. Just a reminder, we have some logic where relying on the behavior, I mean, once a PropagationPolicy is removed, the detector will cleanup the claimed metadata from the resource template and expect a following reconcile to match another PropagationPolicy. |
|
Thanks for your reminder—this is indeed an issue. It could likely be resolved by distinguishing whether the operation is specifically adding |
If there are no further changes to resources, the member cluster resources will lack claim metadata. I think we should maintain consistency; in addition, in some cases the claim metadata on resources is also helpful for troubleshooting. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR solves a problem where, when claim metadata is added to an object, the object should be processed next time because the update event will enqueue it again.
Every object will be handled by detector twice at least even though nothing changed. And accordingly every rb will be handled twice by rb controller. This should be optimized.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: