From 1138045185a3a9a71f46421355cdef19af267bf3 Mon Sep 17 00:00:00 2001 From: Subin M Date: Mon, 2 Mar 2015 16:11:45 +0530 Subject: [PATCH] use ChooseHostInterface to get IP --- pkg/master/master.go | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/pkg/master/master.go b/pkg/master/master.go index 68c2ff7729..49f91f4a93 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -206,34 +206,14 @@ func setDefaults(c *Config) { c.CacheTimeout = 5 * time.Second } for c.PublicAddress == nil { - // Find and use the first non-loopback address. - // TODO: potentially it'd be useful to skip the docker interface if it - // somehow is first in the list. - addrs, err := net.InterfaceAddrs() + hostIP, err := util.ChooseHostInterface() if err != nil { - glog.Fatalf("Unable to get network interfaces: error='%v'", err) - } - found := false - for i := range addrs { - ip, _, err := net.ParseCIDR(addrs[i].String()) - if err != nil { - glog.Errorf("Error parsing '%v': %v", addrs[i], err) - continue - } - if ip.IsLoopback() { - glog.V(5).Infof("'%v' (%v) is a loopback address, ignoring.", ip, addrs[i]) - continue - } - found = true - c.PublicAddress = ip - glog.V(2).Infof("Will report %v as public IP address.", ip) - break - } - if !found { - glog.Errorf("Unable to find suitable network address in list: '%v'\n"+ - "Will try again in 5 seconds. Set the public address directly to avoid this wait.", addrs) + glog.Fatalf("Unable to find suitable network address.error='%v' . "+ + "Will try again in 5 seconds. Set the public address directly to avoid this wait.", err) time.Sleep(5 * time.Second) } + c.PublicAddress = hostIP + glog.Infof("Will report %v as public IP address.", c.PublicAddress) } if c.RequestContextMapper == nil { c.RequestContextMapper = api.NewRequestContextMapper()