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

Add finalizer in (Cluster)ResourceBinding to delete works #756

Merged
merged 1 commit into from
Sep 29, 2021

Conversation

dddddai
Copy link
Member

@dddddai dddddai commented Sep 24, 2021

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

NONE

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 24, 2021
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 24, 2021
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.

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 {
Copy link
Member

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},
Copy link
Member

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:

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.

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

pkg/controllers/binding/binding_controller.go Outdated Show resolved Hide resolved
@RainbowMango
Copy link
Member

This patch is reasonable to me. Would like to take a look?
@mrlihanbo @Garrybest

@RainbowMango
Copy link
Member

/hold
hold on. I just realized #708 has been claimed by @shuazi (#708 (comment)), unfortunately, the assignment seems not successful.

@shuazi Have you started your work?

@karmada-bot karmada-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 28, 2021
Copy link
Member

@Garrybest Garrybest left a 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.

pkg/controllers/binding/binding_controller.go Outdated Show resolved Hide resolved
@@ -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},
Copy link
Member

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

@dddddai dddddai force-pushed the add-finalizer branch 2 times, most recently from bfec0a5 to 5efa01b Compare September 28, 2021 02:25
@dddddai
Copy link
Member Author

dddddai commented Sep 28, 2021

@RainbowMango @Garrybest Thanks for your review!
I have modified as you addressed, PTAL

I suppose this PR is related to #756.

Sorry I didn't get your point, this is exactly #756😂

@Garrybest
Copy link
Member

Sorry I didn't get your point, this is exactly #756😂

Oh I'm sorry. I mean #752.

@dddddai dddddai force-pushed the add-finalizer branch 2 times, most recently from c452b9f to 48cd417 Compare September 28, 2021 02:55
@RainbowMango
Copy link
Member

/lgtm
But, @dddddai you have to solve the conflict.

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2021
@RainbowMango
Copy link
Member

/hold cancel
Didn't get a response from @shuaizi.

@karmada-bot karmada-bot removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Sep 29, 2021
@dddddai
Copy link
Member Author

dddddai commented Sep 29, 2021

Sorry, I'm still working on the conflict and squash...

@dddddai dddddai marked this pull request as draft September 29, 2021 03:06
@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, 2021
@RainbowMango
Copy link
Member

Fine, no rush.

Signed-off-by: dddddai <dddwq@foxmail.com>
@dddddai
Copy link
Member Author

dddddai commented Sep 29, 2021

@RainbowMango @XiShanYongYe-Chang Thanks for elaborating, conflict is resolved, PTAL

@dddddai dddddai marked this pull request as ready for review September 29, 2021 03:43
@karmada-bot karmada-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 29, 2021
@RainbowMango RainbowMango added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 29, 2021
@karmada-bot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@XiShanYongYe-Chang
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2021
@karmada-bot karmada-bot merged commit 5be78ba into karmada-io:master Sep 29, 2021
@dddddai dddddai deleted the add-finalizer branch October 8, 2021 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. 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.

work will not be deleted under some circumstances
5 participants