Skip to content

Commit

Permalink
fix: resolve the issue of node address update errors
Browse files Browse the repository at this point in the history
Signed-off-by: OrangeBao <[email protected]>
  • Loading branch information
OrangeBao committed Dec 22, 2023
1 parent 76c7ecb commit 7893dca
Show file tree
Hide file tree
Showing 3 changed files with 13 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
11 changes: 9 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,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
})
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 7893dca

Please sign in to comment.