fix: prevent duplicate objects in FetchResourceTemplatesByLabelSelector#7671
Conversation
When cache fails and falls back to API server, the function was appending both the fallback results AND the original (empty) cache results, causing duplicates. Add a usedFallback flag to track when fallback is used, and only append cache objects if fallback was not used. Fixes karmada-io#7670 Signed-off-by: barbierajput378-pixel <barbierajput378@gmail.com>
Summary of ChangesHello, 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 addresses a bug in 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 the 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 counterproductive. 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. Footnotes
|
|
Welcome @barbierajput378-pixel! It looks like this is your first PR to karmada-io/karmada 🎉 |
There was a problem hiding this comment.
Code Review
This pull request introduces a usedFallback boolean flag in FetchResourceTemplatesByLabelSelector to prevent processing cached objects when a fallback to the API server occurs. The reviewer suggests simplifying the control flow by returning early from the fallback block, which eliminates the need for the usedFallback flag and reduces nesting in the subsequent cache-processing loop.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This pull request fixes a control-flow issue in FetchResourceTemplatesByLabelSelector (pkg/util/helper/binding.go) that could cause the returned resource template list to include duplicates when the informer cache path falls back to an API-server list.
Changes:
- Introduces a
usedFallbackflag to track whether the API-server fallback path was taken. - Skips appending objects from the informer cache when fallback was used, preventing duplicate results.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Added a usedFallback flag to prevent duplicate objects when cache fails. Tests passing locally - ready for review! @XiShanYongYe-Chang , @whitewindmills |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7671 +/- ##
=======================================
Coverage 42.06% 42.06%
=======================================
Files 879 879
Lines 54831 54832 +1
=======================================
+ Hits 23063 23066 +3
+ Misses 30023 30022 -1
+ Partials 1745 1744 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/assign |
…ly return Signed-off-by: barbierajput378-pixel <barbierajput378@gmail.com>
|
Invalid commit message issues detected Invalid commit messagesKeywords which can automatically close issues and hashtag(#) mentions are not allowed.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
[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 |
|
Incorporated the feedback - simplified with early return instead of the usedFallback flag. Ready for review! |
|
/remove-kind bug |
/kind bug
What this PR does / why we need it:
Fixes the duplicate objects bug in FetchResourceTemplatesByLabelSelector function in pkg/util/helper/binding.go.
When cache fails and falls back to API server, the function was appending both the fallback results AND the original (empty) cache results, causing duplicates.
Added a
usedFallbackflag to track when fallback is used, and only append cache objects if fallback was NOT used.Which issue(s) this PR fixes:
Fixes #7670
Special notes for your reviewer:
Tested locally with:
go test ./pkg/util/helper/All tests passed successfully.
Does this PR introduce a user-facing change?: