From 1a032a0cee93e7040dafd23fecce1c07e9d2331c Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Fri, 15 Dec 2017 11:12:45 -0500 Subject: [PATCH] add flag to set the host interface to use --- pkg/cmd/main.go | 6 ++++-- pkg/controller/keepalived.go | 1 + pkg/controller/main.go | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/main.go b/pkg/cmd/main.go index c938d284..f753e352 100644 --- a/pkg/cmd/main.go +++ b/pkg/cmd/main.go @@ -76,6 +76,9 @@ var ( `The keepalived VRID (Virtual Router Identifier, between 0 and 255 as per RFC-5798), which must be different for every Virtual Router (ie. every keepalived sets) running on the same network.`) + + iface = flags.String("iface", "", `network interface to listen on. If undefined, the nodes + default interface will be used instead`) ) func main() { @@ -118,14 +121,13 @@ func main() { if *proxyMode { copyHaproxyCfg() } - kubeClient, err := createApiserverClient(*apiserverHost, *kubeConfigFile) if err != nil { handleFatalInitError(err) } glog.Info("starting LVS configuration") - ipvsc := controller.NewIPVSController(kubeClient, *watchNamespace, *useUnicast, *configMapName, *vrid, *proxyMode) + ipvsc := controller.NewIPVSController(kubeClient, *watchNamespace, *useUnicast, *configMapName, *vrid, *proxyMode, *iface) ipvsc.Start() } diff --git a/pkg/controller/keepalived.go b/pkg/controller/keepalived.go index b12599ce..c415c7fe 100644 --- a/pkg/controller/keepalived.go +++ b/pkg/controller/keepalived.go @@ -81,6 +81,7 @@ func (k *keepalived) WriteCfg(svcs []vip) error { conf["priority"] = k.priority conf["useUnicast"] = k.useUnicast conf["vrid"] = k.vrid + conf["iface"] = k.iface conf["proxyMode"] = k.proxyMode conf["vipIsEmpty"] = len(k.vips) == 0 diff --git a/pkg/controller/main.go b/pkg/controller/main.go index 35360f0b..3f49985c 100644 --- a/pkg/controller/main.go +++ b/pkg/controller/main.go @@ -340,7 +340,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) *ipvsControllerController { +func NewIPVSController(kubeClient *kubernetes.Clientset, namespace string, useUnicast bool, configMapName string, vrid int, proxyMode bool, iface string) *ipvsControllerController { ipvsc := ipvsControllerController{ client: kubeClient, reloadRateLimiter: flowcontrol.NewTokenBucketRateLimiter(0.5, 1), @@ -365,15 +365,18 @@ func NewIPVSController(kubeClient *kubernetes.Clientset, namespace string, useUn if err != nil { glog.Fatalf("Error getting local IP from nodes in the cluster: %v", err) } - neighbors := getNodeNeighbors(nodeInfo, clusterNodes) + if iface == "" { + iface = nodeInfo.iface + glog.Info("No interface was provided, proceeding with the node's default: ", iface) + } execer := utilexec.New() dbus := utildbus.New() iptInterface := utiliptables.New(execer, dbus, utiliptables.ProtocolIpv4) ipvsc.keepalived = &keepalived{ - iface: nodeInfo.iface, + iface: iface, ip: nodeInfo.ip, netmask: nodeInfo.netmask, nodes: clusterNodes,