Skip to content

fix: prevent duplicate objects in FetchResourceTemplatesByLabelSelector#7671

Open
barbierajput378-pixel wants to merge 2 commits into
karmada-io:masterfrom
barbierajput378-pixel:fetch-resource-templates-duplicates
Open

fix: prevent duplicate objects in FetchResourceTemplatesByLabelSelector#7671
barbierajput378-pixel wants to merge 2 commits into
karmada-io:masterfrom
barbierajput378-pixel:fetch-resource-templates-duplicates

Conversation

@barbierajput378-pixel

Copy link
Copy Markdown

/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 usedFallback flag 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?:

NONE

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>
Copilot AI review requested due to automatic review settings June 27, 2026 11:59
@karmada-bot karmada-bot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. labels Jun 27, 2026
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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 FetchResourceTemplatesByLabelSelector function where duplicate objects were being returned. By implementing a conditional check, the function now correctly handles the fallback mechanism to the API server, preventing redundant data processing when the cache is unavailable or empty.

Highlights

  • Duplicate Object Prevention: Introduced a usedFallback flag to track when the cache lookup fails, ensuring that original cache results are not incorrectly appended when the API server fallback is triggered.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot

Copy link
Copy Markdown
Contributor

Welcome @barbierajput378-pixel! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 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.

Comment thread pkg/util/helper/binding.go Outdated
Comment thread pkg/util/helper/binding.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 usedFallback flag 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.

@barbierajput378-pixel

Copy link
Copy Markdown
Author

Added a usedFallback flag to prevent duplicate objects when cache fails. Tests passing locally - ready for review! @XiShanYongYe-Chang , @whitewindmills

@codecov-commenter

codecov-commenter commented Jun 27, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.06%. Comparing base (56d5d87) to head (a27ab2a).
⚠️ Report is 16 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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     
Flag Coverage Δ
unittests 42.06% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@whitewindmills

Copy link
Copy Markdown
Member

/assign

…ly return

Signed-off-by: barbierajput378-pixel <barbierajput378@gmail.com>
@karmada-bot

Copy link
Copy Markdown
Contributor

Invalid commit message issues detected

Invalid commit messages

Keywords which can automatically close issues and hashtag(#) mentions are not allowed.

  • e17660d fix: prevent duplicate objects in FetchResourceTemplatesByLabelSelector

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.

@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from whitewindmills. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 27, 2026
@barbierajput378-pixel

Copy link
Copy Markdown
Author

Incorporated the feedback - simplified with early return instead of the usedFallback flag. Ready for review!

Comment thread pkg/util/helper/binding.go
@zhzhuang-zju

Copy link
Copy Markdown
Contributor

/remove-kind bug
/kind cleanup

@karmada-bot karmada-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FetchResourceTemplatesByLabelSelector returns duplicate objects

6 participants