Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Cleanup VIPs on startup #68

Merged
merged 2 commits into from
Dec 3, 2018
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
19 changes: 12 additions & 7 deletions pkg/controller/keepalived.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (k *keepalived) WriteCfg(svcs []vip) error {
conf["myIP"] = k.ip
conf["netmask"] = k.netmask
conf["svcs"] = svcs
conf["vips"] = getVIPs(svcs)
conf["vips"] = k.vips
conf["nodes"] = k.neighbors
conf["priority"] = k.priority
conf["useUnicast"] = k.useUnicast
Expand Down Expand Up @@ -165,6 +165,7 @@ func (k *keepalived) Reload() error {
return nil
}

k.Cleanup()
glog.Info("reloading keepalived")
err := syscall.Kill(k.cmd.Process.Pid, syscall.SIGHUP)
if err != nil {
Expand All @@ -174,8 +175,8 @@ func (k *keepalived) Reload() error {
return nil
}

// Stop stop keepalived process
func (k *keepalived) Stop() {
func (k *keepalived) Cleanup() {
glog.Infof("Cleanup: %s", k.vips)
for _, vip := range k.vips {
k.removeVIP(vip)
}
Expand All @@ -184,20 +185,24 @@ func (k *keepalived) Stop() {
if err != nil {
glog.V(2).Infof("unexpected error flushing iptables chain %v: %v", err, iptablesChain)
}
}

err = syscall.Kill(k.cmd.Process.Pid, syscall.SIGTERM)
// Stop stop keepalived process
func (k *keepalived) Stop() {
k.Cleanup()

err := syscall.Kill(k.cmd.Process.Pid, syscall.SIGTERM)
if err != nil {
glog.Errorf("error stopping keepalived: %v", err)
}
}

func (k *keepalived) removeVIP(vip string) error {
func (k *keepalived) removeVIP(vip string) {
glog.Infof("removing configured VIP %v", vip)
out, err := k8sexec.New().Command("ip", "addr", "del", vip+"/32", "dev", k.iface).CombinedOutput()
if err != nil {
return fmt.Errorf("error reloading keepalived: %v\n%s", err, out)
glog.V(2).Infof("Error removing VIP %s: %v\n%s", vip, err, out)
}
return nil
}

func (k *keepalived) loadTemplates() error {
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type ipvsControllerController struct {
keepalived *keepalived

configMapName string
configMapResourceVersion string

ruMD5 string

Expand Down Expand Up @@ -259,6 +260,12 @@ func (ipvsc *ipvsControllerController) sync(key interface{}) error {
return fmt.Errorf("unexpected error searching configmap %v: %v", ipvsc.configMapName, err)
}

if ipvsc.configMapResourceVersion == cfgMap.ObjectMeta.ResourceVersion {
glog.V(2).Infof("No change to %s ConfigMap", name)
return nil
}

ipvsc.configMapResourceVersion = cfgMap.ObjectMeta.ResourceVersion
svc := ipvsc.getServices(cfgMap)

err = ipvsc.keepalived.WriteCfg(svc)
Expand Down
2 changes: 1 addition & 1 deletion rootfs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN clean-install \
libxtables12 \
libnfnetlink0 \
libiptcdata0 \
libipset3 \
libipset11 \
libipset-dev \
libsnmp30 \
kmod \
Expand Down