Fix testing if an interface is the loopback

It's not guaranteed that the loopback interface only has the loopback
IP, in our environments our loopback interface is also assigned a 169
address as well.
pull/564/head
Ben Moss 2019-02-14 10:17:52 -05:00
parent 01e7b3040a
commit 70923dd9db
1 changed files with 4 additions and 1 deletions

View File

@ -547,12 +547,15 @@ func getLocalIP() ([]v1.NodeAddress, error) {
return nil, err
}
for _, i := range ifaces {
if i.Flags&net.FlagLoopback != 0 {
continue
}
localAddrs, err := i.Addrs()
if err != nil {
klog.Warningf("Failed to extract addresses for NodeAddresses - %v", err)
} else {
for _, addr := range localAddrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet, ok := addr.(*net.IPNet); ok {
if ipnet.IP.To4() != nil {
// Filter external IP by MAC address OUIs from vCenter and from ESX
vmMACAddr := strings.ToLower(i.HardwareAddr.String())