Skip to content

Commit

Permalink
feature(main): delete node if failed
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu committed Mar 16, 2023
1 parent ebefb19 commit 07e2bce
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 07e2bce

Please sign in to comment.