Skip to content

Commit 2b4f18d

Browse files
authored
Merge pull request kubernetes#77056 from tedyu/cidr
Follow on for Store parsed CIDRs at initialization of Proxier kubernetes#76779
2 parents e6188f8 + 2472d34 commit 2b4f18d

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pkg/proxy/ipvs/proxier.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,17 @@ func (r *realIPGetter) NodeIPs() (ips []net.IP, err error) {
274274
// Proxier implements ProxyProvider
275275
var _ proxy.ProxyProvider = &Proxier{}
276276

277-
// ParseExcludedCIDRs parses the input strings and returns net.IPNet
277+
// parseExcludedCIDRs parses the input strings and returns net.IPNet
278278
// The validation has been done earlier so the error condition will never happen under normal conditions
279-
func ParseExcludedCIDRs(excludeCIDRStrs []string) []*net.IPNet {
279+
func parseExcludedCIDRs(excludeCIDRs []string) []*net.IPNet {
280280
var cidrExclusions []*net.IPNet
281-
for _, excludedCIDR := range excludeCIDRStrs {
281+
for _, excludedCIDR := range excludeCIDRs {
282282
_, n, err := net.ParseCIDR(excludedCIDR)
283-
if err == nil {
284-
cidrExclusions = append(cidrExclusions, n)
283+
if err != nil {
284+
klog.Errorf("Error parsing exclude CIDR %q, err: %v", excludedCIDR, err)
285+
continue
285286
}
287+
cidrExclusions = append(cidrExclusions, n)
286288
}
287289
return cidrExclusions
288290
}
@@ -299,7 +301,7 @@ func NewProxier(ipt utiliptables.Interface,
299301
exec utilexec.Interface,
300302
syncPeriod time.Duration,
301303
minSyncPeriod time.Duration,
302-
excludeCIDRStrs []string,
304+
excludeCIDRs []string,
303305
strictARP bool,
304306
masqueradeAll bool,
305307
masqueradeBit int,
@@ -410,7 +412,7 @@ func NewProxier(ipt utiliptables.Interface,
410412
endpointsChanges: proxy.NewEndpointChangeTracker(hostname, nil, &isIPv6, recorder),
411413
syncPeriod: syncPeriod,
412414
minSyncPeriod: minSyncPeriod,
413-
excludeCIDRs: ParseExcludedCIDRs(excludeCIDRStrs),
415+
excludeCIDRs: parseExcludedCIDRs(excludeCIDRs),
414416
iptables: ipt,
415417
masqueradeAll: masqueradeAll,
416418
masqueradeMark: masqueradeMark,

pkg/proxy/ipvs/proxier_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,7 @@ func TestCleanLegacyService(t *testing.T) {
28232823
ipt := iptablestest.NewFake()
28242824
ipvs := ipvstest.NewFake()
28252825
ipset := ipsettest.NewFake(testIPSetVersion)
2826-
fp := NewFakeProxier(ipt, ipvs, ipset, nil, ParseExcludedCIDRs([]string{"3.3.3.0/24", "4.4.4.0/24"}))
2826+
fp := NewFakeProxier(ipt, ipvs, ipset, nil, parseExcludedCIDRs([]string{"3.3.3.0/24", "4.4.4.0/24"}))
28272827

28282828
// All ipvs services that were processed in the latest sync loop.
28292829
activeServices := map[string]bool{"ipvs0": true, "ipvs1": true}
@@ -2930,7 +2930,7 @@ func TestCleanLegacyRealServersExcludeCIDRs(t *testing.T) {
29302930
ipvs := ipvstest.NewFake()
29312931
ipset := ipsettest.NewFake(testIPSetVersion)
29322932
gtm := NewGracefulTerminationManager(ipvs)
2933-
fp := NewFakeProxier(ipt, ipvs, ipset, nil, ParseExcludedCIDRs([]string{"4.4.4.4/32"}))
2933+
fp := NewFakeProxier(ipt, ipvs, ipset, nil, parseExcludedCIDRs([]string{"4.4.4.4/32"}))
29342934
fp.gracefuldeleteManager = gtm
29352935

29362936
vs := &utilipvs.VirtualServer{
@@ -2984,7 +2984,7 @@ func TestCleanLegacyService6(t *testing.T) {
29842984
ipt := iptablestest.NewFake()
29852985
ipvs := ipvstest.NewFake()
29862986
ipset := ipsettest.NewFake(testIPSetVersion)
2987-
fp := NewFakeProxier(ipt, ipvs, ipset, nil, ParseExcludedCIDRs([]string{"3000::/64", "4000::/64"}))
2987+
fp := NewFakeProxier(ipt, ipvs, ipset, nil, parseExcludedCIDRs([]string{"3000::/64", "4000::/64"}))
29882988
fp.nodeIP = net.ParseIP("::1")
29892989

29902990
// All ipvs services that were processed in the latest sync loop.

0 commit comments

Comments
 (0)