Skip to content

Commit

Permalink
fix(sync): use cluster client if cache not sync
Browse files Browse the repository at this point in the history
  • Loading branch information
JackZxj committed Aug 9, 2023
1 parent 7ede6f4 commit 44e388e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pkg/controllers/sync/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,15 @@ func (s *SyncController) syncToClusters(ctx context.Context, fedResource Federat
{
// TODO: updating the sync status may thrash the host apiserver if the host caches are synced but member caches are not synced.
// Find out if this is ok.
lister, hasSynced, exists := s.fedInformerManager.GetResourceLister(fedResource.TargetGVK(), clusterName)
if !exists || !hasSynced() {
shouldRecheckAfterDispatch = true
wrappedErr := fmt.Errorf("cluster cache is not synced")
dispatcher.RecordClusterError(fedcorev1a1.CachedRetrievalFailed, clusterName, wrappedErr)
continue
}

clusterObjAny, err := lister.Get(fedResource.TargetName().String())
if err == nil {
clusterObj = clusterObjAny.(*unstructured.Unstructured)
} else if !apierrors.IsNotFound(err) {
clusterObj, _, err = informermanager.GetClusterObject(
ctx,
s.ftcManager,
s.fedInformerManager,
clusterName,
fedResource.TargetName(),
fedResource.TargetGVK(),
)
if err != nil {
wrappedErr := fmt.Errorf("failed to get cluster object: %w", err)
dispatcher.RecordClusterError(fedcorev1a1.CachedRetrievalFailed, clusterName, wrappedErr)
continue
Expand Down

0 comments on commit 44e388e

Please sign in to comment.