middleware/kubernetes: cleanup (#818)

Drop the interfaceAddr interfaces and just use a function. Cleanup
all fallout from that. Remove the use of global variables and cleanup
the tests a bit.
This commit is contained in:
Miek Gieben
2017-08-03 23:14:11 -07:00
committed by GitHub
parent 8ad8c75ab4
commit 2c0fc3182c
8 changed files with 25 additions and 53 deletions

View File

@@ -46,7 +46,7 @@ type Kubernetes struct {
ReverseCidrs []net.IPNet
Fallthrough bool
AutoPath
interfaceAddrs interfaceAddrser
interfaceAddrsFunc func() net.IP
}
type AutoPath struct {
@@ -98,8 +98,6 @@ type recordRequest struct {
federation string
}
var localPodIP net.IP
var (
errNoItems = errors.New("no items found")
errNsNotExposed = errors.New("namespace is not exposed")
@@ -651,11 +649,11 @@ func symbolContainsWildcard(symbol string) bool {
return (symbol == "*" || symbol == "any")
}
func (k *Kubernetes) localPodIP() net.IP {
if localPodIP != nil {
return localPodIP
func localPodIP() net.IP {
addrs, err := net.InterfaceAddrs()
if err != nil {
return nil
}
addrs, _ := k.interfaceAddrs.interfaceAddrs()
for _, addr := range addrs {
ip, _, _ := net.ParseCIDR(addr.String())
@@ -663,8 +661,7 @@ func (k *Kubernetes) localPodIP() net.IP {
if ip == nil || ip.IsLoopback() {
continue
}
localPodIP = ip
return localPodIP
return ip
}
return nil
}