Skip to content

Commit

Permalink
fix bug for create svc twice
Browse files Browse the repository at this point in the history
Signed-off-by: duanmengkk <[email protected]>
  • Loading branch information
duanmengkk committed Aug 12, 2024
1 parent 43b2f5a commit 29d7e1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type LeafClientResourceManager interface {
RemoveLeafClientResource(actualClusterName string)

GetLeafResource(actualClusterName string) (*LeafClientResource, error)

ListActualClusters() []string
}

type leafClientResourceManager struct {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 29d7e1d

Please sign in to comment.