Skip to content

Commit a2980eb

Browse files
authored
Merge pull request #6434 from XiShanYongYe-Chang/fix-6433
Ensure EndpointSlice informer cache is synced before reporting EndpointSlice
2 parents db76ef0 + b0560d6 commit a2980eb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/controllers/mcs/service_export_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ func (c *ServiceExportController) reportEndpointSliceWithServiceExportCreate(ctx
408408
return nil
409409
}
410410

411+
// Before retrieving EndpointSlice objects from the informer, ensure the informer cache is synced.
412+
// This is necessary because the informer for EndpointSlice is created dynamically in the Reconcile() routine
413+
// when a Work resource containing an ServiceExport is detected for the cluster. If the informer is not yet synced,
414+
// return an error and wait a retry at the next time.
415+
if !singleClusterManager.IsInformerSynced(endpointSliceGVR) {
416+
return fmt.Errorf("the informer for cluster %s has not been synced, wait a retry at the next time", serviceExportKey.Cluster)
417+
}
418+
411419
endpointSliceLister := singleClusterManager.Lister(endpointSliceGVR)
412420
if endpointSliceObjects, err = endpointSliceLister.ByNamespace(serviceExportKey.Namespace).List(labels.SelectorFromSet(labels.Set{
413421
discoveryv1.LabelServiceName: serviceExportKey.Name,
@@ -483,6 +491,14 @@ func (c *ServiceExportController) reportEndpointSliceWithEndpointSliceCreateOrUp
483491
return nil
484492
}
485493

494+
// Before retrieving ServiceExport objects from the informer, ensure the informer cache is synced.
495+
// This is necessary because the informer for ServiceExport is created dynamically in the Reconcile() routine
496+
// when a Work resource containing an ServiceExport is detected for the cluster. If the informer is not yet synced,
497+
// return an error and wait a retry at the next time.
498+
if !singleClusterManager.IsInformerSynced(serviceExportGVR) {
499+
return fmt.Errorf("the informer for cluster %s has not been synced, wait a retry at the next time", clusterName)
500+
}
501+
486502
serviceExportLister := singleClusterManager.Lister(serviceExportGVR)
487503
_, err := serviceExportLister.ByNamespace(endpointSlice.GetNamespace()).Get(relatedServiceName)
488504
if err != nil {
@@ -614,13 +630,15 @@ func cleanEndpointSliceWork(ctx context.Context, c client.Client, work *workv1al
614630
klog.Errorf("Failed to update work(%s/%s): %v", work.Namespace, work.Name, err)
615631
return err
616632
}
633+
klog.Infof("Successfully updated work(%s/%s)", work.Namespace, work.Name)
617634
return nil
618635
}
619636

620637
if err := c.Delete(ctx, work); err != nil {
621638
klog.Errorf("Failed to delete work(%s/%s), Error: %v", work.Namespace, work.Name, err)
622639
return err
623640
}
641+
klog.Infof("Successfully deleted work(%s/%s)", work.Namespace, work.Name)
624642

625643
return nil
626644
}

0 commit comments

Comments
 (0)