diff --git a/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go b/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go index 2ea1472e9..acfea97ab 100644 --- a/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go +++ b/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go @@ -150,11 +150,6 @@ func (c *NodeResourcesController) Reconcile(ctx context.Context, request reconci // } clone.Spec.Taints = rootNode.Spec.Taints clone.Status = node.Status - clone.Status.Addresses, err = leafUtils.GetAddress(ctx, c.RootClientset, node.Status.Addresses) - if err != nil { - klog.Errorf("GetAddress node %s, err: %v, ", rootNode.Name, err) - return reconcile.Result{}, err - } } } // TODO ggregation Labels and Annotations for classificationModel diff --git a/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go b/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go index e33e60f42..a45274cb1 100644 --- a/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go +++ b/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go @@ -150,18 +150,25 @@ func (h ClassificationHandler) UpdateRootNodeStatus(ctx context.Context, nodesIn rootCopy.Status.Capacity = clusterResources } - rootCopy.Status.Addresses, err = GetAddress(ctx, h.RootClientset, nodesInLeaf.Items[0].Status.Addresses) + updateAddress, err := GetAddress(ctx, h.RootClientset, nodesInLeaf.Items[0].Status.Addresses) if err != nil { return err } patch, err := utils.CreateMergePatch(nodeInRoot, rootCopy) + klog.Infof("patch: %s", patch) if err != nil { return fmt.Errorf("failed to CreateMergePatch while update join node %s status, err: %v", nodeNameInRoot, err) } - if _, err = h.RootClientset.CoreV1().Nodes().PatchStatus(ctx, node.Name, patch); err != nil { + if latestNode, err := h.RootClientset.CoreV1().Nodes().PatchStatus(ctx, node.Name, patch); err != nil { return err + } else { + latestNode.ResourceVersion = "" + latestNode.Status.Addresses = updateAddress + if _, err = h.RootClientset.CoreV1().Nodes().UpdateStatus(ctx, latestNode, metav1.UpdateOptions{}); err != nil { + return err + } } return nil }) diff --git a/pkg/clustertree/cluster-manager/utils/rootcluster.go b/pkg/clustertree/cluster-manager/utils/rootcluster.go index 3707ffbee..0e65ce661 100644 --- a/pkg/clustertree/cluster-manager/utils/rootcluster.go +++ b/pkg/clustertree/cluster-manager/utils/rootcluster.go @@ -49,7 +49,10 @@ func GetAddress(ctx context.Context, rootClient kubernetes.Interface, originAddr } func SortAddress(ctx context.Context, rootClient kubernetes.Interface, originAddress []corev1.NodeAddress) ([]corev1.NodeAddress, error) { - rootnodes, err := rootClient.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) + rootnodes, err := rootClient.CoreV1().Nodes().List(ctx, metav1.ListOptions{ + // get the node which is not created by kosmos + LabelSelector: fmt.Sprintf("%s!=%s", utils.KosmosNodeLabel, utils.KosmosNodeValue), + }) if err != nil { return nil, fmt.Errorf("create node failed, cannot get node from root cluster, err: %v", err) }