-
Notifications
You must be signed in to change notification settings - Fork 94
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
🐛 remove klusterlet finalizer forcely #214
Conversation
38a705d
to
b4298c3
Compare
Codecov ReportPatch coverage:
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
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
b4298c3
to
39e21d3
Compare
pkg/common/patcher/patcher.go
Outdated
@@ -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) { |
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 seems too greedy, you have to set a backoff time.
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 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?
39e21d3
to
509b231
Compare
509b231
to
70523cd
Compare
@qiujian16 PTAL |
pkg/common/patcher/patcher.go
Outdated
@@ -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 |
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.
actually, could we add opts var in the RemoveFinalizer func
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.
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.
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.
not necessary to be a mevat.PatchOptions, but a options field that you can know whether it is force patch or not.
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.
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) |
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.
will it be better if it is like
n.patcher.WithOptions(opts).RemoveFinalizer? ....
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.
Do you mean to make it work for all funcs? not only for RemoveFinalizers?
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.
yes, I think so
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.
fixed
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
c8f9215
to
27e126c
Compare
@qiujian16 PTAL |
/approve |
[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 |
Summary
Now when we delete a klusterlet CR, the klusterlet-operator will remove the
klusterlet.spec.namespace
namespace, before removing the finalizeoperator.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:
Related issue(s)
Fixes #