-
Notifications
You must be signed in to change notification settings - Fork 1k
add dependency policy events #6795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
[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.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @Kexin2000! It looks like this is your first PR to karmada-io/karmada 🎉 |
Summary of ChangesHello @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
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 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 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
|
There was a problem hiding this 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) |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
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."
"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.
There was a problem hiding this 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 != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
if attachedBinding.Spec.PreserveResourcesOnDeletion != nil || attachedBinding.Spec.ConflictResolution != "" { | |
if !equality.Semantic.DeepEqual(attachedBinding.Spec.PreserveResourcesOnDeletion, existBinding.Spec.PreserveResourcesOnDeletion) || attachedBinding.Spec.ConflictResolution != existBinding.Spec.ConflictResolution { |
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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:
ConflictResolution
andPreserveResourcesOnDeletion
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:
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.createOrUpdateAttachedBinding
inpkg/dependenciesdistributor/dependencies_distributor.go
to:ConflictResolution
andPreserveResourcesOnDeletion
when the existing RB is dependency-generated (Spec.Placement == nil
).Does this PR introduce a user-facing change?: