fix review

This commit is contained in:
lichunlong 2017-06-02 15:32:22 +08:00
parent 63bc96e1b0
commit dc768c87c3

View File

@ -401,10 +401,7 @@ func NewProxyServer(config *componentconfig.KubeProxyConfiguration, cleanupAndEx
glog.V(0).Info("Using iptables Proxier.")
var nodeIP net.IP
if config.BindAddress != "0.0.0.0" {
nodeIP := net.ParseIP(config.BindAddress)
if local := isLocalIP(nodeIP); !local {
return nil, fmt.Errorf("invalid bind-address: %v, it must be a local IP", config.BindAddress)
}
nodeIP = net.ParseIP(config.BindAddress)
} else {
nodeIP = getNodeIP(client, hostname)
}
@ -708,20 +705,3 @@ func getNodeIP(client clientset.Interface, hostname string) net.IP {
}
return nodeIP
}
func isLocalIP(ip net.IP) bool {
addrs, err := net.InterfaceAddrs()
if err != nil {
return false
}
for i := range addrs {
intfIP, _, err := net.ParseCIDR(addrs[i].String())
if err != nil {
return false
}
if ip.Equal(intfIP) {
return true
}
}
return false
}