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

🐛 remove klusterlet finalizer forcely #214

Conversation

zhujian7
Copy link
Member

@zhujian7 zhujian7 commented Jul 6, 2023

Summary

Now when we delete a klusterlet CR, the klusterlet-operator will remove the klusterlet.spec.namespace namespace, before removing the finalize operator.open-cluster-management.io/klusterlet-cleanup for the klusterlet CR.
so there is a case, if the klusterlet-operator is running in the klusterlet.spec.namespace namespace, removing the namespace will trigger deleting the klusterlet-operator itself, and if the klusterlet-operator is deleted before the finalize is removed(eg, remove finalize got conflict), the klusterlet will be left and can not be deleted automatically.

this PR is trying to resolve the conflict error when removing the finalizer.

BTW, this PR will fix the warning log:

W0710 06:36:59.764545       1 warnings.go:70] unknown field "metadata.UID"

Related issue(s)

Fixes #

@openshift-ci openshift-ci bot requested review from jnpacker and mikeshng July 6, 2023 15:00
@zhujian7 zhujian7 force-pushed the remove-finalizer-conflict branch from 38a705d to b4298c3 Compare July 6, 2023 15:24
@zhujian7 zhujian7 changed the title WIP: 🐛 retry when getting a conflict error for removing finalizer 🌱 retry when getting a conflict error for removing finalizer Jul 6, 2023
@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Patch coverage: 82.85% and project coverage change: +0.08 🎉

Comparison is base (6649834) 60.18% compared to head (27e126c) 60.26%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
+ Coverage   60.18%   60.26%   +0.08%     
==========================================
  Files         128      128              
  Lines       13373    13411      +38     
==========================================
+ Hits         8048     8082      +34     
- Misses       4581     4584       +3     
- Partials      744      745       +1     
Flag Coverage Δ
unit 60.26% <82.85%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...sterletcontroller/klusterlet_cleanup_controller.go 54.40% <0.00%> (-0.29%) ⬇️
...usterletcontroller/klusterlet_managed_reconcile.go 52.88% <50.00%> (ø)
pkg/common/patcher/patcher.go 76.00% <86.36%> (+3.60%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@zhujian7 zhujian7 force-pushed the remove-finalizer-conflict branch from b4298c3 to 39e21d3 Compare July 6, 2023 15:51
@@ -131,6 +140,16 @@ func (p *patcher[R, Sp, St]) RemoveFinalizer(ctx context.Context, object R, fina
if errors.IsNotFound(err) {
return nil
}

// If it's a conflict, we need to get the latest version of the object and try again.
if errors.IsConflict(err) {
Copy link
Member

@qiujian16 qiujian16 Jul 7, 2023

Choose a reason for hiding this comment

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

it seems too greedy, you have to set a backoff time.

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 setting a backoff time will make the retry slow, which is not good for deleting the klusterlet CR.
can we set a retry times(eg.3 times) into the ctx, and if it exceeds, we stop?

@zhujian7 zhujian7 force-pushed the remove-finalizer-conflict branch from 39e21d3 to 509b231 Compare July 10, 2023 05:56
@zhujian7 zhujian7 changed the title 🌱 retry when getting a conflict error for removing finalizer 🐛: remove klusterlet finalizer forcely Jul 10, 2023
@zhujian7 zhujian7 changed the title 🐛: remove klusterlet finalizer forcely 🐛 remove klusterlet finalizer forcely Jul 10, 2023
@zhujian7 zhujian7 force-pushed the remove-finalizer-conflict branch from 509b231 to 70523cd Compare July 10, 2023 06:35
@zhujian7
Copy link
Member Author

@qiujian16 PTAL

@@ -25,6 +25,8 @@ type PatchClient[R runtime.Object] interface {
type Patcher[R runtime.Object, Sp any, St any] interface {
AddFinalizer(context.Context, R, ...string) (bool, error)
RemoveFinalizer(context.Context, R, ...string) error
Copy link
Member

Choose a reason for hiding this comment

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

actually, could we add opts var in the RemoveFinalizer func

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean the patch option for the p.client.Patch(ctx, accessor.GetName(), types.MergePatchType, patchBytes, metav1.PatchOptions{})

we will not set force to true for the patch option, it is used for re-acquire conflicting fields owned by other people.
in our case, we just need to keep the resourceVersion empty.

Copy link
Member

Choose a reason for hiding this comment

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

not necessary to be a mevat.PatchOptions, but a options field that you can know whether it is force patch or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

added a PatchOptions param for the RemoveFinalizers func.

@@ -191,7 +191,7 @@ func (n *klusterletCleanupController) sync(ctx context.Context, controllerContex
return utilerrors.NewAggregate(errs)
}

return n.patcher.RemoveFinalizerForcely(ctx, klusterlet, klusterletFinalizer, klusterletHostedFinalizer)
return n.patcher.RemoveFinalizer(ctx, klusterlet, patcher.PatchOptions{IgnoreResourceVersion: true}, klusterletFinalizer, klusterletHostedFinalizer)
Copy link
Member

Choose a reason for hiding this comment

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

will it be better if it is like

n.patcher.WithOptions(opts).RemoveFinalizer? ....

Copy link
Member Author

@zhujian7 zhujian7 Jul 10, 2023

Choose a reason for hiding this comment

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

Do you mean to make it work for all funcs? not only for RemoveFinalizers?

Copy link
Member

Choose a reason for hiding this comment

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

yes, I think so

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

zhujian7 added 3 commits July 11, 2023 02:34
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7 zhujian7 force-pushed the remove-finalizer-conflict branch from c8f9215 to 27e126c Compare July 11, 2023 02:53
@zhujian7
Copy link
Member Author

@qiujian16 PTAL

@qiujian16
Copy link
Member

/approve
/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, zhujian7

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

@openshift-merge-robot openshift-merge-robot merged commit 5db2240 into open-cluster-management-io:main Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants