-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a node has a large subnet, such as a /56 or larger, we need to allocate a /64 subnet for each individual node. Signed-off-by: Serge Logvinov <[email protected]>
- Loading branch information
1 parent
db6c211
commit 68d4133
Showing
13 changed files
with
158 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package ipam | ||
|
||
import ( | ||
"fmt" | ||
"net/netip" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/siderolabs/talos-cloud-controller-manager/pkg/nodeipam/ipam/cidrset" | ||
) | ||
|
||
func TestAddCIDRSet(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
cidr string | ||
expectedError error | ||
expectedSize int | ||
expectedClusterCIDR netip.Prefix | ||
}{ | ||
{ | ||
name: "CIDRv6 with mask size 56", | ||
cidr: "2000::1111:aaaa:bbbb:cccc:123/56", | ||
expectedSize: 1, | ||
expectedClusterCIDR: netip.MustParsePrefix("2000:0:0:1111::/64"), | ||
}, | ||
{ | ||
name: "CIDRv6 with mask size 64", | ||
cidr: "2000::aaaa:bbbb:cccc:123/64", | ||
expectedSize: 1, | ||
expectedClusterCIDR: netip.MustParsePrefix("2000::/64"), | ||
}, | ||
{ | ||
name: "CIDRv6 with mask size 80", | ||
cidr: "2000::aaaa:bbbb:cccc:123/80", | ||
expectedSize: 1, | ||
expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:0:0:0/80"), | ||
}, | ||
{ | ||
name: "CIDRv6 with mask size 96", | ||
cidr: "2000::aaaa:bbbb:cccc:123/96", | ||
expectedSize: 1, | ||
expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:0:0/96"), | ||
}, | ||
{ | ||
name: "CIDRv6 with mask size 112", | ||
cidr: "2000::aaaa:bbbb:cccc:123/112", | ||
expectedSize: 1, | ||
expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:cccc:0/112"), | ||
}, | ||
{ | ||
name: "CIDRv6 with mask size 120", | ||
cidr: "2000::aaaa:bbbb:cccc:123/120", | ||
expectedSize: 1, | ||
expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:cccc:100/120"), | ||
}, | ||
{ | ||
name: "CIDRv6 with mask size 124", | ||
cidr: "2000::aaaa:bbbb:cccc:123/124", | ||
expectedError: fmt.Errorf("CIDRv6 is too small: 2000::aaaa:bbbb:cccc:123/124"), | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cidrSets := make(map[netip.Prefix]*cidrset.CidrSet, 0) | ||
allocator := cloudAllocator{ | ||
cidrSets: cidrSets, | ||
} | ||
err := allocator.addCIDRSet(tt.cidr) | ||
|
||
if tt.expectedError != nil { | ||
assert.Error(t, err) | ||
assert.Equal(t, tt.expectedError, err) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.Len(t, cidrSets, tt.expectedSize) | ||
assert.Contains(t, cidrSets, tt.expectedClusterCIDR, "CIDRSet not found") | ||
assert.NotNil(t, cidrSets[tt.expectedClusterCIDR], "CIDRSet not found") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters