mirror of https://github.com/kubernetes/kops.git
Merge pull request #4078 from justinsb/protokube_local_addresses
Automatic merge from submit-queue. protokube: better discovery of local address
This commit is contained in:
commit
490f860bc9
|
@ -139,6 +139,15 @@ func run() error {
|
||||||
internalIP = vsphereVolumes.InternalIp()
|
internalIP = vsphereVolumes.InternalIp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if cloud == "baremetal" {
|
||||||
|
if internalIP == nil {
|
||||||
|
ip, err := findInternalIP()
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("error finding internal IP: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
internalIP = ip
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("Unknown cloud %q", cloud)
|
glog.Errorf("Unknown cloud %q", cloud)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -314,7 +323,7 @@ func run() error {
|
||||||
return fmt.Errorf("Unexpected exit")
|
return fmt.Errorf("Unexpected exit")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: run with --net=host ??
|
// findInternalIP attempts to discover the internal IP address by inspecting the network interfaces
|
||||||
func findInternalIP() (net.IP, error) {
|
func findInternalIP() (net.IP, error) {
|
||||||
var ips []net.IP
|
var ips []net.IP
|
||||||
|
|
||||||
|
@ -334,7 +343,7 @@ func findInternalIP() (net.IP, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not a lot else to go on...
|
// Not a lot else to go on...
|
||||||
if !strings.HasPrefix(name, "eth") {
|
if !strings.HasPrefix(name, "eth") && !strings.HasPrefix(name, "en") {
|
||||||
glog.V(2).Infof("Ignoring interface %s - name does not look like ethernet device", name)
|
glog.V(2).Infof("Ignoring interface %s - name does not look like ethernet device", name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -368,11 +377,32 @@ func findInternalIP() (net.IP, error) {
|
||||||
return nil, fmt.Errorf("unable to determine internal ip (no adddresses found)")
|
return nil, fmt.Errorf("unable to determine internal ip (no adddresses found)")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ips) != 1 {
|
if len(ips) == 1 {
|
||||||
glog.Warningf("Found multiple internal IPs; making arbitrary choice")
|
return ips[0], nil
|
||||||
for _, ip := range ips {
|
}
|
||||||
glog.Warningf("\tip: %s", ip.String())
|
|
||||||
|
var ipv4s []net.IP
|
||||||
|
for _, ip := range ips {
|
||||||
|
if ip.To4() != nil {
|
||||||
|
ipv4s = append(ipv4s, ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.Warningf("Found multiple internal IPs")
|
||||||
|
for _, ip := range ips {
|
||||||
|
glog.Warningf("\tip: %s", ip.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ipv4s) != 0 {
|
||||||
|
// TODO: sort?
|
||||||
|
if len(ipv4s) == 1 {
|
||||||
|
glog.Warningf("choosing IPv4 address: %s", ipv4s[0].String())
|
||||||
|
} else {
|
||||||
|
glog.Warningf("arbitrarily choosing IPv4 address: %s", ipv4s[0].String())
|
||||||
|
}
|
||||||
|
return ipv4s[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.Warningf("arbitrarily choosing address: %s", ips[0].String())
|
||||||
return ips[0], nil
|
return ips[0], nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue