From b1be963cb6beb267c5989466d935950c9f099948 Mon Sep 17 00:00:00 2001 From: zhouqiu0103 Date: Thu, 8 Sep 2022 09:35:41 +0800 Subject: [PATCH] clean up the vip when delete cluster or nodes --- pkg/loadbalancer/module.go | 13 +++++++++++-- pkg/loadbalancer/tasks.go | 12 ++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/loadbalancer/module.go b/pkg/loadbalancer/module.go index 28b857f31..298219b90 100644 --- a/pkg/loadbalancer/module.go +++ b/pkg/loadbalancer/module.go @@ -353,15 +353,24 @@ func (k *DeleteVIPModule) Init() { k.Name = "DeleteVIPModule" k.Desc = "Delete VIP" + getInterface := &task.RemoteTask{ + Name: "GetNodeInterface", + Desc: "Get Node Interface", + Hosts: k.Runtime.GetHostsByRole(common.Master), + Action: new(GetInterfaceName), + Parallel: true, + } + DeleteVIP := &task.RemoteTask{ - Name: "GenerateKubevipManifest", - Desc: "Generate kubevip manifest at other master", + Name: "Delete VIP", + Desc: "Delete the VIP", Hosts: k.Runtime.GetHostsByRole(common.Master), Action: new(DeleteVIP), Parallel: true, } k.Tasks = []task.Interface{ + getInterface, DeleteVIP, } } diff --git a/pkg/loadbalancer/tasks.go b/pkg/loadbalancer/tasks.go index f723e1d6e..9d0831ecc 100644 --- a/pkg/loadbalancer/tasks.go +++ b/pkg/loadbalancer/tasks.go @@ -303,12 +303,12 @@ type DeleteVIP struct { } func (g *DeleteVIP) Execute(runtime connector.Runtime) error { - if g.KubeConf.Cluster.ControlPlaneEndpoint.KubeVip.Mode == "BGP" { - cmd := fmt.Sprintf("ip addr del %s dev lo", g.KubeConf.Cluster.ControlPlaneEndpoint.Address) - _, err := runtime.GetRunner().SudoCmd(cmd, false) - if err != nil { - return err - } + host := runtime.RemoteHost() + interfaceName, ok := host.GetCache().GetMustString("interface") + if !ok { + return errors.New("get interface failed") } + cmd := fmt.Sprintf("ip addr del %s dev %s", g.KubeConf.Cluster.ControlPlaneEndpoint.Address, interfaceName) + runtime.GetRunner().SudoCmd(cmd, false) return nil }