From c25763e159a4560b6a7b794c109255eebbf6385d Mon Sep 17 00:00:00 2001 From: Cezar Sa Espinola Date: Tue, 23 Jul 2019 10:55:38 -0300 Subject: [PATCH] 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. --- pkg/proxy/ipvs/proxier.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index a64408bb2cd..6e665586b56 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -834,15 +834,14 @@ func (proxier *Proxier) syncProxyRules() { if err == nil && nodeAddrSet.Len() > 0 { nodeAddresses = nodeAddrSet.List() for _, address := range nodeAddresses { - if !utilproxy.IsZeroCIDR(address) { - nodeIPs = append(nodeIPs, net.ParseIP(address)) - continue - } - // zero cidr - nodeIPs, err = proxier.ipGetter.NodeIPs() - if err != nil { - klog.Errorf("Failed to list all node IPs from host, err: %v", err) + if utilproxy.IsZeroCIDR(address) { + nodeIPs, err = proxier.ipGetter.NodeIPs() + if err != nil { + klog.Errorf("Failed to list all node IPs from host, err: %v", err) + } + break } + nodeIPs = append(nodeIPs, net.ParseIP(address)) } } }