From 07e2bceac191107fc955d7a716463d6b091de8ee Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Mon, 13 Mar 2023 14:32:00 +0800 Subject: [PATCH] feature(main): delete node if failed Signed-off-by: cuisongliu --- pkg/runtime/utils.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/runtime/utils.go b/pkg/runtime/utils.go index 52996d25ea6..05a4111ecbd 100644 --- a/pkg/runtime/utils.go +++ b/pkg/runtime/utils.go @@ -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 }