Skip to content

Commit

Permalink
Merge pull request #2794 from cuisongliu/delete_node
Browse files Browse the repository at this point in the history
feature(main): delete node if failed
  • Loading branch information
bxy4543 authored Mar 17, 2023
2 parents ebefb19 + 07e2bce commit af1bae9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/runtime/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,27 @@ func (k *KubeadmRuntime) sendFileToHosts(Hosts []string, src, dst string) error
}

func (k *KubeadmRuntime) deleteKubeNode(ip string) error {
var err error
logger.Info("start to remove node from k8s %s", ip)
cli, err := kubernetes.NewKubernetesClient(k.getContentData().AdminFile(), k.getMaster0IPAPIServer())
if err != nil {
return err
logger.Warn("kubernetes client get node %s failed %v,skip delete node", ip, err)
return nil
}
ctx := context.Background()
hostname, err := kubernetes.GetHostNameFromInternalIP(cli.Kubernetes(), ip)
if err != nil {
return err
logger.Warn("kubernetes client get hostname %s failed %v,skip delete node", ip, err)
return nil
}
deletePropagation := v1.DeletePropagationBackground
err = cli.Kubernetes().CoreV1().Nodes().Delete(ctx, hostname, v1.DeleteOptions{PropagationPolicy: &deletePropagation})
if err != nil {
if errors.IsNotFound(err) {
logger.Warn("not find target delete node ip: %s", ip)
return nil
}
return err
logger.Warn("kubernetes client delete node %s failed %v,skip delete node", ip, err)
}
return nil
}

0 comments on commit af1bae9

Please sign in to comment.