fix review

This commit is contained in:
lichunlong 2017-06-01 17:22:41 +08:00
parent 58d0596c23
commit 63bc96e1b0

View File

@ -399,9 +399,13 @@ func NewProxyServer(config *componentconfig.KubeProxyConfiguration, cleanupAndEx
proxyMode := getProxyMode(string(config.Mode), iptInterface, iptables.LinuxKernelCompatTester{})
if proxyMode == proxyModeIPTables {
glog.V(0).Info("Using iptables Proxier.")
nodeIP := net.ParseIP(config.BindAddress)
if local, _ := isLocalIP(nodeIP); !local {
glog.V(2).Infof("bind-address %s must be local ip", config.BindAddress)
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)
}
} else {
nodeIP = getNodeIP(client, hostname)
}
if config.IPTables.MasqueradeBit == nil {
@ -705,19 +709,19 @@ func getNodeIP(client clientset.Interface, hostname string) net.IP {
return nodeIP
}
func isLocalIP(ip net.IP) (bool, error) {
func isLocalIP(ip net.IP) bool {
addrs, err := net.InterfaceAddrs()
if err != nil {
return false, err
return false
}
for i := range addrs {
intfIP, _, err := net.ParseCIDR(addrs[i].String())
if err != nil {
return false, err
return false
}
if ip.Equal(intfIP) {
return true, nil
return true
}
}
return false, nil
return false
}