mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
fix review
This commit is contained in:
parent
1965157b49
commit
58d0596c23
@ -399,19 +399,10 @@ func NewProxyServer(config *componentconfig.KubeProxyConfiguration, cleanupAndEx
|
|||||||
proxyMode := getProxyMode(string(config.Mode), iptInterface, iptables.LinuxKernelCompatTester{})
|
proxyMode := getProxyMode(string(config.Mode), iptInterface, iptables.LinuxKernelCompatTester{})
|
||||||
if proxyMode == proxyModeIPTables {
|
if proxyMode == proxyModeIPTables {
|
||||||
glog.V(0).Info("Using iptables Proxier.")
|
glog.V(0).Info("Using iptables Proxier.")
|
||||||
var nodeIP net.IP
|
nodeIP := net.ParseIP(config.BindAddress)
|
||||||
if config.BindAddress == "0.0.0.0" || config.BindAddress == "" {
|
if local, _ := isLocalIP(nodeIP); !local {
|
||||||
|
glog.V(2).Infof("bind-address %s must be local ip", config.BindAddress)
|
||||||
nodeIP = getNodeIP(client, hostname)
|
nodeIP = getNodeIP(client, hostname)
|
||||||
} else {
|
|
||||||
nodeIP = net.ParseIP(config.BindAddress)
|
|
||||||
if nodeIP == nil {
|
|
||||||
return nil, fmt.Errorf("bind-address %s must be valid ip", config.BindAddress)
|
|
||||||
}
|
|
||||||
if local, err := isLocalIP(nodeIP.String()); err != nil {
|
|
||||||
return nil, fmt.Errorf("can't determine if IP is local, assuming not: %v", err)
|
|
||||||
} else if !local {
|
|
||||||
return nil, fmt.Errorf("bind-address %s must be local ip", config.BindAddress)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if config.IPTables.MasqueradeBit == nil {
|
if config.IPTables.MasqueradeBit == nil {
|
||||||
// MasqueradeBit must be specified or defaulted.
|
// MasqueradeBit must be specified or defaulted.
|
||||||
@ -714,17 +705,17 @@ func getNodeIP(client clientset.Interface, hostname string) net.IP {
|
|||||||
return nodeIP
|
return nodeIP
|
||||||
}
|
}
|
||||||
|
|
||||||
func isLocalIP(ip string) (bool, error) {
|
func isLocalIP(ip net.IP) (bool, error) {
|
||||||
addrs, err := net.InterfaceAddrs()
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
for i := range addrs {
|
for i := range addrs {
|
||||||
intf, _, err := net.ParseCIDR(addrs[i].String())
|
intfIP, _, err := net.ParseCIDR(addrs[i].String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if net.ParseIP(ip).Equal(intf) {
|
if ip.Equal(intfIP) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user