Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

whitewindmills
Copy link
Member

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?:

NONE

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 10, 2024
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 10, 2024
@XiShanYongYe-Chang
Copy link
Member

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.

@whitewindmills
Copy link
Member Author

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.

@XiShanYongYe-Chang
Copy link
Member

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?

@whitewindmills
Copy link
Member Author

Are you referring to the gc controller responsible for cleaning up the resource bindings of the resource template?

sure

@XiShanYongYe-Chang
Copy link
Member

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?

@whitewindmills
Copy link
Member Author

Can you help add some comments on the event handler to explain why we don't need to care about this?

okay

@XiShanYongYe-Chang
Copy link
Member

/cc @chaunceyjiang
/assign

@codecov-commenter
Copy link

codecov-commenter commented Jan 12, 2024

Codecov Report

Attention: Patch coverage is 26.66667% with 22 lines in your changes are missing coverage. Please review.

Project coverage is 53.26%. Comparing base (81acb31) to head (b30e537).

Files Patch % Lines
...ependenciesdistributor/dependencies_distributor.go 26.66% 20 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    #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     
Flag Coverage Δ
unittests 53.26% <26.66%> (-0.03%) ⬇️

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.

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.

Other parts LGTM

@whitewindmills
Copy link
Member Author

ping @chaunceyjiang
could you help take a look?

@XiShanYongYe-Chang
Copy link
Member

/lgtm
/kind cleanup

@karmada-bot karmada-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. labels Jan 15, 2024
@XiShanYongYe-Chang
Copy link
Member

@whitewindmills
Copy link
Member Author

Could you help move it forward?
/assign @RainbowMango

@RainbowMango
Copy link
Member

@chaunceyjiang Do you want to take another look? As you are the related code author.

@whitewindmills
Copy link
Member Author

@chaunceyjiang Could you help take a look?

@XiShanYongYe-Chang
Copy link
Member

Hi @whitewindmills, We can move forward with this PR. Can you rebase it and confirm if there are any required changes?

@whitewindmills whitewindmills force-pushed the improve_dependencies_distributor branch from b901dcb to 43f0dca Compare May 27, 2024 01:36
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label May 27, 2024
@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 ask for approval from rainbowmango. 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

@whitewindmills whitewindmills force-pushed the improve_dependencies_distributor branch from 43f0dca to b30e537 Compare May 27, 2024 01:48
@whitewindmills
Copy link
Member Author

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.

Comment on lines +141 to +143
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()))
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

For this part:

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)
}

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang May 28, 2024

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.

Copy link
Member

Choose a reason for hiding this comment

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

/lgtm

Copy link
Member

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.

Copy link
Member Author

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.

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)
}

Copy link
Member

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.

@chaunceyjiang
Copy link
Member

/assign

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label May 28, 2024
@whitewindmills
Copy link
Member Author

ping @chaunceyjiang

klog.Errorf("Failed to transform newObj, error: %v", err)
return
}
if !unstructuredNewObj.GetDeletionTimestamp().IsZero() {
Copy link
Member

@chaunceyjiang chaunceyjiang May 31, 2024

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants