From 8a58f62fe03e744ba75fcdd5fbd1f057c84ff4d7 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 7 Jul 2017 11:17:17 -0500 Subject: [PATCH] proxy/userspace: honor listen IP address as host IP if given Allows the proxier to be used on an interface that's not the default route, otherwise hostIP gets set to the default route interface even if that's not what the user intended. If listen IP isn't given, falls back to previous behavior. --- pkg/proxy/userspace/proxier.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/proxy/userspace/proxier.go b/pkg/proxy/userspace/proxier.go index 5032577b81f..5224d45d4b8 100644 --- a/pkg/proxy/userspace/proxier.go +++ b/pkg/proxy/userspace/proxier.go @@ -166,9 +166,15 @@ func NewCustomProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptab return nil, ErrProxyOnLocalhost } - hostIP, err := utilnet.ChooseHostInterface() - if err != nil { - return nil, fmt.Errorf("failed to select a host interface: %v", err) + // If listenIP is given, assume that is the intended host IP. Otherwise + // try to find a suitable host IP address from network interfaces. + var err error + hostIP := listenIP + if hostIP.Equal(net.IPv4zero) { + hostIP, err = utilnet.ChooseHostInterface() + if err != nil { + return nil, fmt.Errorf("failed to select a host interface: %v", err) + } } err = setRLimit(64 * 1000)