-
Notifications
You must be signed in to change notification settings - Fork 919
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
reduce useless logic to improve dependencies distributor #4532
base: master
Are you sure you want to change the base?
reduce useless logic to improve dependencies distributor #4532
Conversation
I don't quite understand why dependencies distributor doesn't need to be concerned about deletion events. When the attached resource template is deleted, the corresponding rb should also need to be cleaned up. |
Since the attached resource template is deleted, so it's resourceBinding is deleted, cleaning up makes no sense. |
Are you referring to the gc controller responsible for cleaning up the resource bindings of the resource template? |
sure |
Thanks, I get it. Can you help add some comments on the event handler to explain why we don't need to care about this? |
okay |
/cc @chaunceyjiang |
1d7989b
to
b901dcb
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #4532 +/- ##
==========================================
- Coverage 53.29% 53.26% -0.03%
==========================================
Files 252 252
Lines 20495 20508 +13
==========================================
+ Hits 10922 10924 +2
- Misses 8851 8861 +10
- Partials 722 723 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Other parts LGTM
ping @chaunceyjiang |
/lgtm |
Kind ping @chaunceyjiang @RainbowMango |
Could you help move it forward? |
@chaunceyjiang Do you want to take another look? As you are the related code author. |
@chaunceyjiang Could you help take a look? |
Hi @whitewindmills, We can move forward with this PR. Can you rebase it and confirm if there are any required changes? |
b901dcb
to
43f0dca
Compare
[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 |
Signed-off-by: whitewindmills <[email protected]>
43f0dca
to
b30e537
Compare
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.
/assign @XiShanYongYe-Chang @chaunceyjiang
if !unstructuredNewObj.GetDeletionTimestamp().IsZero() { | ||
klog.V(4).Infof("Ignore update event of object(%s, kind=%s, %s) as being deleted.", | ||
unstructuredNewObj.GetAPIVersion(), unstructuredNewObj.GetKind(), names.NamespacedKey(unstructuredNewObj.GetNamespace(), unstructuredNewObj.GetName())) |
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.
It's better to check it in the reconciling loop in case there are some clean-up tasks.
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.
but it's for resource template, we won't have any cleanup.
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.
+1
Our current model cannot discard this event, otherwise it would not be possible to do the cleanup.
Other parts LGTM.
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.
I don't get what to clean up. the schedule result of attached bindings? or labels about dependencies?
since it will definitely be deleted, there is no point in us cleaning these.
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.
For this part:
karmada/pkg/dependenciesdistributor/dependencies_distributor.go
Lines 256 to 263 in d676996
if !bindingObject.Spec.PropagateDeps || !bindingObject.DeletionTimestamp.IsZero() { | |
err = d.handleIndependentBindingDeletion(request.Namespace, request.Name) | |
if err != nil { | |
klog.Errorf("Failed to cleanup attached bindings for independent binding(%s): %v", request.NamespacedName, err) | |
return reconcile.Result{}, err | |
} | |
return reconcile.Result{}, d.removeFinalizer(ctx, bindingObject) | |
} |
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.
We have added a finalizer. The delete event does not handle this.
Sorry, I gave the wrong example. This is a resource template update event.
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.
/lgtm
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.
I don't have a strong opinion just feel not good to do such things in event filter.
I'm not sure that's a good pattern, my thinking is the event filter should be simple.
Let's @chaunceyjiang make the final decision.
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.
I don't have a strong opinion just feel not good to do such things in event filter.
I'm not sure that's a good pattern, my thinking is the event filter should be simple.
I don't totally agree. if unnecessary events can be filtered out before they are queued, this can significantly improve the efficiency of the work queue. Of course, keeping it simple is also a consideration, but compared to this type of processing in the detector, this obviously does not add much complexity.
karmada/pkg/detector/detector.go
Lines 907 to 953 in 6fbdd9e
func (d *ResourceDetector) OnPropagationPolicyUpdate(oldObj, newObj interface{}) { | |
d.policyReconcileWorker.Enqueue(newObj) | |
// Temporary solution of corner case: After the priority(.spec.priority) of | |
// PropagationPolicy changed from high priority (e.g. 5) to low priority(e.g. 3), | |
// we should try to check if there is a PropagationPolicy(e.g. with priority 4) | |
// could preempt the targeted resources. | |
// | |
// Recognized limitations of the temporary solution are: | |
// - Too much logical processed in an event handler function will slow down | |
// the overall reconcile speed. | |
// - If there is an error raised during the process, the event will be lost | |
// and no second chance to retry. | |
// | |
// The idea of the long-term solution, perhaps PropagationPolicy could have | |
// a status, in that case we can record the observed priority(.status.observedPriority) | |
// which can be used to detect priority changes during reconcile logic. | |
if features.FeatureGate.Enabled(features.PolicyPreemption) { | |
var unstructuredOldObj *unstructured.Unstructured | |
var unstructuredNewObj *unstructured.Unstructured | |
unstructuredOldObj, err := helper.ToUnstructured(oldObj) | |
if err != nil { | |
klog.Errorf("Failed to transform oldObj, error: %v", err) | |
return | |
} | |
unstructuredNewObj, err = helper.ToUnstructured(newObj) | |
if err != nil { | |
klog.Errorf("Failed to transform newObj, error: %v", err) | |
return | |
} | |
var oldPolicy policyv1alpha1.PropagationPolicy | |
var newPolicy policyv1alpha1.PropagationPolicy | |
if err = helper.ConvertToTypedObject(unstructuredOldObj, &oldPolicy); err != nil { | |
klog.Errorf("Failed to convert typed PropagationPolicy(%s/%s): %v", unstructuredOldObj.GetNamespace(), unstructuredOldObj.GetName(), err) | |
return | |
} | |
if err = helper.ConvertToTypedObject(unstructuredNewObj, &newPolicy); err != nil { | |
klog.Errorf("Failed to convert typed PropagationPolicy(%s/%s): %v", newPolicy.GetNamespace(), newPolicy.GetName(), err) | |
return | |
} | |
if newPolicy.ExplicitPriority() < oldPolicy.ExplicitPriority() { | |
d.HandleDeprioritizedPropagationPolicy(oldPolicy, newPolicy) | |
} |
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.
It's better to check it in the reconciling loop in case there are some clean-up tasks.
I also lean towards this, I don't really recommend adding too much logic processing in the event Filter.
/assign |
ping @chaunceyjiang |
klog.Errorf("Failed to transform newObj, error: %v", err) | ||
return | ||
} | ||
if !unstructuredNewObj.GetDeletionTimestamp().IsZero() { |
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.
I remember, if a resource doesn't have Finalizers
, then when it is deleted, there won't be any update events.
So, we have no way to check the DeletionTimestamp
.
Most resources probably don't have Finalizers
.
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.
what this PR wants to do is to ignore the resources that need to be deleted.
What type of PR is this?
/kind feature
What this PR does / why we need it:
The dependent distributor does not pay attention to deleted or deleting attached resource templates, so optimize this part of the logic.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: