Skip to content

Conversation

Kexin2000
Copy link

What type of PR is this?

/kind feature
/kind cleanup

What this PR does / why we need it:
This PR introduces two key improvements to the dependency distribution mechanism in Karmada:

  1. Enhanced Observability: Adds new event reasons to improve visibility into dependency policy conflicts and aggregation.
  2. Behavioral Fix: Prevents the dependency controller from overwriting ConflictResolution and PreserveResourcesOnDeletion fields on ResourceBindings (RBs) that are explicitly governed by PropagationPolicy or ClusterPropagationPolicy.

These changes address issues where multi-path distribution could cause field flapping and unpredictable behavior, ensuring more stable and predictable resource management.

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

Special notes for your reviewer:

  • Adds the following event reasons in pkg/events/events.go:
    • DependencyPolicyConflict: Indicates multiple parents have divergent dependency policies.
    • DependencyPolicyAggregated: Indicates aggregated dependency policies have been applied.
    • DependencyOverriddenByExplicitPolicy: Indicates dependency path is overridden by explicit policy.
  • Updates createOrUpdateAttachedBinding in pkg/dependenciesdistributor/dependencies_distributor.go to:
    • Only set ConflictResolution and PreserveResourcesOnDeletion when the existing RB is dependency-generated (Spec.Placement == nil).
    • Emit a warning event when dependency path settings are ignored due to explicit policy ownership.

Does this PR introduce a user-facing change?:

- Added new event reasons for dependency policy conflicts and aggregation.  
- Dependency controller no longer overwrites [ConflictResolution](http://_vscodecontentref_/0) and [PreserveResourcesOnDeletion](http://_vscodecontentref_/1) fields on explicitly governed ResourceBindings.  

@Copilot 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

[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 assign xishanyongye-chang for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
Collaborator

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

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

if attachedBinding.Spec.PreserveResourcesOnDeletion != nil || attachedBinding.Spec.ConflictResolution != "" {
// notify that dependency path settings are ignored due to explicit policy ownership
d.EventRecorder.Eventf(existBinding, corev1.EventTypeWarning, events.EventReasonDependencyOverriddenByExplicitPolicy,
"Ignore dependency settings for %s/%s because it is governed by explicit policy.", existBinding.Namespace, existBinding.Name)
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The error message format uses string formatting with %s placeholders but the message text says "Ignore" which is grammatically awkward. Consider changing to "Ignoring dependency settings for %s/%s because it is governed by explicit policy."

Suggested change
"Ignore dependency settings for %s/%s because it is governed by explicit policy.", existBinding.Namespace, existBinding.Name)
"Ignoring dependency settings for %s/%s because it is governed by explicit policy.", existBinding.Namespace, existBinding.Name)

Copilot uses AI. Check for mistakes.

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.

existBinding.Spec.PreserveResourcesOnDeletion = attachedBinding.Spec.PreserveResourcesOnDeletion
} else {
// explicit RB: do not override conflict-related fields via dependency path
if attachedBinding.Spec.PreserveResourcesOnDeletion != nil || attachedBinding.Spec.ConflictResolution != "" {

Choose a reason for hiding this comment

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

high

The current condition for triggering a warning event, attachedBinding.Spec.ConflictResolution != "", will always be true because ConflictResolution is a required field with a default value of "Abort". This will cause an event to be logged on every reconciliation for every dependency with an explicit policy, leading to excessive and noisy event logs.

A better approach is to check if the values from the dependency path (attachedBinding) actually differ from what's already on the explicit ResourceBinding (existBinding). This ensures that a warning is only emitted when a meaningful configuration difference is being ignored.

Suggested change
if attachedBinding.Spec.PreserveResourcesOnDeletion != nil || attachedBinding.Spec.ConflictResolution != "" {
if !equality.Semantic.DeepEqual(attachedBinding.Spec.PreserveResourcesOnDeletion, existBinding.Spec.PreserveResourcesOnDeletion) || attachedBinding.Spec.ConflictResolution != existBinding.Spec.ConflictResolution {

@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

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

Codecov Report

❌ Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.83%. Comparing base (768f929) to head (7ad6c3f).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
...ependenciesdistributor/dependencies_distributor.go 22.22% 6 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6795      +/-   ##
==========================================
+ Coverage   45.75%   45.83%   +0.08%     
==========================================
  Files         689      690       +1     
  Lines       57176    57307     +131     
==========================================
+ Hits        26159    26268     +109     
- Misses      29390    29407      +17     
- Partials     1627     1632       +5     
Flag Coverage Δ
unittests 45.83% <22.22%> (+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.

@Kexin2000 Kexin2000 changed the title add dependency policy events; prevent overriding explicit RB fields add dependency policy events Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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. size/S Denotes a PR that changes 10-29 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

3 participants