diff --git a/pkg/clustertree/cluster-manager/cluster_controller.go b/pkg/clustertree/cluster-manager/cluster_controller.go index 5fca8739b..8ac854ed1 100644 --- a/pkg/clustertree/cluster-manager/cluster_controller.go +++ b/pkg/clustertree/cluster-manager/cluster_controller.go @@ -231,7 +231,15 @@ func (c *ClusterController) clearClusterControllers(cluster *kosmosv1alpha1.Clus } func (c *ClusterController) setupControllers(mgr manager.Manager, cluster *kosmosv1alpha1.Cluster, nodes []*corev1.Node, clientDynamic *dynamic.DynamicClient, leafClient kubernetes.Interface, kosmosClient kosmosversioned.Interface) 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 + } + c.GlobalLeafManager.AddLeafResource(clusterName, &leafUtils.LeafResource{ Client: mgr.GetClient(), DynamicClient: clientDynamic, @@ -244,10 +252,6 @@ func (c *ClusterController) setupControllers(mgr manager.Manager, cluster *kosmo EnableServiceAccount: true, }, cluster.Spec.ClusterTreeOptions.LeafModels, nodes) - isNode2NodeFunc := func(cluster *kosmosv1alpha1.Cluster) bool { - return cluster.Spec.ClusterTreeOptions.LeafModels != nil - } - nodeResourcesController := controllers.NodeResourcesController{ Leaf: mgr.GetClient(), GlobalLeafManager: c.GlobalLeafManager, @@ -289,7 +293,7 @@ func (c *ClusterController) setupControllers(mgr manager.Manager, cluster *kosmo return fmt.Errorf("error starting podUpstreamReconciler %s: %v", podcontrollers.LeafPodControllerName, err) } - err := c.setupStorageControllers(mgr, nodes, leafClient) + err := c.setupStorageControllers(mgr, nodes, leafClient, cluster.Name) if err != nil { return err } @@ -297,12 +301,12 @@ func (c *ClusterController) setupControllers(mgr manager.Manager, cluster *kosmo return nil } -func (c *ClusterController) setupStorageControllers(mgr manager.Manager, nodes []*corev1.Node, leafClient kubernetes.Interface) error { +func (c *ClusterController) setupStorageControllers(mgr manager.Manager, nodes []*corev1.Node, leafClient kubernetes.Interface, clustername string) error { leafPVCController := pvc.LeafPVCController{ LeafClient: mgr.GetClient(), RootClient: c.Root, RootClientSet: c.RootClient, - NodeName: nodes[0].Name, + ClusterName: clustername, } if err := leafPVCController.SetupWithManager(mgr); err != nil { return fmt.Errorf("error starting leaf pvc controller %v", err) @@ -312,7 +316,7 @@ func (c *ClusterController) setupStorageControllers(mgr manager.Manager, nodes [ LeafClient: mgr.GetClient(), RootClient: c.Root, RootClientSet: c.RootClient, - NodeName: nodes[0].Name, + ClusterName: clustername, } if err := leafPVController.SetupWithManager(mgr); err != nil { return fmt.Errorf("error starting leaf pv controller %v", err) diff --git a/pkg/clustertree/cluster-manager/controllers/pv/leaf_pv_controller.go b/pkg/clustertree/cluster-manager/controllers/pv/leaf_pv_controller.go index a6f8fd773..d6930a80d 100644 --- a/pkg/clustertree/cluster-manager/controllers/pv/leaf_pv_controller.go +++ b/pkg/clustertree/cluster-manager/controllers/pv/leaf_pv_controller.go @@ -32,7 +32,7 @@ type LeafPVController struct { LeafClient client.Client RootClient client.Client RootClientSet kubernetes.Interface - NodeName string + ClusterName string } func (l *LeafPVController) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { @@ -84,7 +84,7 @@ func (l *LeafPVController) Reconcile(ctx context.Context, request reconcile.Requ } rootPV = pv.DeepCopy() - filterPV(rootPV, l.NodeName) + filterPV(rootPV, l.ClusterName) nn := types.NamespacedName{ Name: rootPV.Spec.ClaimRef.Name, Namespace: rootPV.Spec.ClaimRef.Namespace, @@ -101,7 +101,7 @@ func (l *LeafPVController) Reconcile(ctx context.Context, request reconcile.Requ rootPV.Spec.ClaimRef.UID = rootPVC.UID rootPV.Spec.ClaimRef.ResourceVersion = rootPVC.ResourceVersion - utils.AddResourceOwnersAnnotations(rootPV.Annotations, l.NodeName) + utils.AddResourceOwnersAnnotations(rootPV.Annotations, l.ClusterName) rootPV, err = l.RootClientSet.CoreV1().PersistentVolumes().Create(ctx, rootPV, metav1.CreateOptions{}) if err != nil || rootPV == nil { @@ -112,7 +112,7 @@ func (l *LeafPVController) Reconcile(ctx context.Context, request reconcile.Requ return reconcile.Result{}, nil } - if !utils.HasResourceOwnersAnnotations(rootPV.Annotations, l.NodeName) { + if !utils.HasResourceOwnersAnnotations(rootPV.Annotations, l.ClusterName) { klog.Errorf("meet the same name root pv name: %q !", request.NamespacedName.Name) return reconcile.Result{}, nil } @@ -128,7 +128,7 @@ func (l *LeafPVController) Reconcile(ctx context.Context, request reconcile.Requ return reconcile.Result{}, nil } - filterPV(rootPV, l.NodeName) + filterPV(rootPV, l.ClusterName) if pvCopy.Spec.ClaimRef != nil || rootPV.Spec.ClaimRef == nil { nn := types.NamespacedName{ Name: pvCopy.Spec.ClaimRef.Name, @@ -151,7 +151,7 @@ func (l *LeafPVController) Reconcile(ctx context.Context, request reconcile.Requ pvCopy.Spec.NodeAffinity = rootPV.Spec.NodeAffinity pvCopy.UID = rootPV.UID pvCopy.ResourceVersion = rootPV.ResourceVersion - utils.AddResourceOwnersAnnotations(pvCopy.Annotations, l.NodeName) + utils.AddResourceOwnersAnnotations(pvCopy.Annotations, l.ClusterName) if utils.IsPVEqual(rootPV, pvCopy) { return reconcile.Result{}, nil diff --git a/pkg/clustertree/cluster-manager/controllers/pvc/leaf_pvc_controller.go b/pkg/clustertree/cluster-manager/controllers/pvc/leaf_pvc_controller.go index 0db39ad67..07a85bab7 100644 --- a/pkg/clustertree/cluster-manager/controllers/pvc/leaf_pvc_controller.go +++ b/pkg/clustertree/cluster-manager/controllers/pvc/leaf_pvc_controller.go @@ -34,7 +34,7 @@ type LeafPVCController struct { LeafClient client.Client RootClient client.Client RootClientSet kubernetes.Interface - NodeName string + ClusterName string } func (l *LeafPVCController) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { @@ -65,14 +65,14 @@ func (l *LeafPVCController) Reconcile(ctx context.Context, request reconcile.Req if reflect.DeepEqual(rootPVC.Status, pvcCopy.Status) { return reconcile.Result{}, nil } - if err = filterPVC(pvcCopy, l.NodeName); err != nil { + if err = filterPVC(pvcCopy, l.ClusterName); err != nil { return reconcile.Result{}, nil } delete(pvcCopy.Annotations, utils.PVCSelectedNodeKey) pvcCopy.ResourceVersion = rootPVC.ResourceVersion pvcCopy.OwnerReferences = rootPVC.OwnerReferences - utils.AddResourceOwnersAnnotations(pvcCopy.Annotations, l.NodeName) + utils.AddResourceOwnersAnnotations(pvcCopy.Annotations, l.ClusterName) pvcCopy.Spec = rootPVC.Spec klog.V(4).Infof("rootPVC %+v\n, pvc %+v", rootPVC, pvcCopy)