@@ -408,6 +408,14 @@ func (c *ServiceExportController) reportEndpointSliceWithServiceExportCreate(ctx
408
408
return nil
409
409
}
410
410
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
+
411
419
endpointSliceLister := singleClusterManager .Lister (endpointSliceGVR )
412
420
if endpointSliceObjects , err = endpointSliceLister .ByNamespace (serviceExportKey .Namespace ).List (labels .SelectorFromSet (labels.Set {
413
421
discoveryv1 .LabelServiceName : serviceExportKey .Name ,
@@ -483,6 +491,14 @@ func (c *ServiceExportController) reportEndpointSliceWithEndpointSliceCreateOrUp
483
491
return nil
484
492
}
485
493
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
+
486
502
serviceExportLister := singleClusterManager .Lister (serviceExportGVR )
487
503
_ , err := serviceExportLister .ByNamespace (endpointSlice .GetNamespace ()).Get (relatedServiceName )
488
504
if err != nil {
@@ -614,13 +630,15 @@ func cleanEndpointSliceWork(ctx context.Context, c client.Client, work *workv1al
614
630
klog .Errorf ("Failed to update work(%s/%s): %v" , work .Namespace , work .Name , err )
615
631
return err
616
632
}
633
+ klog .Infof ("Successfully updated work(%s/%s)" , work .Namespace , work .Name )
617
634
return nil
618
635
}
619
636
620
637
if err := c .Delete (ctx , work ); err != nil {
621
638
klog .Errorf ("Failed to delete work(%s/%s), Error: %v" , work .Namespace , work .Name , err )
622
639
return err
623
640
}
641
+ klog .Infof ("Successfully deleted work(%s/%s)" , work .Namespace , work .Name )
624
642
625
643
return nil
626
644
}
0 commit comments