@@ -2665,11 +2665,12 @@ func TestHandlePodResourcesResize(t *testing.T) {
2665
2665
defer kubelet .podManager .RemovePod (testPod1 )
2666
2666
2667
2667
tests := []struct {
2668
- name string
2669
- pod * v1.Pod
2670
- newRequests v1.ResourceList
2671
- expectedAllocations v1.ResourceList
2672
- expectedResize v1.PodResizeStatus
2668
+ name string
2669
+ pod * v1.Pod
2670
+ newRequests v1.ResourceList
2671
+ newRequestsAllocated bool // Whether the new requests have already been allocated (but not actuated)
2672
+ expectedAllocations v1.ResourceList
2673
+ expectedResize v1.PodResizeStatus
2673
2674
}{
2674
2675
{
2675
2676
name : "Request CPU and memory decrease - expect InProgress" ,
@@ -2720,25 +2721,63 @@ func TestHandlePodResourcesResize(t *testing.T) {
2720
2721
expectedAllocations : v1.ResourceList {v1 .ResourceCPU : cpu1000m , v1 .ResourceMemory : mem1000M },
2721
2722
expectedResize : v1 .PodResizeStatusInfeasible ,
2722
2723
},
2724
+ {
2725
+ name : "CPU increase in progress - expect InProgress" ,
2726
+ pod : testPod2 ,
2727
+ newRequests : v1.ResourceList {v1 .ResourceCPU : cpu1500m , v1 .ResourceMemory : mem1000M },
2728
+ newRequestsAllocated : true ,
2729
+ expectedAllocations : v1.ResourceList {v1 .ResourceCPU : cpu1500m , v1 .ResourceMemory : mem1000M },
2730
+ expectedResize : v1 .PodResizeStatusInProgress ,
2731
+ },
2732
+ {
2733
+ name : "No resize" ,
2734
+ pod : testPod2 ,
2735
+ newRequests : v1.ResourceList {v1 .ResourceCPU : cpu1000m , v1 .ResourceMemory : mem1000M },
2736
+ expectedAllocations : v1.ResourceList {v1 .ResourceCPU : cpu1000m , v1 .ResourceMemory : mem1000M },
2737
+ expectedResize : "" ,
2738
+ },
2723
2739
}
2724
2740
2725
2741
for _ , tt := range tests {
2726
2742
t .Run (tt .name , func (t * testing.T ) {
2727
2743
kubelet .statusManager = status .NewFakeManager ()
2728
- require .NoError (t , kubelet .statusManager .SetPodAllocation (tt .pod ))
2729
2744
2730
- pod := tt .pod .DeepCopy ()
2731
- pod .Spec .Containers [0 ].Resources .Requests = tt .newRequests
2732
- updatedPod , err := kubelet .handlePodResourcesResize (pod )
2745
+ newPod := tt .pod .DeepCopy ()
2746
+ newPod .Spec .Containers [0 ].Resources .Requests = tt .newRequests
2747
+
2748
+ if ! tt .newRequestsAllocated {
2749
+ require .NoError (t , kubelet .statusManager .SetPodAllocation (tt .pod ))
2750
+ } else {
2751
+ require .NoError (t , kubelet .statusManager .SetPodAllocation (newPod ))
2752
+ }
2753
+
2754
+ podStatus := & kubecontainer.PodStatus {
2755
+ ID : tt .pod .UID ,
2756
+ Name : tt .pod .Name ,
2757
+ Namespace : tt .pod .Namespace ,
2758
+ ContainerStatuses : make ([]* kubecontainer.Status , len (tt .pod .Spec .Containers )),
2759
+ }
2760
+ for i , c := range tt .pod .Spec .Containers {
2761
+ podStatus .ContainerStatuses [i ] = & kubecontainer.Status {
2762
+ Name : c .Name ,
2763
+ State : kubecontainer .ContainerStateRunning ,
2764
+ Resources : & kubecontainer.ContainerResources {
2765
+ CPURequest : c .Resources .Requests .Cpu (),
2766
+ CPULimit : c .Resources .Limits .Cpu (),
2767
+ MemoryLimit : c .Resources .Limits .Memory (),
2768
+ },
2769
+ }
2770
+ }
2771
+
2772
+ updatedPod , err := kubelet .handlePodResourcesResize (newPod , podStatus )
2733
2773
require .NoError (t , err )
2734
2774
assert .Equal (t , tt .expectedAllocations , updatedPod .Spec .Containers [0 ].Resources .Requests , "updated pod spec resources" )
2735
2775
2736
- alloc , found := kubelet .statusManager .GetContainerResourceAllocation (string (pod .UID ), pod .Spec .Containers [0 ].Name )
2776
+ alloc , found := kubelet .statusManager .GetContainerResourceAllocation (string (newPod .UID ), newPod .Spec .Containers [0 ].Name )
2737
2777
require .True (t , found , "container allocation" )
2738
2778
assert .Equal (t , tt .expectedAllocations , alloc .Requests , "stored container allocation" )
2739
2779
2740
- resizeStatus , found := kubelet .statusManager .GetPodResizeStatus (string (pod .UID ))
2741
- require .True (t , found , "pod resize status" )
2780
+ resizeStatus , _ := kubelet .statusManager .GetPodResizeStatus (string (newPod .UID ))
2742
2781
assert .Equal (t , tt .expectedResize , resizeStatus )
2743
2782
})
2744
2783
}
0 commit comments