Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve the issue of node address update errors #341

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

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 @@ -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
Expand All @@ -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
})
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
Loading