@@ -2920,6 +2920,40 @@ func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, string, string) {
2920
2920
return true , "" , ""
2921
2921
}
2922
2922
2923
+ func disallowResizeForSwappableContainers (runtime kubecontainer.Runtime , desiredPod , allocatedPod * v1.Pod ) (bool , string ) {
2924
+ if desiredPod == nil || allocatedPod == nil {
2925
+ return false , ""
2926
+ }
2927
+ restartableMemoryResizePolicy := func (resizePolicies []v1.ContainerResizePolicy ) bool {
2928
+ for _ , policy := range resizePolicies {
2929
+ if policy .ResourceName == v1 .ResourceMemory {
2930
+ return policy .RestartPolicy == v1 .RestartContainer
2931
+ }
2932
+ }
2933
+ return false
2934
+ }
2935
+ allocatedContainers := make (map [string ]v1.Container )
2936
+ for _ , container := range append (allocatedPod .Spec .Containers , allocatedPod .Spec .InitContainers ... ) {
2937
+ allocatedContainers [container .Name ] = container
2938
+ }
2939
+ for _ , desiredContainer := range append (desiredPod .Spec .Containers , desiredPod .Spec .InitContainers ... ) {
2940
+ allocatedContainer , ok := allocatedContainers [desiredContainer .Name ]
2941
+ if ! ok {
2942
+ continue
2943
+ }
2944
+ origMemRequest := desiredContainer .Resources .Requests [v1 .ResourceMemory ]
2945
+ newMemRequest := allocatedContainer .Resources .Requests [v1 .ResourceMemory ]
2946
+ if ! origMemRequest .Equal (newMemRequest ) && ! restartableMemoryResizePolicy (allocatedContainer .ResizePolicy ) {
2947
+ aSwapBehavior := runtime .GetContainerSwapBehavior (desiredPod , & desiredContainer )
2948
+ bSwapBehavior := runtime .GetContainerSwapBehavior (allocatedPod , & allocatedContainer )
2949
+ if aSwapBehavior != kubetypes .NoSwap || bSwapBehavior != kubetypes .NoSwap {
2950
+ return true , "In-place resize of containers with swap is not supported."
2951
+ }
2952
+ }
2953
+ }
2954
+ return false , ""
2955
+ }
2956
+
2923
2957
// handlePodResourcesResize returns the "allocated pod", which should be used for all resource
2924
2958
// calculations after this function is called. It also updates the cached ResizeStatus according to
2925
2959
// the allocation decision and pod status.
@@ -2949,6 +2983,10 @@ func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod, podStatus *kubecontaine
2949
2983
// If there is a pending resize but the resize is not allowed, always use the allocated resources.
2950
2984
kl .statusManager .SetPodResizePendingCondition (pod .UID , v1 .PodReasonInfeasible , msg )
2951
2985
return podFromAllocation , nil
2986
+ } else if resizeNotAllowed , msg := disallowResizeForSwappableContainers (kl .containerRuntime , pod , podFromAllocation ); resizeNotAllowed {
2987
+ // If this resize involve swap recalculation, set as infeasible, as IPPR with swap is not supported for beta.
2988
+ kl .statusManager .SetPodResizePendingCondition (pod .UID , v1 .PodReasonInfeasible , msg )
2989
+ return podFromAllocation , nil
2952
2990
}
2953
2991
2954
2992
kl .podResizeMutex .Lock ()
0 commit comments