Skip to content

Commit

Permalink
Merge pull request kosmos-io#681 from duanmengkk/feature_0.4.0_fix
Browse files Browse the repository at this point in the history
fix bug for create svc twice
  • Loading branch information
duanmengkk committed Aug 13, 2024
2 parents 43b2f5a + 29d7e1d commit d84e895
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 d84e895

Please sign in to comment.