mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Allow multiple node cidr masks in cm
update tests add comment amend var name update comment add check for empty slice fix tests fix mask size in test review feedback add ipv4 and ipv6 flag for mask sizes add to violation exception list remove import alias run update-openapi-spec review feedback run update-bazel review feedback review feedback
This commit is contained in:
@@ -88,8 +88,21 @@ type CIDRAllocator interface {
|
||||
Run(stopCh <-chan struct{})
|
||||
}
|
||||
|
||||
// CIDRAllocatorParams is parameters that's required for creating new
|
||||
// cidr range allocator.
|
||||
type CIDRAllocatorParams struct {
|
||||
// ClusterCIDRs is list of cluster cidrs
|
||||
ClusterCIDRs []*net.IPNet
|
||||
// ServiceCIDR is primary service cidr for cluster
|
||||
ServiceCIDR *net.IPNet
|
||||
// SecondaryServiceCIDR is secondary service cidr for cluster
|
||||
SecondaryServiceCIDR *net.IPNet
|
||||
// NodeCIDRMaskSizes is list of node cidr mask sizes
|
||||
NodeCIDRMaskSizes []int
|
||||
}
|
||||
|
||||
// New creates a new CIDR range allocator.
|
||||
func New(kubeClient clientset.Interface, cloud cloudprovider.Interface, nodeInformer informers.NodeInformer, allocatorType CIDRAllocatorType, clusterCIDRs []*net.IPNet, serviceCIDR *net.IPNet, secondaryServiceCIDR *net.IPNet, nodeCIDRMaskSize int) (CIDRAllocator, error) {
|
||||
func New(kubeClient clientset.Interface, cloud cloudprovider.Interface, nodeInformer informers.NodeInformer, allocatorType CIDRAllocatorType, allocatorParams CIDRAllocatorParams) (CIDRAllocator, error) {
|
||||
nodeList, err := listNodes(kubeClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,7 +110,7 @@ func New(kubeClient clientset.Interface, cloud cloudprovider.Interface, nodeInfo
|
||||
|
||||
switch allocatorType {
|
||||
case RangeAllocatorType:
|
||||
return NewCIDRRangeAllocator(kubeClient, nodeInformer, clusterCIDRs, serviceCIDR, secondaryServiceCIDR, nodeCIDRMaskSize, nodeList)
|
||||
return NewCIDRRangeAllocator(kubeClient, nodeInformer, allocatorParams, nodeList)
|
||||
case CloudAllocatorType:
|
||||
return NewCloudCIDRAllocator(kubeClient, cloud, nodeInformer)
|
||||
default:
|
||||
|
||||
@@ -43,6 +43,8 @@ const (
|
||||
// The subnet mask size cannot be greater than 16 more than the cluster mask size
|
||||
// TODO: https://github.com/kubernetes/kubernetes/issues/44918
|
||||
// clusterSubnetMaxDiff limited to 16 due to the uncompressed bitmap
|
||||
// Due to this limitation the subnet mask for IPv6 cluster cidr needs to be >= 48
|
||||
// as default mask size for IPv6 is 64.
|
||||
clusterSubnetMaxDiff = 16
|
||||
// halfIPv6Len is the half of the IPv6 length
|
||||
halfIPv6Len = net.IPv6len / 2
|
||||
|
||||
@@ -21,9 +21,9 @@ import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/klog"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
@@ -71,7 +71,7 @@ type rangeAllocator struct {
|
||||
// Caller must always pass in a list of existing nodes so the new allocator.
|
||||
// Caller must ensure that ClusterCIDRs are semantically correct e.g (1 for non DualStack, 2 for DualStack etc..)
|
||||
// can initialize its CIDR map. NodeList is only nil in testing.
|
||||
func NewCIDRRangeAllocator(client clientset.Interface, nodeInformer informers.NodeInformer, clusterCIDRs []*net.IPNet, serviceCIDR *net.IPNet, secondaryServiceCIDR *net.IPNet, subNetMaskSize int, nodeList *v1.NodeList) (CIDRAllocator, error) {
|
||||
func NewCIDRRangeAllocator(client clientset.Interface, nodeInformer informers.NodeInformer, allocatorParams CIDRAllocatorParams, nodeList *v1.NodeList) (CIDRAllocator, error) {
|
||||
if client == nil {
|
||||
klog.Fatalf("kubeClient is nil when starting NodeController")
|
||||
}
|
||||
@@ -84,9 +84,9 @@ func NewCIDRRangeAllocator(client clientset.Interface, nodeInformer informers.No
|
||||
|
||||
// create a cidrSet for each cidr we operate on
|
||||
// cidrSet are mapped to clusterCIDR by index
|
||||
cidrSets := make([]*cidrset.CidrSet, len(clusterCIDRs))
|
||||
for idx, cidr := range clusterCIDRs {
|
||||
cidrSet, err := cidrset.NewCIDRSet(cidr, subNetMaskSize)
|
||||
cidrSets := make([]*cidrset.CidrSet, len(allocatorParams.ClusterCIDRs))
|
||||
for idx, cidr := range allocatorParams.ClusterCIDRs {
|
||||
cidrSet, err := cidrset.NewCIDRSet(cidr, allocatorParams.NodeCIDRMaskSizes[idx])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func NewCIDRRangeAllocator(client clientset.Interface, nodeInformer informers.No
|
||||
|
||||
ra := &rangeAllocator{
|
||||
client: client,
|
||||
clusterCIDRs: clusterCIDRs,
|
||||
clusterCIDRs: allocatorParams.ClusterCIDRs,
|
||||
cidrSets: cidrSets,
|
||||
nodeLister: nodeInformer.Lister(),
|
||||
nodesSynced: nodeInformer.Informer().HasSynced,
|
||||
@@ -104,14 +104,14 @@ func NewCIDRRangeAllocator(client clientset.Interface, nodeInformer informers.No
|
||||
nodesInProcessing: sets.NewString(),
|
||||
}
|
||||
|
||||
if serviceCIDR != nil {
|
||||
ra.filterOutServiceRange(serviceCIDR)
|
||||
if allocatorParams.ServiceCIDR != nil {
|
||||
ra.filterOutServiceRange(allocatorParams.ServiceCIDR)
|
||||
} else {
|
||||
klog.V(0).Info("No Service CIDR provided. Skipping filtering out service addresses.")
|
||||
}
|
||||
|
||||
if secondaryServiceCIDR != nil {
|
||||
ra.filterOutServiceRange(secondaryServiceCIDR)
|
||||
if allocatorParams.SecondaryServiceCIDR != nil {
|
||||
ra.filterOutServiceRange(allocatorParams.SecondaryServiceCIDR)
|
||||
} else {
|
||||
klog.V(0).Info("No Secondary Service CIDR provided. Skipping filtering out secondary service addresses.")
|
||||
}
|
||||
|
||||
@@ -60,12 +60,9 @@ func getFakeNodeInformer(fakeNodeHandler *testutil.FakeNodeHandler) coreinformer
|
||||
}
|
||||
|
||||
type testCase struct {
|
||||
description string
|
||||
fakeNodeHandler *testutil.FakeNodeHandler
|
||||
clusterCIDRs []*net.IPNet
|
||||
serviceCIDR *net.IPNet
|
||||
secondaryServiceCIDR *net.IPNet
|
||||
subNetMaskSize int
|
||||
description string
|
||||
fakeNodeHandler *testutil.FakeNodeHandler
|
||||
allocatorParams CIDRAllocatorParams
|
||||
// key is index of the cidr allocated
|
||||
expectedAllocatedCIDR map[int]string
|
||||
allocatedCIDRs map[int][]string
|
||||
@@ -88,13 +85,15 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: false,
|
||||
@@ -111,14 +110,16 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24, 24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: false,
|
||||
@@ -138,13 +139,15 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: false,
|
||||
@@ -164,14 +167,16 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24, 24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: false,
|
||||
@@ -192,13 +197,15 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: true,
|
||||
@@ -219,13 +226,15 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
return []*net.IPNet{clusterCIDRv4}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: true,
|
||||
@@ -246,14 +255,16 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24, 24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: true,
|
||||
@@ -274,14 +285,16 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 24,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("10.10.0.0/16")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24, 24},
|
||||
},
|
||||
allocatedCIDRs: nil,
|
||||
expectedAllocatedCIDR: nil,
|
||||
ctrlCreateFail: true,
|
||||
@@ -294,7 +307,7 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
// Initialize the range allocator.
|
||||
fakeNodeInformer := getFakeNodeInformer(tc.fakeNodeHandler)
|
||||
nodeList, _ := tc.fakeNodeHandler.List(metav1.ListOptions{})
|
||||
_, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, fakeNodeInformer, tc.clusterCIDRs, tc.serviceCIDR, tc.secondaryServiceCIDR, tc.subNetMaskSize, nodeList)
|
||||
_, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, fakeNodeInformer, tc.allocatorParams, nodeList)
|
||||
if err == nil && tc.ctrlCreateFail {
|
||||
t.Fatalf("creating range allocator was expected to fail, but it did not")
|
||||
}
|
||||
@@ -320,13 +333,15 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/24")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 30,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/24")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{30},
|
||||
},
|
||||
expectedAllocatedCIDR: map[int]string{
|
||||
0: "127.123.234.0/30",
|
||||
},
|
||||
@@ -343,16 +358,18 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/24")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
serviceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 30,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/24")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
ServiceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{30},
|
||||
},
|
||||
// it should return first /30 CIDR after service range
|
||||
expectedAllocatedCIDR: map[int]string{
|
||||
0: "127.123.234.64/30",
|
||||
@@ -370,16 +387,18 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/24")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
serviceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 30,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/24")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
ServiceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{30},
|
||||
},
|
||||
allocatedCIDRs: map[int][]string{
|
||||
0: {"127.123.234.64/30", "127.123.234.68/30", "127.123.234.72/30", "127.123.234.80/30"},
|
||||
},
|
||||
@@ -399,16 +418,19 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("127.123.234.0/8")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
serviceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
secondaryServiceCIDR: nil,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("127.123.234.0/8")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/84")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6}
|
||||
}(),
|
||||
ServiceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24, 98},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Dualstack CIDRs v6,v4",
|
||||
@@ -422,18 +444,20 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("127.123.234.0/8")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
return []*net.IPNet{clusterCIDRv6, clusterCIDRv4}
|
||||
}(),
|
||||
serviceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
secondaryServiceCIDR: nil,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("127.123.234.0/8")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/84")
|
||||
return []*net.IPNet{clusterCIDRv6, clusterCIDRv4}
|
||||
}(),
|
||||
ServiceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{98, 24},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
description: "Dualstack CIDRs, more than two",
|
||||
fakeNodeHandler: &testutil.FakeNodeHandler{
|
||||
@@ -446,24 +470,27 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("127.123.234.0/8")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/8")
|
||||
_, clusterCIDRv4_2, _ := net.ParseCIDR("10.0.0.0/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6, clusterCIDRv4_2}
|
||||
}(),
|
||||
serviceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
secondaryServiceCIDR: nil,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDRv4, _ := net.ParseCIDR("127.123.234.0/8")
|
||||
_, clusterCIDRv6, _ := net.ParseCIDR("ace:cab:deca::/84")
|
||||
_, clusterCIDRv4_2, _ := net.ParseCIDR("10.0.0.0/8")
|
||||
return []*net.IPNet{clusterCIDRv4, clusterCIDRv6, clusterCIDRv4_2}
|
||||
}(),
|
||||
ServiceCIDR: func() *net.IPNet {
|
||||
_, serviceCIDR, _ := net.ParseCIDR("127.123.234.0/26")
|
||||
return serviceCIDR
|
||||
}(),
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{24, 98, 24},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// test function
|
||||
testFunc := func(tc testCase) {
|
||||
// Initialize the range allocator.
|
||||
allocator, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.clusterCIDRs, tc.serviceCIDR, tc.secondaryServiceCIDR, tc.subNetMaskSize, nil)
|
||||
allocator, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.allocatorParams, nil)
|
||||
if err != nil {
|
||||
t.Errorf("%v: failed to create CIDRRangeAllocator with error %v", tc.description, err)
|
||||
return
|
||||
@@ -535,13 +562,15 @@ func TestAllocateOrOccupyCIDRFailure(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/28")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 30,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/28")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{30},
|
||||
},
|
||||
allocatedCIDRs: map[int][]string{
|
||||
0: {"127.123.234.0/30", "127.123.234.4/30", "127.123.234.8/30", "127.123.234.12/30"},
|
||||
},
|
||||
@@ -550,7 +579,7 @@ func TestAllocateOrOccupyCIDRFailure(t *testing.T) {
|
||||
|
||||
testFunc := func(tc testCase) {
|
||||
// Initialize the range allocator.
|
||||
allocator, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.clusterCIDRs, tc.serviceCIDR, tc.secondaryServiceCIDR, tc.subNetMaskSize, nil)
|
||||
allocator, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.allocatorParams, nil)
|
||||
if err != nil {
|
||||
t.Logf("%v: failed to create CIDRRangeAllocator with error %v", tc.description, err)
|
||||
}
|
||||
@@ -609,10 +638,7 @@ func TestAllocateOrOccupyCIDRFailure(t *testing.T) {
|
||||
type releaseTestCase struct {
|
||||
description string
|
||||
fakeNodeHandler *testutil.FakeNodeHandler
|
||||
clusterCIDRs []*net.IPNet
|
||||
serviceCIDR *net.IPNet
|
||||
secondaryServiceCIDR *net.IPNet
|
||||
subNetMaskSize int
|
||||
allocatorParams CIDRAllocatorParams
|
||||
expectedAllocatedCIDRFirstRound map[int]string
|
||||
expectedAllocatedCIDRSecondRound map[int]string
|
||||
allocatedCIDRs map[int][]string
|
||||
@@ -633,13 +659,15 @@ func TestReleaseCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/28")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 30,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/28")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{30},
|
||||
},
|
||||
allocatedCIDRs: map[int][]string{
|
||||
0: {"127.123.234.0/30", "127.123.234.4/30", "127.123.234.8/30", "127.123.234.12/30"},
|
||||
},
|
||||
@@ -663,13 +691,15 @@ func TestReleaseCIDRSuccess(t *testing.T) {
|
||||
},
|
||||
Clientset: fake.NewSimpleClientset(),
|
||||
},
|
||||
clusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/28")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
serviceCIDR: nil,
|
||||
secondaryServiceCIDR: nil,
|
||||
subNetMaskSize: 30,
|
||||
allocatorParams: CIDRAllocatorParams{
|
||||
ClusterCIDRs: func() []*net.IPNet {
|
||||
_, clusterCIDR, _ := net.ParseCIDR("127.123.234.0/28")
|
||||
return []*net.IPNet{clusterCIDR}
|
||||
}(),
|
||||
ServiceCIDR: nil,
|
||||
SecondaryServiceCIDR: nil,
|
||||
NodeCIDRMaskSizes: []int{30},
|
||||
},
|
||||
allocatedCIDRs: map[int][]string{
|
||||
0: {"127.123.234.4/30", "127.123.234.8/30", "127.123.234.12/30"},
|
||||
},
|
||||
@@ -687,7 +717,7 @@ func TestReleaseCIDRSuccess(t *testing.T) {
|
||||
|
||||
testFunc := func(tc releaseTestCase) {
|
||||
// Initialize the range allocator.
|
||||
allocator, _ := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.clusterCIDRs, tc.serviceCIDR, tc.secondaryServiceCIDR, tc.subNetMaskSize, nil)
|
||||
allocator, _ := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.allocatorParams, nil)
|
||||
rangeAllocator, ok := allocator.(*rangeAllocator)
|
||||
if !ok {
|
||||
t.Logf("%v: found non-default implementation of CIDRAllocator, skipping white-box test...", tc.description)
|
||||
|
||||
Reference in New Issue
Block a user