From 0d21a5ebf47d00e9fa8d736e3ab13e04e77830bb Mon Sep 17 00:00:00 2001 From: changzhen Date: Sat, 13 Jul 2024 15:05:28 +0800 Subject: [PATCH] Fix the issue of residual work in the MultiClusterService feature. Signed-off-by: changzhen --- .../endpointslice_collect_controller.go | 1 + .../endpointslice_dispatch_controller.go | 8 -------- pkg/util/helper/work.go | 1 + 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/controllers/multiclusterservice/endpointslice_collect_controller.go b/pkg/controllers/multiclusterservice/endpointslice_collect_controller.go index 2229944c1056..c7cfbbbc2bc9 100644 --- a/pkg/controllers/multiclusterservice/endpointslice_collect_controller.go +++ b/pkg/controllers/multiclusterservice/endpointslice_collect_controller.go @@ -439,6 +439,7 @@ func reportEndpointSlice(c client.Client, endpointSlice *unstructured.Unstructur util.PropagationInstruction: util.PropagationInstructionSuppressed, util.ManagedByKarmadaLabel: util.ManagedByKarmadaLabelValue, }, + Finalizers: []string{util.MCSEndpointSliceDispatchControllerFinalizer}, } if err := helper.CreateOrUpdateWork(c, workMeta, endpointSlice); err != nil { diff --git a/pkg/controllers/multiclusterservice/endpointslice_dispatch_controller.go b/pkg/controllers/multiclusterservice/endpointslice_dispatch_controller.go index 259040f1e56b..a008d4427326 100644 --- a/pkg/controllers/multiclusterservice/endpointslice_dispatch_controller.go +++ b/pkg/controllers/multiclusterservice/endpointslice_dispatch_controller.go @@ -327,14 +327,6 @@ func (c *EndpointsliceDispatchController) syncEndpointSlice(ctx context.Context, return err } } - - if controllerutil.AddFinalizer(work, util.MCSEndpointSliceDispatchControllerFinalizer) { - if err := c.Client.Update(ctx, work); err != nil { - klog.Errorf("Failed to add finalizer %s for work %s/%s:%v", util.MCSEndpointSliceDispatchControllerFinalizer, work.Namespace, work.Name, err) - return err - } - } - return nil } diff --git a/pkg/util/helper/work.go b/pkg/util/helper/work.go index 9af79a4ceaf8..2cb59634ce97 100644 --- a/pkg/util/helper/work.go +++ b/pkg/util/helper/work.go @@ -85,6 +85,7 @@ func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resour if util.GetLabelValue(runtimeObject.Labels, workv1alpha2.WorkPermanentIDLabel) == "" { runtimeObject.Labels = util.DedupeAndMergeLabels(runtimeObject.Labels, map[string]string{workv1alpha2.WorkPermanentIDLabel: uuid.New().String()}) } + runtimeObject.Finalizers = work.Finalizers return nil }) if err != nil {