Skip to content

Commit

Permalink
Merge pull request #253 from duanmengkk/fix_nodenotfound_err
Browse files Browse the repository at this point in the history
Fix nodenotfound err
  • Loading branch information
kosmos-robot authored Nov 16, 2023
2 parents 9a6c2ba + bda6aa3 commit 49a1e26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pkg/clustertree/cluster-manager/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (c *ClusterController) Reconcile(ctx context.Context, request reconcile.Req

nodes, err := c.createNode(ctx, cluster, leafClient)
if err != nil {
return reconcile.Result{}, fmt.Errorf("create node with err %v, cluster %s", err, cluster.Name)
return reconcile.Result{RequeueAfter: RequeueTime}, fmt.Errorf("create node with err %v, cluster %s", err, cluster.Name)
}
// TODO @wyz
for _, node := range nodes {
Expand Down
83 changes: 35 additions & 48 deletions pkg/clustertree/cluster-manager/utils/leaf_model_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,23 @@ func (h AggregationModelHandler) CreateNodeInRoot(ctx context.Context, cluster *
nodeName := fmt.Sprintf("%s%s", utils.KosmosNodePrefix, cluster.Name)
node, err := h.RootClientset.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
node = utils.BuildNodeTemplate(nodeName)
node.Status.NodeInfo.KubeletVersion = gitVersion
node.Status.DaemonEndpoints = corev1.NodeDaemonEndpoints{
KubeletEndpoint: corev1.DaemonEndpoint{
Port: listenPort,
},
}
if !errors.IsNotFound(err) {
return nil, err
}
node = utils.BuildNodeTemplate(nodeName)
node.Status.NodeInfo.KubeletVersion = gitVersion
node.Status.DaemonEndpoints = corev1.NodeDaemonEndpoints{
KubeletEndpoint: corev1.DaemonEndpoint{
Port: listenPort,
},
}

node, err = h.RootClientset.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{})
if err != nil {
if !errors.IsAlreadyExists(err) {
return nil, err
} else {
nodes = append(nodes, node)
}
}
} else {
node, err = h.RootClientset.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{})
if err != nil {
return nil, err
}
} else {
nodes = append(nodes, node)
}
nodes = append(nodes, node)
return nodes, nil
}

Expand Down Expand Up @@ -169,40 +163,33 @@ func (h DispersionModelHandler) CreateNodeInRoot(ctx context.Context, cluster *k
// todo only support nodeName now
if leafModel.NodeSelector.NodeName != "" {
nodeName := leafModel.NodeSelector.NodeName

node, err := h.RootClientset.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
node = utils.BuildNodeTemplate(nodeName)

nodeAnnotations := node.GetAnnotations()
if nodeAnnotations == nil {
nodeAnnotations = make(map[string]string, 1)
}
nodeAnnotations[utils.KosmosNodeOwnedByClusterAnnotations] = cluster.Name
node.SetAnnotations(nodeAnnotations)

node.Status.NodeInfo.KubeletVersion = gitVersion
node.Status.DaemonEndpoints = corev1.NodeDaemonEndpoints{
KubeletEndpoint: corev1.DaemonEndpoint{
Port: listenPort,
},
}

node, err = h.RootClientset.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{})
if err != nil {
if !errors.IsAlreadyExists(err) {
return nil, err
} else {
nodes = append(nodes, node)
}
}
} else {
if !errors.IsNotFound(err) {
return nil, err
}

node = utils.BuildNodeTemplate(nodeName)
nodeAnnotations := node.GetAnnotations()
if nodeAnnotations == nil {
nodeAnnotations = make(map[string]string, 1)
}
nodeAnnotations[utils.KosmosNodeOwnedByClusterAnnotations] = cluster.Name
node.SetAnnotations(nodeAnnotations)

node.Status.NodeInfo.KubeletVersion = gitVersion
node.Status.DaemonEndpoints = corev1.NodeDaemonEndpoints{
KubeletEndpoint: corev1.DaemonEndpoint{
Port: listenPort,
},
}

node, err = h.RootClientset.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{})
if err != nil {
return nil, err
}
} else {
nodes = append(nodes, node)
}
nodes = append(nodes, node)
}
}
return nodes, nil
Expand Down

0 comments on commit 49a1e26

Please sign in to comment.