Skip to content

Commit

Permalink
Merge pull request #338 from OrangeBao/fix
Browse files Browse the repository at this point in the history
fix: resolve the issue of node address update errors
  • Loading branch information
wuyingjun-lucky committed Dec 25, 2023
2 parents 5a6b267 + 4df622f commit ab5a658
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pkg/clustertree/cluster-manager/utils/leaf_model_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ 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
}
Expand All @@ -160,8 +160,14 @@ func (h ClassificationHandler) UpdateRootNodeStatus(ctx context.Context, nodesIn
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
})
Expand Down
5 changes: 4 additions & 1 deletion pkg/clustertree/cluster-manager/utils/rootcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ab5a658

Please sign in to comment.