From c71d214af1e3be3da40ae379eef4e26d658dbc24 Mon Sep 17 00:00:00 2001 From: 24sama Date: Fri, 10 Jun 2022 14:21:45 +0800 Subject: [PATCH] fix: replace the "ClearOSEnvironmentModule" in the "DeleteNodePipeline" with the "ClearNodeOSModule" Signed-off-by: 24sama --- pkg/bootstrap/os/module.go | 45 ++++++++++++++++++++++++++++++++---- pkg/bootstrap/os/tasks.go | 32 +++++++++++++++++++++++++ pkg/certs/module.go | 12 ++++------ pkg/pipelines/delete_node.go | 4 +--- 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/pkg/bootstrap/os/module.go b/pkg/bootstrap/os/module.go index 86d32741..53f20970 100644 --- a/pkg/bootstrap/os/module.go +++ b/pkg/bootstrap/os/module.go @@ -82,6 +82,47 @@ func (c *ConfigureOSModule) Init() { } } +type ClearNodeOSModule struct { + common.KubeModule +} + +func (c *ClearNodeOSModule) Init() { + c.Name = "ClearNodeOSModule" + + resetNetworkConfig := &task.RemoteTask{ + Name: "ResetNetworkConfig", + Desc: "Reset os network config", + Hosts: c.Runtime.GetHostsByRole(common.Worker), + Prepare: new(DeleteNode), + Action: new(ResetNetworkConfig), + Parallel: true, + } + + removeFiles := &task.RemoteTask{ + Name: "RemoveFiles", + Desc: "Remove node files", + Hosts: c.Runtime.GetHostsByRole(common.Worker), + Prepare: new(DeleteNode), + Action: new(RemoveNodeFiles), + Parallel: true, + } + + daemonReload := &task.RemoteTask{ + Name: "DaemonReload", + Desc: "Systemd daemon reload", + Hosts: c.Runtime.GetHostsByRole(common.Worker), + Prepare: new(DeleteNode), + Action: new(DaemonReload), + Parallel: true, + } + + c.Tasks = []task.Interface{ + resetNetworkConfig, + removeFiles, + daemonReload, + } +} + type ClearOSEnvironmentModule struct { common.KubeModule } @@ -93,7 +134,6 @@ func (c *ClearOSEnvironmentModule) Init() { Name: "ResetNetworkConfig", Desc: "Reset os network config", Hosts: c.Runtime.GetHostsByRole(common.K8s), - Prepare: new(DeleteNode), Action: new(ResetNetworkConfig), Parallel: true, } @@ -104,7 +144,6 @@ func (c *ClearOSEnvironmentModule) Init() { Hosts: c.Runtime.GetHostsByRole(common.ETCD), Prepare: &prepare.PrepareCollection{ new(EtcdTypeIsKubeKey), - new(DeleteNode), }, Action: new(UninstallETCD), Parallel: true, @@ -114,7 +153,6 @@ func (c *ClearOSEnvironmentModule) Init() { Name: "RemoveFiles", Desc: "Remove cluster files", Hosts: c.Runtime.GetHostsByRole(common.K8s), - Prepare: new(DeleteNode), Action: new(RemoveFiles), Parallel: true, } @@ -123,7 +161,6 @@ func (c *ClearOSEnvironmentModule) Init() { Name: "DaemonReload", Desc: "Systemd daemon reload", Hosts: c.Runtime.GetHostsByRole(common.K8s), - Prepare: new(DeleteNode), Action: new(DaemonReload), Parallel: true, } diff --git a/pkg/bootstrap/os/tasks.go b/pkg/bootstrap/os/tasks.go index 5ea04b82..44aacc3e 100644 --- a/pkg/bootstrap/os/tasks.go +++ b/pkg/bootstrap/os/tasks.go @@ -196,6 +196,38 @@ func (s *UninstallETCD) Execute(runtime connector.Runtime) error { return nil } +type RemoveNodeFiles struct { + common.KubeAction +} + +func (r *RemoveNodeFiles) Execute(runtime connector.Runtime) error { + nodeFiles := []string{ + "/etc/kubernetes", + "/etc/systemd/system/etcd.service", + "/var/log/calico", + "/etc/cni", + "/var/log/pods/", + "/var/lib/cni", + "/var/lib/calico", + "/var/lib/kubelet", + "/run/calico", + "/run/flannel", + "/etc/flannel", + "/etc/systemd/system/kubelet.service", + "/etc/systemd/system/kubelet.service.d", + "/usr/local/bin/kubelet", + "/usr/local/bin/kubeadm", + "/usr/bin/kubelet", + "/tmp/kubekey", + "/etc/kubekey", + } + + for _, file := range nodeFiles { + _, _ = runtime.GetRunner().SudoCmd(fmt.Sprintf("rm -rf %s", file), true) + } + return nil +} + type RemoveFiles struct { common.KubeAction } diff --git a/pkg/certs/module.go b/pkg/certs/module.go index 4b1b213d..97d3857c 100644 --- a/pkg/certs/module.go +++ b/pkg/certs/module.go @@ -21,7 +21,6 @@ import ( versionutil "k8s.io/apimachinery/pkg/util/version" - "github.com/kubesphere/kubekey/pkg/bootstrap/os" "github.com/kubesphere/kubekey/pkg/certs/templates" "github.com/kubesphere/kubekey/pkg/common" "github.com/kubesphere/kubekey/pkg/core/action" @@ -201,13 +200,10 @@ func (u *UninstallAutoRenewCertsModule) Init() { u.Desc = "UnInstall auto renew control-plane certs" uninstall := &task.RemoteTask{ - Name: "UnInstallAutoRenewCerts", - Desc: "UnInstall auto renew control-plane certs", - Hosts: u.Runtime.GetHostsByRole(common.Master), - Prepare: &prepare.PrepareCollection{ - new(AutoRenewCertsEnabled), - new(os.DeleteNode), - }, + Name: "UnInstallAutoRenewCerts", + Desc: "UnInstall auto renew control-plane certs", + Hosts: u.Runtime.GetHostsByRole(common.Master), + Prepare: new(AutoRenewCertsEnabled), Action: new(UninstallAutoRenewCerts), Parallel: true, } diff --git a/pkg/pipelines/delete_node.go b/pkg/pipelines/delete_node.go index db8f4e24..164d5c66 100644 --- a/pkg/pipelines/delete_node.go +++ b/pkg/pipelines/delete_node.go @@ -20,7 +20,6 @@ import ( "github.com/kubesphere/kubekey/pkg/bootstrap/confirm" "github.com/kubesphere/kubekey/pkg/bootstrap/os" "github.com/kubesphere/kubekey/pkg/bootstrap/precheck" - "github.com/kubesphere/kubekey/pkg/certs" "github.com/kubesphere/kubekey/pkg/common" "github.com/kubesphere/kubekey/pkg/core/module" "github.com/kubesphere/kubekey/pkg/core/pipeline" @@ -33,8 +32,7 @@ func DeleteNodePipeline(runtime *common.KubeRuntime) error { &confirm.DeleteNodeConfirmModule{}, &kubernetes.CompareConfigAndClusterInfoModule{}, &kubernetes.DeleteKubeNodeModule{}, - &os.ClearOSEnvironmentModule{}, - &certs.UninstallAutoRenewCertsModule{}, + &os.ClearNodeOSModule{}, } p := pipeline.Pipeline{