Skip to content

Conversation

@Kexin2000
Copy link
Contributor

@Kexin2000 Kexin2000 commented Sep 29, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds observability for dependency policy conflicts. When multiple independent resources define divergent policies on the same dependent resource, Karmada now emits a single warning event to surface the behavior.

Which issue(s) this PR fixes:
Fixes #6000
Part of #6803

Special notes for your reviewer:

  • Adds the following event reason in pkg/events/events.go:

    • DependencyPolicyConflict: emitted when a dependency policy conflict is detected.
  • Updates createOrUpdateAttachedBinding in pkg/dependenciesdistributor/dependencies_distributor.go to:

    • Treat RBs with Spec.Placement == nil as dependency-generated:
      • Detect conflicts and emit a Warning event (DependencyPolicyConflict).
    • For policy-owned RBs (Spec.Placement != nil), leave Spec.ConflictResolution unchanged

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Added a new Warning event `DependencyPolicyConflict` to surface when dependency policy have conflicts.

Copilot AI review requested due to automatic review settings September 29, 2025 17:49
@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 29, 2025
@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 29, 2025
@karmada-bot
Copy link
Collaborator

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

@gemini-code-assist
Copy link

Summary of Changes

Hello @Kexin2000, 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 stability and predictability of resource management in Karmada by addressing issues related to multi-path distribution. It enhances the system's ability to communicate dependency policy states through new event reasons and rectifies a behavioral flaw where dependency mechanisms could inadvertently override explicitly defined resource binding configurations. These changes collectively aim to prevent field flapping and ensure that explicit policies are respected, leading to more robust and understandable resource propagation.

Highlights

  • Enhanced Observability: Introduced new event reasons (DependencyPolicyConflict, DependencyPolicyAggregated, DependencyOverriddenByExplicitPolicy) to provide better visibility into dependency policy conflicts and aggregation within Karmada's dependency distribution mechanism.
  • Behavioral Fix for ResourceBindings: Prevented the dependency controller from overwriting ConflictResolution and PreserveResourcesOnDeletion fields on ResourceBindings (RBs) that are explicitly governed by PropagationPolicy or ClusterPropagationPolicy, ensuring explicit policies take precedence.
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 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.

@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 29, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the dependency distribution mechanism in Karmada by adding observability events and preventing field overrides on explicitly governed ResourceBindings. The changes address issues with multi-path distribution causing field flapping and unpredictable behavior.

  • Adds three new event reasons for better visibility into dependency policy conflicts and aggregation
  • Modifies dependency controller to respect explicit policy ownership of ResourceBindings
  • Prevents overwriting of ConflictResolution and PreserveResourcesOnDeletion fields when ResourceBindings are governed by PropagationPolicy or ClusterPropagationPolicy

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/events/events.go Adds three new event reason constants for dependency policy handling
pkg/dependenciesdistributor/dependencies_distributor.go Updates binding update logic to conditionally set fields and emit warning events

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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 introduces new events for dependency policies and prevents the dependency distributor from overwriting fields on ResourceBindings that are managed by an explicit policy. The changes are logical and address the intended issue. However, I've found one issue with the implementation of the new warning event, which could lead to excessive event logging. My review includes a suggestion to refine the condition for firing this event to make it more meaningful and less noisy.

@Kexin2000 Kexin2000 marked this pull request as draft September 29, 2025 17:51
@karmada-bot karmada-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 29, 2025
@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2025

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

Codecov Report

❌ Patch coverage is 85.48387% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.28%. Comparing base (f3c4376) to head (e6922db).
⚠️ Report is 66 commits behind head on master.

Files with missing lines Patch % Lines
...ependenciesdistributor/dependencies_distributor.go 66.66% 2 Missing and 3 partials ⚠️
pkg/dependenciesdistributor/policy_utils.go 91.48% 2 Missing and 2 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6795      +/-   ##
==========================================
+ Coverage   45.82%   46.28%   +0.46%     
==========================================
  Files         690      693       +3     
  Lines       57242    47249    -9993     
==========================================
- Hits        26231    21871    -4360     
+ Misses      29384    23721    -5663     
- Partials     1627     1657      +30     
Flag Coverage Δ
unittests 46.28% <85.48%> (+0.46%) ⬆️

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.

@Kexin2000 Kexin2000 changed the title add dependency policy events; prevent overriding explicit RB fields add dependency policy events Sep 30, 2025
@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 17, 2025
@XiShanYongYe-Chang
Copy link
Member

If the PR is ready, remember to cc me.

@Kexin2000 Kexin2000 force-pushed the kt1 branch 2 times, most recently from d720532 to 1efab6c Compare October 21, 2025 21:30
@Kexin2000 Kexin2000 changed the title add dependency policy events Add dependency policy event: DependencyPolicyConflictResolved Oct 21, 2025
@Kexin2000 Kexin2000 force-pushed the kt1 branch 2 times, most recently from 59d702b to 40cfc94 Compare October 22, 2025 01:26
@Kexin2000 Kexin2000 marked this pull request as ready for review October 22, 2025 06:52
@karmada-bot karmada-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 22, 2025
@karmada-bot karmada-bot requested a review from Garrybest October 22, 2025 06:52
@Kexin2000
Copy link
Contributor Author

Hi @XiShanYongYe-Chang, the PR is now ready for review. Please take a look when you are free. 😃 This PR only adds the new event. The changes to the conflict field aggregation logic are in a separate PR #6796.

@XiShanYongYe-Chang
Copy link
Member

Hi @XiShanYongYe-Chang, the PR is now ready for review. Please take a look when you are free. 😃 This PR only adds the new event. The changes to the conflict field aggregation logic are in a separate PR #6796.

Good.

/assign

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 introduces a new event, DependencyPolicyConflict, to enhance observability for dependency policy conflicts in Karmada. It modifies the createOrUpdateAttachedBinding function to detect conflicts in ConflictResolution and PreserveResourcesOnDeletion settings, emitting a warning event when discrepancies are found. Additionally, the pull request includes corresponding unit tests to validate the new functionality. No style guide was provided, so the review focuses on correctness and code clarity.

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.

Thanks~

@Kexin2000
Copy link
Contributor Author

/gemini review

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 introduces a new DependencyPolicyConflict event to improve observability when multiple resources define conflicting dependency policies. The implementation correctly identifies conflicts in ConflictResolution and PreserveResourcesOnDeletion for dependency-generated resource bindings and emits a warning event. The changes are well-tested. I've provided a few suggestions to improve code quality, performance, and conciseness.

@Kexin2000
Copy link
Contributor Author

/gemini review

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 introduces a new DependencyPolicyConflict event to provide observability into conflicting dependency policies. The implementation adds new logic to detect conflicts in ConflictResolution and PreserveResourcesOnDeletion settings from different ResourceBindings. The changes are well-tested with a new unit test to verify event emission.

My review focuses on improving the efficiency of the new conflict detection logic and adhering to best practices for context propagation. I've suggested merging the two conflict detection functions into one to reduce redundant API calls. I also pointed out the use of context.TODO() and a minor issue with a copyright year.

@Kexin2000 Kexin2000 force-pushed the kt1 branch 2 times, most recently from 0f9ed1b to 94db2de Compare October 27, 2025 04:29
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.

Thanks~
/lgtm
/cc @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 27, 2025
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Oct 27, 2025
Signed-off-by: Kexin2000 <3299133282@qq.com>
@XiShanYongYe-Chang
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 27, 2025
@RainbowMango RainbowMango added this to the v1.16 milestone Oct 28, 2025
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/assign

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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 Oct 28, 2025
@karmada-bot karmada-bot merged commit e2864be into karmada-io:master Oct 28, 2025
24 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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Whether to forbid the same resource multi dependency distribution

5 participants