diff --git a/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go b/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go index 0cfcad813..14831c71f 100644 --- a/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go +++ b/pkg/clustertree/cluster-manager/controllers/node_resources_controller.go @@ -149,11 +149,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 - } } } diff --git a/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go b/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go index 55c4cbf5f..132841c2d 100644 --- a/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go +++ b/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go @@ -109,7 +109,7 @@ func (h AggregationModelHandler) UpdateNodeStatus(ctx context.Context, n []*core return fmt.Errorf("cannot get node in leaf cluster while update node status, leaf node item is 0") } - clone.Status.Addresses, err = GetAddress(ctx, h.RootClientset, nodeListInLeaf.Items[0].Status.Addresses) + updateAddress, err := GetAddress(ctx, h.RootClientset, nodeListInLeaf.Items[0].Status.Addresses) if err != nil { return err @@ -121,8 +121,14 @@ func (h AggregationModelHandler) UpdateNodeStatus(ctx context.Context, n []*core return fmt.Errorf("cannot get node while update node status %s, err: %v", node.Name, err) } - if node, 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) }