mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
range_allocator: Test (lack of) double counting
This commit is contained in:
parent
ee581278bd
commit
c8c81be8af
@ -486,12 +486,55 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
|||||||
NodeCIDRMaskSizes: []int{24, 98, 24},
|
NodeCIDRMaskSizes: []int{24, 98, 24},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "no double counting",
|
||||||
|
fakeNodeHandler: &testutil.FakeNodeHandler{
|
||||||
|
Existing: []*v1.Node{
|
||||||
|
{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node0",
|
||||||
|
},
|
||||||
|
Spec: v1.NodeSpec{
|
||||||
|
PodCIDRs: []string{"10.10.0.0/24"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
Spec: v1.NodeSpec{
|
||||||
|
PodCIDRs: []string{"10.10.2.0/24"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Clientset: fake.NewSimpleClientset(),
|
||||||
|
},
|
||||||
|
allocatorParams: CIDRAllocatorParams{
|
||||||
|
ClusterCIDRs: func() []*net.IPNet {
|
||||||
|
_, clusterCIDR, _ := net.ParseCIDR("10.10.0.0/22")
|
||||||
|
return []*net.IPNet{clusterCIDR}
|
||||||
|
}(),
|
||||||
|
ServiceCIDR: nil,
|
||||||
|
SecondaryServiceCIDR: nil,
|
||||||
|
NodeCIDRMaskSizes: []int{24},
|
||||||
|
},
|
||||||
|
expectedAllocatedCIDR: map[int]string{
|
||||||
|
0: "10.10.1.0/24",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// test function
|
// test function
|
||||||
testFunc := func(tc testCase) {
|
testFunc := func(tc testCase) {
|
||||||
|
fakeNodeInformer := getFakeNodeInformer(tc.fakeNodeHandler)
|
||||||
|
nodeList, _ := tc.fakeNodeHandler.List(context.TODO(), metav1.ListOptions{})
|
||||||
// Initialize the range allocator.
|
// Initialize the range allocator.
|
||||||
allocator, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, getFakeNodeInformer(tc.fakeNodeHandler), tc.allocatorParams, nil)
|
allocator, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, fakeNodeInformer, tc.allocatorParams, nodeList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v: failed to create CIDRRangeAllocator with error %v", tc.description, err)
|
t.Errorf("%v: failed to create CIDRRangeAllocator with error %v", tc.description, err)
|
||||||
return
|
return
|
||||||
@ -517,12 +560,22 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
|
|||||||
t.Fatalf("%v: unexpected error when occupying CIDR %v: %v", tc.description, allocated, err)
|
t.Fatalf("%v: unexpected error when occupying CIDR %v: %v", tc.description, allocated, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := allocator.AllocateOrOccupyCIDR(tc.fakeNodeHandler.Existing[0]); err != nil {
|
}
|
||||||
|
|
||||||
|
updateCount := 0
|
||||||
|
for _, node := range tc.fakeNodeHandler.Existing {
|
||||||
|
if node.Spec.PodCIDRs == nil {
|
||||||
|
updateCount++
|
||||||
|
}
|
||||||
|
if err := allocator.AllocateOrOccupyCIDR(node); err != nil {
|
||||||
t.Errorf("%v: unexpected error in AllocateOrOccupyCIDR: %v", tc.description, err)
|
t.Errorf("%v: unexpected error in AllocateOrOccupyCIDR: %v", tc.description, err)
|
||||||
}
|
}
|
||||||
if err := waitForUpdatedNodeWithTimeout(tc.fakeNodeHandler, 1, wait.ForeverTestTimeout); err != nil {
|
|
||||||
t.Fatalf("%v: timeout while waiting for Node update: %v", tc.description, err)
|
|
||||||
}
|
}
|
||||||
|
if updateCount != 1 {
|
||||||
|
t.Fatalf("test error: all tests must update exactly one node")
|
||||||
|
}
|
||||||
|
if err := waitForUpdatedNodeWithTimeout(tc.fakeNodeHandler, updateCount, wait.ForeverTestTimeout); err != nil {
|
||||||
|
t.Fatalf("%v: timeout while waiting for Node update: %v", tc.description, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tc.expectedAllocatedCIDR) == 0 {
|
if len(tc.expectedAllocatedCIDR) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user