Skip to content

Commit

Permalink
Merge pull request #1496 from zhouqiu0103/add-vip
Browse files Browse the repository at this point in the history
Clean up the vip when delete cluster or nodes
  • Loading branch information
ks-ci-bot authored Sep 8, 2022
2 parents c2d063c + b1be963 commit 2d2fd3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 11 additions & 2 deletions pkg/loadbalancer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
12 changes: 6 additions & 6 deletions pkg/loadbalancer/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2d2fd3d

Please sign in to comment.