Skip to content

Commit

Permalink
Merge pull request #266 from duanmengkk/fix_clustername_bug
Browse files Browse the repository at this point in the history
fix: fix the clusterName in leafResourceManger not consistent
  • Loading branch information
kosmos-robot authored Nov 20, 2023
2 parents 40187c7 + e9109a4 commit f251e4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
10 changes: 1 addition & 9 deletions pkg/clustertree/cluster-manager/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,7 @@ func (c *ClusterController) clearClusterControllers(cluster *kosmosv1alpha1.Clus
}

func (c *ClusterController) setupControllers(mgr manager.Manager, cluster *kosmosv1alpha1.Cluster, nodes []*corev1.Node, clientDynamic *dynamic.DynamicClient, leafClientset kubernetes.Interface, kosmosClient kosmosversioned.Interface, leafRestConfig *rest.Config) error {
isNode2NodeFunc := func(cluster *kosmosv1alpha1.Cluster) bool {
return cluster.Spec.ClusterTreeOptions.LeafModels != nil
}

clusterName := fmt.Sprintf("%s%s", utils.KosmosNodePrefix, cluster.Name)
if isNode2NodeFunc(cluster) {
clusterName = cluster.Name
}

clusterName := c.LeafModelHandler.GetGlobalLeafManagerClusterName(cluster)
c.GlobalLeafManager.AddLeafResource(clusterName, &leafUtils.LeafResource{
Client: mgr.GetClient(),
DynamicClient: clientDynamic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ func (c *AutoCreateMCSController) cleanUpMcsResources(ctx context.Context, names
continue
}

leafManager, err := c.GlobalLeafManager.GetLeafResource(cluster.Name)
clusterName := clustertreeutils.GetLeafResourceClusterName(newCluster)
leafManager, err := c.GlobalLeafManager.GetLeafResource(clusterName)
if err != nil {
klog.Errorf("get leafManager for cluster %s failed,Error: %v", cluster.Name, err)
klog.Errorf("get leafManager for cluster %s failed,Error: %v", clusterName, err)
return err
}
if err = leafManager.KosmosClient.MulticlusterV1alpha1().ServiceImports(namespace).Delete(ctx, name, metav1.DeleteOptions{}); err != nil {
Expand Down Expand Up @@ -212,9 +213,10 @@ func (c *AutoCreateMCSController) autoCreateMcsResources(ctx context.Context, se
continue
}

leafManager, err := c.GlobalLeafManager.GetLeafResource(cluster.Name)
clusterName := clustertreeutils.GetLeafResourceClusterName(newCluster)
leafManager, err := c.GlobalLeafManager.GetLeafResource(clusterName)
if err != nil {
klog.Errorf("get leafManager for cluster %s failed,Error: %v", cluster.Name, err)
klog.Errorf("get leafManager for cluster %s failed,Error: %v", clusterName, err)
return err
}
serviceImport := &mcsv1alpha1.ServiceImport{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

kosmosv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
kosmosversioned "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned"
"github.com/kosmos.io/kosmos/pkg/utils"
)

var (
Expand Down Expand Up @@ -64,6 +65,13 @@ type leafResourceManager struct {
leafResourceManagersLock sync.Mutex
}

func GetLeafResourceClusterName(cluster *kosmosv1alpha1.Cluster) string {
if cluster.Spec.ClusterTreeOptions.LeafModels != nil {
return cluster.Name
}
return fmt.Sprintf("%s%s", utils.KosmosNodePrefix, cluster.Name)
}

func has(clusternodes []ClusterNode, target string) bool {
for _, v := range clusternodes {
if v.NodeName == target {
Expand Down

0 comments on commit f251e4d

Please sign in to comment.