From f65d20d8cf7265a8c1dcdbcc9b23fbf8d21b3745 Mon Sep 17 00:00:00 2001 From: Mikhail Shaverdo Date: Thu, 24 Jan 2019 13:05:28 +0300 Subject: [PATCH] Add flag to make ipvs reset optional * implement flag --release-vips default true. If it true, add --release-vips to keepalived args --- pkg/cmd/main.go | 4 +++- pkg/controller/keepalived.go | 12 +++++++----- pkg/controller/main.go | 23 ++++++++++++----------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pkg/cmd/main.go b/pkg/cmd/main.go index 24f36eb8..9739f2a3 100644 --- a/pkg/cmd/main.go +++ b/pkg/cmd/main.go @@ -81,6 +81,8 @@ var ( default interface will be used instead`) httpPort = flags.Int("http-port", 8080, `The HTTP port to use for health checks`) + + releaseVips = flags.Bool("release-vips", true, `add --release-vips to keepalived args`) ) func main() { @@ -137,7 +139,7 @@ func main() { } glog.Info("starting LVS configuration") - ipvsc := controller.NewIPVSController(kubeClient, *watchNamespace, *useUnicast, *configMapName, *vrid, *proxyMode, *iface, *httpPort) + ipvsc := controller.NewIPVSController(kubeClient, *watchNamespace, *useUnicast, *configMapName, *vrid, *proxyMode, *iface, *httpPort, *releaseVips) ipvsc.Start() } diff --git a/pkg/controller/keepalived.go b/pkg/controller/keepalived.go index 9e93e5bc..1d5b316e 100644 --- a/pkg/controller/keepalived.go +++ b/pkg/controller/keepalived.go @@ -65,6 +65,7 @@ type keepalived struct { vrid int proxyMode bool notify string + releaseVips bool } // WriteCfg creates a new keepalived configuration file. @@ -141,11 +142,12 @@ func (k *keepalived) Start() { glog.V(2).Infof("chain %v already existed", iptablesChain) } - k.cmd = exec.Command("keepalived", - "--dont-fork", - "--log-console", - "--release-vips", - "--log-detail") + args := []string{"--dont-fork", "--log-console", "--log-detail"} + if k.releaseVips { + args = append(args, "--release-vips") + } + + k.cmd = exec.Command("keepalived", args...) k.cmd.Stdout = os.Stdout k.cmd.Stderr = os.Stderr diff --git a/pkg/controller/main.go b/pkg/controller/main.go index 4d49cc2f..2ab643f4 100644 --- a/pkg/controller/main.go +++ b/pkg/controller/main.go @@ -353,7 +353,7 @@ func (ipvsc *ipvsControllerController) Stop() error { } // NewIPVSController creates a new controller from the given config. -func NewIPVSController(kubeClient *kubernetes.Clientset, namespace string, useUnicast bool, configMapName string, vrid int, proxyMode bool, iface string, httpPort int) *ipvsControllerController { +func NewIPVSController(kubeClient *kubernetes.Clientset, namespace string, useUnicast bool, configMapName string, vrid int, proxyMode bool, iface string, httpPort int, releaseVips bool) *ipvsControllerController { ipvsc := ipvsControllerController{ client: kubeClient, reloadRateLimiter: flowcontrol.NewTokenBucketRateLimiter(0.5, 1), @@ -392,17 +392,18 @@ func NewIPVSController(kubeClient *kubernetes.Clientset, namespace string, useUn iptInterface := utiliptables.New(execer, dbus, utiliptables.ProtocolIpv4) ipvsc.keepalived = &keepalived{ - iface: iface, - ip: nodeInfo.ip, - netmask: nodeInfo.netmask, - nodes: clusterNodes, - neighbors: neighbors, - priority: getNodePriority(nodeInfo.ip, clusterNodes), - useUnicast: useUnicast, - ipt: iptInterface, - vrid: vrid, - proxyMode: proxyMode, + iface: iface, + ip: nodeInfo.ip, + netmask: nodeInfo.netmask, + nodes: clusterNodes, + neighbors: neighbors, + priority: getNodePriority(nodeInfo.ip, clusterNodes), + useUnicast: useUnicast, + ipt: iptInterface, + vrid: vrid, + proxyMode: proxyMode, notify: notify, + releaseVips: releaseVips, } ipvsc.syncQueue = task.NewTaskQueue(ipvsc.sync)