@@ -56,7 +56,8 @@ type resourceSynchro struct {
56
56
storage storage.ResourceStorage
57
57
convertor runtime.ObjectConvertor
58
58
59
- status atomic.Value // clusterv1alpha2.ClusterResourceSyncCondition
59
+ status atomic.Value // clusterv1alpha2.ClusterResourceSyncCondition
60
+ initialListPhase atomic.Bool // If other phases are added, it can be changed to a more general field.
60
61
61
62
startlock sync.Mutex
62
63
stopped chan struct {}
@@ -312,12 +313,18 @@ func (synchro *resourceSynchro) Start(stopCh <-chan struct{}) {
312
313
}
313
314
314
315
i := informer .NewResourceVersionInformer (synchro .cluster , config )
315
- if synchro .eventSynchro != nil {
316
- go func () {
317
- cache .WaitForCacheSync (informerStopCh , i .HasSynced , func () bool { return ! synchro .queue .HasInitialEvent () })
316
+ go func () {
317
+ synchro .initialListPhase .Store (true )
318
+ if ! cache .WaitForCacheSync (informerStopCh , i .HasSynced , func () bool { return ! synchro .queue .HasInitialEvent () }) {
319
+ synchro .initialListPhase .Store (false )
320
+ return
321
+ }
322
+ synchro .initialListPhase .Store (false )
323
+
324
+ if synchro .eventSynchro != nil {
318
325
synchro .eventSynchro .Start (informerStopCh )
319
- }()
320
- }
326
+ }
327
+ }()
321
328
i .Run (informerStopCh )
322
329
323
330
// TODO(Iceber): Optimize status updates in case of storage exceptions
@@ -624,7 +631,12 @@ func (synchro *resourceSynchro) setStatus(status string, reason, message string)
624
631
}
625
632
626
633
func (synchro * resourceSynchro ) Status () clusterv1alpha2.ClusterResourceSyncCondition {
627
- return synchro .status .Load ().(clusterv1alpha2.ClusterResourceSyncCondition )
634
+ s := synchro .status .Load ().(clusterv1alpha2.ClusterResourceSyncCondition )
635
+ switch s .Status {
636
+ case clusterv1alpha2 .ResourceSyncStatusPending , clusterv1alpha2 .ResourceSyncStatusSyncing :
637
+ s .InitialListPhase = synchro .initialListPhase .Load ()
638
+ }
639
+ return s
628
640
}
629
641
630
642
func (synchro * resourceSynchro ) ErrorHandler (r * informer.Reflector , err error ) {
@@ -638,7 +650,8 @@ func (synchro *resourceSynchro) ErrorHandler(r *informer.Reflector, err error) {
638
650
// `reflector` sets a default timeout when watching,
639
651
// then when re-watching the error handler is called again and the `err` is nil.
640
652
// if the current status is Syncing, then the status is not updated to avoid triggering a cluster status update
641
- if status := synchro .Status (); status .Status != clusterv1alpha2 .ResourceSyncStatusSyncing {
653
+ status := synchro .status .Load ().(clusterv1alpha2.ClusterResourceSyncCondition )
654
+ if status .Status != clusterv1alpha2 .ResourceSyncStatusSyncing {
642
655
synchro .setStatus (clusterv1alpha2 .ResourceSyncStatusSyncing , "" , "" )
643
656
}
644
657
}
0 commit comments