mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #80585 from gongguan/check_svcCIDR_contains_clusterCIDR
check whether serviceCIDR contains clusterCIDR during ipam initialization
This commit is contained in:
commit
60ca3c8a57
@ -92,7 +92,17 @@ func NewController(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
//check whether there is a remaining cidr after occupyServiceCIDR
|
||||
cidr, err := c.set.AllocateNext()
|
||||
switch err {
|
||||
case cidrset.ErrCIDRRangeNoCIDRsRemaining:
|
||||
return nil, fmt.Errorf("failed after occupy serviceCIDR: %v", err)
|
||||
case nil:
|
||||
err := c.set.Release(cidr)
|
||||
return c, err
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected error when check remaining CIDR range: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start initializes the Controller with the existing list of nodes and
|
||||
|
@ -77,6 +77,7 @@ func TestNewNodeIpamControllerWithCIDRMasks(t *testing.T) {
|
||||
{"invalid_cluster_CIDR", "invalid", "10.1.0.0/21", 24, ipam.IPAMFromClusterAllocatorType, true},
|
||||
{"valid_CIDR_smaller_than_mask_cloud_allocator", "10.0.0.0/26", "10.1.0.0/21", 24, ipam.CloudAllocatorType, false},
|
||||
{"invalid_CIDR_smaller_than_mask_other_allocators", "10.0.0.0/26", "10.1.0.0/21", 24, ipam.IPAMFromCloudAllocatorType, true},
|
||||
{"invalid_serviceCIDR_contains_clusterCIDR", "10.0.0.0/23", "10.0.0.0/21", 24, ipam.IPAMFromClusterAllocatorType, true},
|
||||
} {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
clusterCidrs, _ := netutils.ParseCIDRs(strings.Split(tc.clusterCIDR, ","))
|
||||
|
Loading…
Reference in New Issue
Block a user