@@ -2447,8 +2447,8 @@ func TestPodResourceAllocationReset(t *testing.T) {
2447
2447
name : "Having both memory and cpu, resource allocation not exists" ,
2448
2448
pod : podWithUIDNameNsSpec ("1" , "pod1" , "foo" , * cpu500mMem500MPodSpec ),
2449
2449
expectedPodResourceAllocation : state.PodResourceAllocation {
2450
- "1" : map [string ]v1.ResourceList {
2451
- cpu500mMem500MPodSpec .Containers [0 ].Name : cpu500mMem500MPodSpec .Containers [0 ].Resources . Requests ,
2450
+ "1" : map [string ]v1.ResourceRequirements {
2451
+ cpu500mMem500MPodSpec .Containers [0 ].Name : cpu500mMem500MPodSpec .Containers [0 ].Resources ,
2452
2452
},
2453
2453
},
2454
2454
},
@@ -2457,8 +2457,8 @@ func TestPodResourceAllocationReset(t *testing.T) {
2457
2457
pod : podWithUIDNameNsSpec ("2" , "pod2" , "foo" , * cpu500mMem500MPodSpec ),
2458
2458
existingPodAllocation : podWithUIDNameNsSpec ("2" , "pod2" , "foo" , * cpu500mMem500MPodSpec ),
2459
2459
expectedPodResourceAllocation : state.PodResourceAllocation {
2460
- "2" : map [string ]v1.ResourceList {
2461
- cpu500mMem500MPodSpec .Containers [0 ].Name : cpu500mMem500MPodSpec .Containers [0 ].Resources . Requests ,
2460
+ "2" : map [string ]v1.ResourceRequirements {
2461
+ cpu500mMem500MPodSpec .Containers [0 ].Name : cpu500mMem500MPodSpec .Containers [0 ].Resources ,
2462
2462
},
2463
2463
},
2464
2464
},
@@ -2467,17 +2467,17 @@ func TestPodResourceAllocationReset(t *testing.T) {
2467
2467
pod : podWithUIDNameNsSpec ("3" , "pod3" , "foo" , * cpu500mMem500MPodSpec ),
2468
2468
existingPodAllocation : podWithUIDNameNsSpec ("3" , "pod3" , "foo" , * cpu800mMem800MPodSpec ),
2469
2469
expectedPodResourceAllocation : state.PodResourceAllocation {
2470
- "3" : map [string ]v1.ResourceList {
2471
- cpu800mMem800MPodSpec .Containers [0 ].Name : cpu800mMem800MPodSpec .Containers [0 ].Resources . Requests ,
2470
+ "3" : map [string ]v1.ResourceRequirements {
2471
+ cpu800mMem800MPodSpec .Containers [0 ].Name : cpu800mMem800MPodSpec .Containers [0 ].Resources ,
2472
2472
},
2473
2473
},
2474
2474
},
2475
2475
{
2476
2476
name : "Only has cpu, resource allocation not exists" ,
2477
2477
pod : podWithUIDNameNsSpec ("4" , "pod5" , "foo" , * cpu500mPodSpec ),
2478
2478
expectedPodResourceAllocation : state.PodResourceAllocation {
2479
- "4" : map [string ]v1.ResourceList {
2480
- cpu500mPodSpec .Containers [0 ].Name : cpu500mPodSpec .Containers [0 ].Resources . Requests ,
2479
+ "4" : map [string ]v1.ResourceRequirements {
2480
+ cpu500mPodSpec .Containers [0 ].Name : cpu500mPodSpec .Containers [0 ].Resources ,
2481
2481
},
2482
2482
},
2483
2483
},
@@ -2486,8 +2486,8 @@ func TestPodResourceAllocationReset(t *testing.T) {
2486
2486
pod : podWithUIDNameNsSpec ("5" , "pod5" , "foo" , * cpu500mPodSpec ),
2487
2487
existingPodAllocation : podWithUIDNameNsSpec ("5" , "pod5" , "foo" , * cpu500mPodSpec ),
2488
2488
expectedPodResourceAllocation : state.PodResourceAllocation {
2489
- "5" : map [string ]v1.ResourceList {
2490
- cpu500mPodSpec .Containers [0 ].Name : cpu500mPodSpec .Containers [0 ].Resources . Requests ,
2489
+ "5" : map [string ]v1.ResourceRequirements {
2490
+ cpu500mPodSpec .Containers [0 ].Name : cpu500mPodSpec .Containers [0 ].Resources ,
2491
2491
},
2492
2492
},
2493
2493
},
@@ -2496,17 +2496,17 @@ func TestPodResourceAllocationReset(t *testing.T) {
2496
2496
pod : podWithUIDNameNsSpec ("6" , "pod6" , "foo" , * cpu500mPodSpec ),
2497
2497
existingPodAllocation : podWithUIDNameNsSpec ("6" , "pod6" , "foo" , * cpu800mPodSpec ),
2498
2498
expectedPodResourceAllocation : state.PodResourceAllocation {
2499
- "6" : map [string ]v1.ResourceList {
2500
- cpu800mPodSpec .Containers [0 ].Name : cpu800mPodSpec .Containers [0 ].Resources . Requests ,
2499
+ "6" : map [string ]v1.ResourceRequirements {
2500
+ cpu800mPodSpec .Containers [0 ].Name : cpu800mPodSpec .Containers [0 ].Resources ,
2501
2501
},
2502
2502
},
2503
2503
},
2504
2504
{
2505
2505
name : "Only has memory, resource allocation not exists" ,
2506
2506
pod : podWithUIDNameNsSpec ("7" , "pod7" , "foo" , * mem500MPodSpec ),
2507
2507
expectedPodResourceAllocation : state.PodResourceAllocation {
2508
- "7" : map [string ]v1.ResourceList {
2509
- mem500MPodSpec .Containers [0 ].Name : mem500MPodSpec .Containers [0 ].Resources . Requests ,
2508
+ "7" : map [string ]v1.ResourceRequirements {
2509
+ mem500MPodSpec .Containers [0 ].Name : mem500MPodSpec .Containers [0 ].Resources ,
2510
2510
},
2511
2511
},
2512
2512
},
@@ -2515,8 +2515,8 @@ func TestPodResourceAllocationReset(t *testing.T) {
2515
2515
pod : podWithUIDNameNsSpec ("8" , "pod8" , "foo" , * mem500MPodSpec ),
2516
2516
existingPodAllocation : podWithUIDNameNsSpec ("8" , "pod8" , "foo" , * mem500MPodSpec ),
2517
2517
expectedPodResourceAllocation : state.PodResourceAllocation {
2518
- "8" : map [string ]v1.ResourceList {
2519
- mem500MPodSpec .Containers [0 ].Name : mem500MPodSpec .Containers [0 ].Resources . Requests ,
2518
+ "8" : map [string ]v1.ResourceRequirements {
2519
+ mem500MPodSpec .Containers [0 ].Name : mem500MPodSpec .Containers [0 ].Resources ,
2520
2520
},
2521
2521
},
2522
2522
},
@@ -2525,17 +2525,17 @@ func TestPodResourceAllocationReset(t *testing.T) {
2525
2525
pod : podWithUIDNameNsSpec ("9" , "pod9" , "foo" , * mem500MPodSpec ),
2526
2526
existingPodAllocation : podWithUIDNameNsSpec ("9" , "pod9" , "foo" , * mem800MPodSpec ),
2527
2527
expectedPodResourceAllocation : state.PodResourceAllocation {
2528
- "9" : map [string ]v1.ResourceList {
2529
- mem800MPodSpec .Containers [0 ].Name : mem800MPodSpec .Containers [0 ].Resources . Requests ,
2528
+ "9" : map [string ]v1.ResourceRequirements {
2529
+ mem800MPodSpec .Containers [0 ].Name : mem800MPodSpec .Containers [0 ].Resources ,
2530
2530
},
2531
2531
},
2532
2532
},
2533
2533
{
2534
2534
name : "No CPU and memory, resource allocation not exists" ,
2535
2535
pod : podWithUIDNameNsSpec ("10" , "pod10" , "foo" , * emptyPodSpec ),
2536
2536
expectedPodResourceAllocation : state.PodResourceAllocation {
2537
- "10" : map [string ]v1.ResourceList {
2538
- emptyPodSpec .Containers [0 ].Name : emptyPodSpec .Containers [0 ].Resources . Requests ,
2537
+ "10" : map [string ]v1.ResourceRequirements {
2538
+ emptyPodSpec .Containers [0 ].Name : emptyPodSpec .Containers [0 ].Resources ,
2539
2539
},
2540
2540
},
2541
2541
},
@@ -2544,27 +2544,29 @@ func TestPodResourceAllocationReset(t *testing.T) {
2544
2544
pod : podWithUIDNameNsSpec ("11" , "pod11" , "foo" , * emptyPodSpec ),
2545
2545
existingPodAllocation : podWithUIDNameNsSpec ("11" , "pod11" , "foo" , * emptyPodSpec ),
2546
2546
expectedPodResourceAllocation : state.PodResourceAllocation {
2547
- "11" : map [string ]v1.ResourceList {
2548
- emptyPodSpec .Containers [0 ].Name : emptyPodSpec .Containers [0 ].Resources . Requests ,
2547
+ "11" : map [string ]v1.ResourceRequirements {
2548
+ emptyPodSpec .Containers [0 ].Name : emptyPodSpec .Containers [0 ].Resources ,
2549
2549
},
2550
2550
},
2551
2551
},
2552
2552
}
2553
2553
for _ , tc := range tests {
2554
- if tc .existingPodAllocation != nil {
2555
- // when kubelet restarts, AllocatedResources has already existed before adding pod
2556
- err := kubelet .statusManager .SetPodAllocation (tc .existingPodAllocation )
2557
- if err != nil {
2558
- t .Fatalf ("failed to set pod allocation: %v" , err )
2554
+ t .Run (tc .name , func (t * testing.T ) {
2555
+ if tc .existingPodAllocation != nil {
2556
+ // when kubelet restarts, AllocatedResources has already existed before adding pod
2557
+ err := kubelet .statusManager .SetPodAllocation (tc .existingPodAllocation )
2558
+ if err != nil {
2559
+ t .Fatalf ("failed to set pod allocation: %v" , err )
2560
+ }
2559
2561
}
2560
- }
2561
- kubelet .HandlePodAdditions ([]* v1.Pod {tc .pod })
2562
+ kubelet .HandlePodAdditions ([]* v1.Pod {tc .pod })
2562
2563
2563
- allocatedResources , found := kubelet .statusManager .GetContainerResourceAllocation (string (tc .pod .UID ), tc .pod .Spec .Containers [0 ].Name )
2564
- if ! found {
2565
- t .Fatalf ("resource allocation should exist: (pod: %#v, container: %s)" , tc .pod , tc .pod .Spec .Containers [0 ].Name )
2566
- }
2567
- assert .Equal (t , tc .expectedPodResourceAllocation [string (tc .pod .UID )][tc .pod .Spec .Containers [0 ].Name ], allocatedResources , tc .name )
2564
+ allocatedResources , found := kubelet .statusManager .GetContainerResourceAllocation (string (tc .pod .UID ), tc .pod .Spec .Containers [0 ].Name )
2565
+ if ! found {
2566
+ t .Fatalf ("resource allocation should exist: (pod: %#v, container: %s)" , tc .pod , tc .pod .Spec .Containers [0 ].Name )
2567
+ }
2568
+ assert .Equal (t , tc .expectedPodResourceAllocation [string (tc .pod .UID )][tc .pod .Spec .Containers [0 ].Name ], allocatedResources , tc .name )
2569
+ })
2568
2570
}
2569
2571
}
2570
2572
0 commit comments