Skip to content

Commit 3a58cdd

Browse files
author
louisssgong
committed
check clusterCIDR after occupy serviceCIDR
1 parent 84937ae commit 3a58cdd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/controller/nodeipam/ipam/controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ func NewController(
9292
return nil, err
9393
}
9494

95-
return c, nil
95+
//check whether there is a remaining cidr after occupyServiceCIDR
96+
cidr, err := c.set.AllocateNext()
97+
switch err {
98+
case cidrset.ErrCIDRRangeNoCIDRsRemaining:
99+
return nil, fmt.Errorf("failed after occupy serviceCIDR: %v", err)
100+
case nil:
101+
err := c.set.Release(cidr)
102+
return c, err
103+
default:
104+
return nil, fmt.Errorf("unexpected error when check remaining CIDR range: %v", err)
105+
}
96106
}
97107

98108
// Start initializes the Controller with the existing list of nodes and

pkg/controller/nodeipam/node_ipam_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func TestNewNodeIpamControllerWithCIDRMasks(t *testing.T) {
7777
{"invalid_cluster_CIDR", "invalid", "10.1.0.0/21", 24, ipam.IPAMFromClusterAllocatorType, true},
7878
{"valid_CIDR_smaller_than_mask_cloud_allocator", "10.0.0.0/26", "10.1.0.0/21", 24, ipam.CloudAllocatorType, false},
7979
{"invalid_CIDR_smaller_than_mask_other_allocators", "10.0.0.0/26", "10.1.0.0/21", 24, ipam.IPAMFromCloudAllocatorType, true},
80+
{"invalid_serviceCIDR_contains_clusterCIDR", "10.0.0.0/23", "10.0.0.0/21", 24, ipam.IPAMFromClusterAllocatorType, true},
8081
} {
8182
t.Run(tc.desc, func(t *testing.T) {
8283
clusterCidrs, _ := netutils.ParseCIDRs(strings.Split(tc.clusterCIDR, ","))

0 commit comments

Comments
 (0)