Skip to content

Commit

Permalink
Merge pull request #682 from duanmengkk/feature_fix_svc
Browse files Browse the repository at this point in the history
cherry-pick: fix bug for create svc twice
  • Loading branch information
duanmengkk authored Aug 13, 2024
2 parents 1057f30 + f8c6727 commit cad7365
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 cad7365

Please sign in to comment.