Skip to content

Commit 1c72dab

Browse files
committed
clustersynchro: add initial list phase
Signed-off-by: Iceber Gu <[email protected]>
1 parent 3140889 commit 1c72dab

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

kustomize/crds/cluster.clusterpedia.io_pediaclusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ spec:
249249
syncConditions:
250250
items:
251251
properties:
252+
initialListPhase:
253+
description: optional
254+
type: boolean
252255
lastTransitionTime:
253256
format: date-time
254257
type: string

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/synchromanager/clustersynchro/default_resource_synchro.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ type resourceSynchro struct {
5656
storage storage.ResourceStorage
5757
convertor runtime.ObjectConvertor
5858

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.
6061

6162
startlock sync.Mutex
6263
stopped chan struct{}
@@ -312,12 +313,18 @@ func (synchro *resourceSynchro) Start(stopCh <-chan struct{}) {
312313
}
313314

314315
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 {
318325
synchro.eventSynchro.Start(informerStopCh)
319-
}()
320-
}
326+
}
327+
}()
321328
i.Run(informerStopCh)
322329

323330
// TODO(Iceber): Optimize status updates in case of storage exceptions
@@ -624,7 +631,12 @@ func (synchro *resourceSynchro) setStatus(status string, reason, message string)
624631
}
625632

626633
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
628640
}
629641

630642
func (synchro *resourceSynchro) ErrorHandler(r *informer.Reflector, err error) {
@@ -638,7 +650,8 @@ func (synchro *resourceSynchro) ErrorHandler(r *informer.Reflector, err error) {
638650
// `reflector` sets a default timeout when watching,
639651
// then when re-watching the error handler is called again and the `err` is nil.
640652
// 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 {
642655
synchro.setStatus(clusterv1alpha2.ResourceSyncStatusSyncing, "", "")
643656
}
644657
}

staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ type ClusterResourceSyncCondition struct {
215215
// optional
216216
Message string `json:"message,omitempty"`
217217

218+
// optional
219+
InitialListPhase bool `json:"initialListPhase,omitempty"`
220+
218221
// +required
219222
// +kubebuilder:validation:Required
220223
// +kubebuilder:validation:Type=string

0 commit comments

Comments
 (0)