-
Notifications
You must be signed in to change notification settings - Fork 885
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
Add finalizer in (Cluster)ResourceBinding to delete works #756
Conversation
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.
Looks pretty good to me.
Just some nits, otherwise LGTM.
This patch might be confit with #752. Let's merge the one which gets ready first. :)
@@ -174,11 +173,11 @@ func GetWorks(c client.Client, ls labels.Set) (*workv1alpha1.WorkList, error) { | |||
} | |||
|
|||
// DeleteWorks will delete all Work objects by labels. | |||
func DeleteWorks(c client.Client, selector labels.Set) (controllerruntime.Result, error) { | |||
func DeleteWorks(c client.Client, selector labels.Set) error { |
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
The helper function should not couple reconciler logic.
@@ -626,7 +626,8 @@ func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructure | |||
OwnerReferences: []metav1.OwnerReference{ | |||
*metav1.NewControllerRef(object, objectKey.GroupVersionKind()), | |||
}, | |||
Labels: labels, | |||
Labels: labels, | |||
Finalizers: []string{util.BindingControllerFinalizer}, |
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 guess we should update this place as well:
karmada/pkg/util/detector/detector.go
Lines 438 to 445 in 1947cf2
operationResult, err := controllerutil.CreateOrUpdate(context.TODO(), d.Client, bindingCopy, func() error { | |
// Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists. | |
bindingCopy.Labels = binding.Labels | |
bindingCopy.OwnerReferences = binding.OwnerReferences | |
bindingCopy.Spec.Resource = binding.Spec.Resource | |
bindingCopy.Spec.ReplicaRequirements = binding.Spec.ReplicaRequirements | |
bindingCopy.Spec.Replicas = binding.Spec.Replicas | |
return nil |
Same as below.
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, bindingCopy.Finalizers = binding.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.
Done
This patch is reasonable to me. Would like to take a look? |
/hold @shuazi Have you started your work? |
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 suppose this PR is related to #756.
@@ -626,7 +626,8 @@ func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructure | |||
OwnerReferences: []metav1.OwnerReference{ | |||
*metav1.NewControllerRef(object, objectKey.GroupVersionKind()), | |||
}, | |||
Labels: labels, | |||
Labels: labels, | |||
Finalizers: []string{util.BindingControllerFinalizer}, |
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, bindingCopy.Finalizers = binding.Finalizers
bfec0a5
to
5efa01b
Compare
@RainbowMango @Garrybest Thanks for your review!
Sorry I didn't get your point, this is exactly #756😂 |
c452b9f
to
48cd417
Compare
/lgtm |
/hold cancel |
Sorry, I'm still working on the conflict and squash... |
Fine, no rush. |
8b0537f
to
ede9fad
Compare
Signed-off-by: dddddai <dddwq@foxmail.com>
@RainbowMango @XiShanYongYe-Chang Thanks for elaborating, conflict is resolved, PTAL |
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. 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 |
/lgtm |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Add finalizer in ResourceBinding and ClusterResourceBinding to delete works.
If we delete workload while karmada-controller-manager crashes, this will make sure (Cluster)ResourceBinding remains until controller-manager is ready, then it handles the delete event to delete related works.
Which issue(s) this PR fixes:
Fixes #708
Special notes for your reviewer:
I followed this and verified it works in my local environment.
Does this PR introduce a user-facing change?: