mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	fix review
This commit is contained in:
		@@ -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.")
 | 
			
		||||
		var nodeIP net.IP
 | 
			
		||||
		if config.BindAddress != "0.0.0.0" {
 | 
			
		||||
			nodeIP := net.ParseIP(config.BindAddress)
 | 
			
		||||
		if local, _ := isLocalIP(nodeIP); !local {
 | 
			
		||||
			glog.V(2).Infof("bind-address %s must be local ip", 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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user