Skip to content

Conversation

@zhzhuang-zju
Copy link
Contributor

@zhzhuang-zju zhzhuang-zju commented Aug 28, 2025

Cherry pick of #6656 on release-1.12.
#6656: fixed the issue where pp-related claimMetadata was not
For details on the cherry pick process, see the cherry pick requests page.

`karmada-controller-manager`: Fixed the issue where pp-related claimMetadata was not properly cleaned up when deleting propagationpolicy with Lazy activationPreference.

@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 28, 2025
Copy link

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @zhzhuang-zju, 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 is an automated cherry-pick of a fix from PR #6656, addressing an issue where claimMetadata associated with PropagationPolicy and ClusterPropagationPolicy was not being consistently cleaned up. The changes introduce a more robust and centralized mechanism for metadata cleanup, particularly during policy deletion or when policies are no longer active. This is achieved by refactoring existing cleanup handlers, introducing new helper functions for streamlined operations, and improving conflict resolution during updates to ensure that both resource templates and their associated bindings have their metadata removed properly.

Highlights

  • Refactored Policy Deletion Handlers: The logic for handling the deletion of PropagationPolicy and ClusterPropagationPolicy has been refactored to iterate over the policy's ResourceSelectors. This ensures that cleanup operations are more precise and only target the resources specified by the policy.
  • Centralized Metadata Cleanup Logic: A new helper function, handleResourceTemplateAndBindingCleanup, has been introduced. This function centralizes the process of removing claimMetadata from both the resource template and its corresponding ResourceBinding or ClusterResourceBinding, improving code reusability and maintainability.
  • Improved Conflict Resolution for Metadata Updates: The metadata cleanup functions now include robust conflict resolution mechanisms. When updating resource templates or bindings, the system will re-fetch the latest version and retry the update if a conflict occurs, ensuring data consistency.
  • New Utility Functions for Resource Handling: New utility functions like fetchResourceBinding, fetchClusterResourceBinding, and ExtractUniqueNamespacedSelectors have been added to support the refactored cleanup and policy application logic, making the process more efficient and reliable.
  • Enhanced Policy Application and Race Condition Handling: The policy application logic has been enhanced to prevent policies that are actively being deleted from being applied. Additionally, if a policy is unexpectedly not found, the system will now proactively trigger a metadata cleanup for the associated resource template, addressing potential race conditions.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue comments and review comments.
Help /gemini help Displays a list of available commands.

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

  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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 is a cherry-pick that fixes an issue with the cleanup of propagation policy-related claim metadata. The changes are robust, refactoring the deletion logic to be driven by resource selectors from the policy, which is more resilient to cache inconsistencies. The introduction of helper functions for fetching bindings with a fallback to the dynamic client, along with improved conflict handling, significantly enhances the reliability of policy management. The code correctly addresses several race conditions and edge cases. I have one minor suggestion for improving logging consistency.

Comment on lines +1179 to +1180
klog.Errorf("Failed to clean up claim metadata from ResourceBinding(%s/%s), error: %v",
objRef.Namespace, bindingName, err)

Choose a reason for hiding this comment

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

medium

For consistency and to avoid potential confusion during debugging, it's better to use template.GetNamespace() in this log message, as it was the value passed to CleanupResourceBindingClaimMetadata on the preceding line. While objRef.Namespace and template.GetNamespace() are expected to be identical here, using the same variable enhances readability and maintainability.

Suggested change
klog.Errorf("Failed to clean up claim metadata from ResourceBinding(%s/%s), error: %v",
objRef.Namespace, bindingName, err)
klog.Errorf("Failed to clean up claim metadata from ResourceBinding(%s/%s), error: %v",
template.GetNamespace(), bindingName, err)

@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2025

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

Codecov Report

❌ Patch coverage is 6.39269% with 205 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.58%. Comparing base (86ed361) to head (a2ce1f5).

Files with missing lines Patch % Lines
pkg/detector/detector.go 0.00% 164 Missing ⚠️
pkg/detector/policy.go 0.00% 41 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@               Coverage Diff                @@
##           release-1.12    #6705      +/-   ##
================================================
- Coverage         46.65%   46.58%   -0.08%     
================================================
  Files               665      665              
  Lines             54928    55053     +125     
================================================
+ Hits              25629    25644      +15     
- Misses            27667    27777     +110     
  Partials           1632     1632              
Flag Coverage Δ
unittests 46.58% <6.39%> (-0.08%) ⬇️

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

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

@zhzhuang-zju zhzhuang-zju force-pushed the automated-cherry-pick-of-#6656-upstream-release-1.12 branch from a94fede to a2ce1f5 Compare August 28, 2025 06:23
Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 29, 2025
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 29, 2025
@karmada-bot karmada-bot merged commit f2b85a6 into karmada-io:release-1.12 Aug 29, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants