proxy/ipvs: Compute all node ips only once when a zero cidr is used

Computing all node ips twice would always happen when no node port
addresses were explicitly set. The GetNodeAddresses call would return
two zero cidrs (ipv4 and ipv6) and we would then retrieve all node IPs
twice because the loop wouldn't break after the first time.

Also, it is possible for the user to set explicit node port addresses
including both a zero and a non-zero cidr, but this wouldn't make sense
for nodeIPs since the zero cidr would already cause nodeIPs to include
all IPs on the node.
This commit is contained in:
Cezar Sa Espinola 2019-07-23 10:55:38 -03:00
parent 5c16940508
commit c25763e159
No known key found for this signature in database
GPG Key ID: 1A2CF01DB5E14655

View File

@ -834,15 +834,14 @@ func (proxier *Proxier) syncProxyRules() {
if err == nil && nodeAddrSet.Len() > 0 { if err == nil && nodeAddrSet.Len() > 0 {
nodeAddresses = nodeAddrSet.List() nodeAddresses = nodeAddrSet.List()
for _, address := range nodeAddresses { for _, address := range nodeAddresses {
if !utilproxy.IsZeroCIDR(address) { if utilproxy.IsZeroCIDR(address) {
nodeIPs = append(nodeIPs, net.ParseIP(address)) nodeIPs, err = proxier.ipGetter.NodeIPs()
continue if err != nil {
} klog.Errorf("Failed to list all node IPs from host, err: %v", err)
// zero cidr }
nodeIPs, err = proxier.ipGetter.NodeIPs() break
if err != nil {
klog.Errorf("Failed to list all node IPs from host, err: %v", err)
} }
nodeIPs = append(nodeIPs, net.ParseIP(address))
} }
} }
} }