Merge pull request #5188 from XiShanYongYe-Chang/fix-residual-work-in-mcs

Fix the issue of residual work in the MultiClusterService feature.
This commit is contained in:
karmada-bot 2024-07-17 11:09:10 +08:00 committed by GitHub
commit a5070c758b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 11 deletions

View File

@ -421,8 +421,12 @@ func getEndpointSliceWorkMeta(c client.Client, ns string, workName string, endpo
controllerSet.Insert(util.MultiClusterServiceKind)
ls[util.EndpointSliceWorkManagedByLabel] = strings.Join(controllerSet.UnsortedList(), ".")
}
workMeta := metav1.ObjectMeta{Name: workName, Namespace: ns, Labels: ls}
return workMeta, nil
return metav1.ObjectMeta{
Name: workName,
Namespace: ns,
Labels: ls,
Finalizers: []string{util.MCSEndpointSliceDispatchControllerFinalizer},
}, nil
}
func cleanupWorkWithEndpointSliceDelete(c client.Client, endpointSliceKey keys.FederatedKey) error {

View File

@ -301,7 +301,7 @@ func (c *EndpointsliceDispatchController) cleanOrphanDispatchedEndpointSlice(ctx
return nil
}
func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Context, work *workv1alpha1.Work, mcs *networkingv1alpha1.MultiClusterService) error {
func (c *EndpointsliceDispatchController) dispatchEndpointSlice(_ context.Context, work *workv1alpha1.Work, mcs *networkingv1alpha1.MultiClusterService) error {
epsSourceCluster, err := names.GetClusterName(work.Namespace)
if err != nil {
klog.Errorf("Failed to get EndpointSlice source cluster name for work %s/%s", work.Namespace, work.Name)
@ -340,14 +340,6 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
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
}

View File

@ -84,6 +84,7 @@ func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resour
runtimeObject.Spec = work.Spec
runtimeObject.Labels = util.DedupeAndMergeLabels(runtimeObject.Labels, work.Labels)
runtimeObject.Annotations = util.DedupeAndMergeAnnotations(runtimeObject.Annotations, work.Annotations)
runtimeObject.Finalizers = work.Finalizers
return nil
})
return err