Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the vip when delete cluster or nodes #1496

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}