-
Notifications
You must be signed in to change notification settings - Fork 369
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
Update finalizer of ResourceExport to be domain-qualified #6742
Conversation
multicluster/apis/multicluster/v1alpha1/resourceexport_webhook.go
Outdated
Show resolved
Hide resolved
// Note for ResourceExports created before Antrea v2.2, LegacyResourceExportFinalizer may still be present | ||
// and needs to be removed before a ResourceExport is deleted. | ||
if r.DeletionTimestamp.IsZero() && !stringExistsInSlice(r.Finalizers, constants.DomainQualifiedResourceExportFinalizer) { | ||
r.Finalizers = append(r.Finalizers, constants.DomainQualifiedResourceExportFinalizer) |
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.
Obviously this predates this PR, but I am surprised to see a webhook being in charge of adding the finalizer. Is there a recommendation to do that somewhere? I usually see it done in the controller itself (Reconcile
). cc @luolanzone
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.
Hi @antoninbas I think the Finalizer is not necessarily handled by the reconciler. If I recall it correctly, the main purpose is to stop deleting the ResourceExport during creation, because if it's already converted by the leader controller into ResourceImport, there will be no way to clean up the corresponding info in the ResourceImport when the ResourceExport is deleted by the user.
@@ -101,7 +101,7 @@ func (r *ResourceExportReconciler) Reconcile(ctx context.Context, req ctrl.Reque | |||
// clean up any replicated resources like ResourceImport. | |||
// For more details about using Finalizers, please refer to https://book.kubebuilder.io/reference/using-finalizers.html. | |||
if !resExport.DeletionTimestamp.IsZero() { | |||
if common.StringExistsInSlice(resExport.Finalizers, constants.ResourceExportFinalizer) { | |||
if common.AnyExistsInSlice(resExport.Finalizers, []string{constants.LegacyResourceExportFinalizer, constants.DomainQualifiedResourceExportFinalizer}) { |
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 am not sure, but would it make sense to update the finalizer as part of the Reconcile
(we could do it earlier in the function), so that:
- the legacy finalizer can be updated to the new one whenever an object is reconciled, reducing the possibility of the legacy finalizer "sticking around"
- the rest of the code only needs to worry about the new finalizer
cc @luolanzone
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.
@antoninbas do you mean to update the Finalizer to the new one in the reconcile? I think we can't guarantee the Finalizer can be updated for all ResourceExports before deletion, we still need to handle the case that both legacy and new one are in the ClusterSet. And this may lead a conflict that one reconciler is updating the Finalizer but another one is deleting it. So I feel we should have only one place to add the Finalizer.
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.
finalizers are usually handled by the controller that owns the resource (that includes adding the finalizer but also processing the finalizer and removing the finalizer), so I am not sure I understand both of your points:
I think we can't guarantee the Finalizer can be updated for all ResourceExports before deletion
And this may lead a conflict that one reconciler is updating the Finalizer but another one is deleting it
Do we have more than one controller / reconciler responsible for the finalizer, or using the finalizer?
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 we have more than one controller / reconciler responsible for the finalizer, or using the finalizer?
I'll try to put my understanding of it here as best as I can, using Service as example:
- End users can create a
ServiceExport
in member clusters. A controller in member cluster [a] will try to create aResourceExport
for this object in the leader cluster. This is currently when a finalizer is put on the resource. - End users can also delete that
ServiceExport
in member cluster. That controller [a] is also responsible for deleting theResourceExport
in the leader cluster. - A controller [b] in the leader cluster watches for
ResourceExports
in its own cluster, and reconciles them (by creating correspondingResourceImports
). When it sees anResourceExport
being deleted, it performs necessary cleanups regardingResourceImports
, and then removes the finalizers onResourceExport
and allows it to be deleted.
So if we treat controller [a] solely as a client, not a controller/reconciler, then it's pretty clear that controller [b] actually "owns" ResourceExports
. I think @antoninbas's suggestion would actually make sense here:
- If we have controller [b] put up finalizers for
ResourceExports
at the beginning of Reconciles (and making sure the finalizer is set before dealing with ResourceImport logics), then allowing client [a] to create-deleteResourceExports
in short succession is actually fine: the leader cluster has not even processed the event yet, so there will not be danglingResourceImports
that contains information of that deletedResourceExport
. - Even if there are
ResourceImports
in the leader cluster for the same named Service, it will only contain endpoints fromResourceExport
created by another member cluster, which would actually have finalizers on it.
In other words, we change the logic to, we add a finalizer to ResourceExports
only when we know there are going to be side-effects in the leader cluster, not when the resource is created at apiserver
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.
However @antoninbas do you think this change warrants a separate PR?
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.
finalizers are usually handled by the controller that owns the resource (that includes adding the finalizer but also processing the finalizer and removing the finalizer), so I am not sure I understand both of your points:
I think we can't guarantee the Finalizer can be updated for all ResourceExports before deletion
And this may lead a conflict that one reconciler is updating the Finalizer but another one is deleting it
Do we have more than one controller / reconciler responsible for the finalizer, or using the finalizer?
At the moment, we have the webhook in the leader and the *Exporter controllers in the member cluster to add the Finalizer during ResourceExport creation, the reconciler itself in the leader will remove the Finalizer. The Finalizer in the webhook is a special one for AntreaClusterNetworkPolicyKind since it will be created by the end user if I recall it correctly. The original purpose is to stop the side-affect when the user or "the controller [a]" in the scenario mentioned by @Dyanngg delete the ResourceExport and leads to some dangling ResourceImports.
But you are right, it should be more clear if we can move all Finalizer operations to the leader controller, @Dyanngg could you help to double check and move forward? I think we may need a seperate PR for the change. Thanks.
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, we can handle this in a future PR
2afa3f2
to
d862b03
Compare
/test-multicluster-e2e |
1 similar comment
/test-multicluster-e2e |
/test-multicluster-e2e |
1 similar comment
/test-multicluster-e2e |
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.
LGTM
multicluster/controllers/multicluster/leader/clusterinfo_export_handler.go
Outdated
Show resolved
Hide resolved
multicluster/controllers/multicluster/leader/resourceexport_controller.go
Outdated
Show resolved
Hide resolved
multicluster/controllers/multicluster/leader/resourceexport_controller_test.go
Outdated
Show resolved
Hide resolved
multicluster/controllers/multicluster/leader/resourceexport_controller_test.go
Show resolved
Hide resolved
multicluster/controllers/multicluster/leader/resourceexport_controller_test.go
Outdated
Show resolved
Hide resolved
multicluster/controllers/multicluster/leader/resourceexport_controller_test.go
Outdated
Show resolved
Hide resolved
d862b03
to
c4553ac
Compare
/test-all /test-multicluster-e2e |
c4553ac
to
900204d
Compare
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.
LGTM
/test-all /test-multicluster-e2e |
/test-multicluster-e2e |
multicluster/controllers/multicluster/leader/resourceexport_controller.go
Show resolved
Hide resolved
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.
LGTM
Fixes antrea-io#6741 Signed-off-by: Dyanngg <[email protected]>
900204d
to
2b93818
Compare
/test-multicluster-e2e All tests were passing before addressing the last comment |
We should probably mention this in the release notes, so I'm adding the label for this |
Fixes #6741