diff --git a/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_endpointslice_controller.go b/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_endpointslice_controller.go index f183b382c..fc7fe6768 100644 --- a/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_endpointslice_controller.go +++ b/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_endpointslice_controller.go @@ -181,7 +181,7 @@ func (c *SimpleSyncEPSController) createNamespace(client client.Client, namespac // nolint:dupl func (c *SimpleSyncEPSController) cleanUpEpsInLeafCluster(namespace string, name string) error { - clusters := c.GlobalLeafManager.ListClusters() + clusters := c.GlobalLeafClientManager.ListActualClusters() var errs []string for _, cluster := range clusters { leafClient, err := c.GlobalLeafManager.GetLeafResource(cluster) diff --git a/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_service_controller.go b/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_service_controller.go index 9e14017f4..17fad2f5f 100644 --- a/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_service_controller.go +++ b/pkg/clustertree/cluster-manager/controllers/svc/simple_sync_service_controller.go @@ -192,7 +192,7 @@ func (c *SimpleSyncServiceController) cleanUpServiceInLeafCluster(namespace stri } func (c *SimpleSyncServiceController) syncServiceInLeafCluster(service *corev1.Service) error { - clusters := c.GlobalLeafManager.ListClusters() + clusters := c.GlobalLeafClientManager.ListActualClusters() errsChan := make(chan string, len(clusters)) var wg sync.WaitGroup for _, cluster := range clusters { diff --git a/pkg/clustertree/cluster-manager/utils/leaf_client_resource_manager.go b/pkg/clustertree/cluster-manager/utils/leaf_client_resource_manager.go index 3fe5cdc09..16da61706 100644 --- a/pkg/clustertree/cluster-manager/utils/leaf_client_resource_manager.go +++ b/pkg/clustertree/cluster-manager/utils/leaf_client_resource_manager.go @@ -33,6 +33,8 @@ type LeafClientResourceManager interface { RemoveLeafClientResource(actualClusterName string) GetLeafResource(actualClusterName string) (*LeafClientResource, error) + + ListActualClusters() []string } type leafClientResourceManager struct { @@ -63,6 +65,21 @@ func (cr *leafClientResourceManager) AddLeafClientResource(lcr *LeafClientResour } } +func (cr *leafClientResourceManager) ListActualClusters() []string { + cr.leafClientResourceManagersLock.Lock() + defer cr.leafClientResourceManagersLock.Unlock() + + keys := make([]string, 0) + for k := range cr.clientResourceMap { + if len(k) == 0 { + continue + } + + keys = append(keys, k) + } + return keys +} + func (cr *leafClientResourceManager) RemoveLeafClientResource(actualClusterName string) { cr.leafClientResourceManagersLock.Lock() defer cr.leafClientResourceManagersLock.Unlock()