@@ -2863,21 +2863,23 @@ func (kl *Kubelet) HandlePodSyncs(pods []*v1.Pod) {
2863
2863
2864
2864
// canResizePod determines if the requested resize is currently feasible.
2865
2865
// pod should hold the desired (pre-allocated) spec.
2866
- // Returns true if the resize can proceed.
2867
- func (kl * Kubelet ) canResizePod (pod * v1.Pod ) (bool , v1.PodResizeStatus , string ) {
2866
+ // Returns true if the resize can proceed; returns a reason and message
2867
+ // otherwise.
2868
+ func (kl * Kubelet ) canResizePod (pod * v1.Pod ) (bool , string , string ) {
2868
2869
if v1qos .GetPodQOS (pod ) == v1 .PodQOSGuaranteed && ! utilfeature .DefaultFeatureGate .Enabled (features .InPlacePodVerticalScalingExclusiveCPUs ) {
2869
2870
if utilfeature .DefaultFeatureGate .Enabled (features .CPUManager ) {
2870
2871
if kl .containerManager .GetNodeConfig ().CPUManagerPolicy == "static" {
2871
2872
msg := "Resize is infeasible for Guaranteed Pods alongside CPU Manager static policy"
2872
2873
klog .V (3 ).InfoS (msg , "pod" , format .Pod (pod ))
2873
- return false , v1 .PodResizeStatusInfeasible , msg
2874
+ return false , v1 .PodReasonInfeasible , msg
2874
2875
}
2875
2876
}
2876
2877
if utilfeature .DefaultFeatureGate .Enabled (features .MemoryManager ) {
2877
2878
if kl .containerManager .GetNodeConfig ().MemoryManagerPolicy == "Static" {
2878
2879
msg := "Resize is infeasible for Guaranteed Pods alongside Memory Manager static policy"
2879
2880
klog .V (3 ).InfoS (msg , "pod" , format .Pod (pod ))
2880
- return false , v1 .PodResizeStatusInfeasible , msg
2881
+ return false , v1 .PodReasonInfeasible , msg
2882
+
2881
2883
}
2882
2884
}
2883
2885
}
@@ -2900,7 +2902,8 @@ func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus, string)
2900
2902
}
2901
2903
msg = "Node didn't have enough capacity: " + msg
2902
2904
klog .V (3 ).InfoS (msg , "pod" , klog .KObj (pod ))
2903
- return false , v1 .PodResizeStatusInfeasible , msg
2905
+ return false , v1 .PodReasonInfeasible , msg
2906
+
2904
2907
}
2905
2908
2906
2909
// Treat the existing pod needing resize as a new pod with desired resources seeking admit.
@@ -2911,83 +2914,75 @@ func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus, string)
2911
2914
if ok , failReason , failMessage := kl .canAdmitPod (allocatedPods , pod ); ! ok {
2912
2915
// Log reason and return. Let the next sync iteration retry the resize
2913
2916
klog .V (3 ).InfoS ("Resize cannot be accommodated" , "pod" , klog .KObj (pod ), "reason" , failReason , "message" , failMessage )
2914
- return false , v1 .PodResizeStatusDeferred , failMessage
2917
+ return false , v1 .PodReasonDeferred , failMessage
2915
2918
}
2916
2919
2917
- return true , v1 . PodResizeStatusInProgress , ""
2920
+ return true , "" , ""
2918
2921
}
2919
2922
2920
2923
// handlePodResourcesResize returns the "allocated pod", which should be used for all resource
2921
2924
// calculations after this function is called. It also updates the cached ResizeStatus according to
2922
2925
// the allocation decision and pod status.
2923
- func (kl * Kubelet ) handlePodResourcesResize (pod * v1.Pod , podStatus * kubecontainer.PodStatus ) (* v1.Pod , error ) {
2924
- allocatedPod , updated := kl .allocationManager .UpdatePodFromAllocation (pod )
2925
-
2926
- if ! updated {
2927
- // Desired resources == allocated resources. Check whether a resize is in progress.
2926
+ func (kl * Kubelet ) handlePodResourcesResize (pod * v1.Pod , podStatus * kubecontainer.PodStatus ) (allocatedPod * v1.Pod , err error ) {
2927
+ // Always check whether a resize is in progress so we can set the PodResizeInProgressCondition
2928
+ // accordingly.
2929
+ defer func () {
2930
+ if err != nil {
2931
+ return
2932
+ }
2928
2933
if kl .isPodResizeInProgress (allocatedPod , podStatus ) {
2929
2934
// If a resize is in progress, make sure the cache has the correct state in case the Kubelet restarted.
2930
- kl .statusManager .SetPodResizeStatus (pod .UID , v1 . PodResizeStatusInProgress )
2935
+ kl .statusManager .SetPodResizeInProgressCondition (pod .UID , "" , "" )
2931
2936
} else {
2932
- // (Desired == Allocated == Actual) => clear the resize status.
2933
- kl .statusManager .SetPodResizeStatus (pod .UID , "" )
2937
+ // (Allocated == Actual) => clear the resize in-progress status.
2938
+ kl .statusManager .ClearPodResizeInProgressCondition (pod .UID )
2934
2939
}
2935
- // Pod allocation does not need to be updated.
2936
- return allocatedPod , nil
2940
+ }()
2941
+
2942
+ podFromAllocation , updated := kl .allocationManager .UpdatePodFromAllocation (pod )
2943
+ if ! updated {
2944
+ // Desired resources == allocated resources. Pod allocation does not need to be updated.
2945
+ kl .statusManager .ClearPodResizePendingCondition (pod .UID )
2946
+ return podFromAllocation , nil
2947
+
2937
2948
} else if resizable , msg := kuberuntime .IsInPlacePodVerticalScalingAllowed (pod ); ! resizable {
2938
2949
// If there is a pending resize but the resize is not allowed, always use the allocated resources.
2939
- kl .recorder .Eventf (pod , v1 .EventTypeWarning , events .ResizeInfeasible , msg )
2940
- kl .statusManager .SetPodResizeStatus (pod .UID , v1 .PodResizeStatusInfeasible )
2941
- return allocatedPod , nil
2950
+ kl .statusManager .SetPodResizePendingCondition (pod .UID , v1 .PodReasonInfeasible , msg )
2951
+ return podFromAllocation , nil
2942
2952
}
2943
2953
2944
2954
kl .podResizeMutex .Lock ()
2945
2955
defer kl .podResizeMutex .Unlock ()
2946
2956
// Desired resources != allocated resources. Can we update the allocation to the desired resources?
2947
- fit , resizeStatus , resizeMsg := kl .canResizePod (pod )
2957
+ fit , reason , message := kl .canResizePod (pod )
2948
2958
if fit {
2949
2959
// Update pod resource allocation checkpoint
2950
2960
if err := kl .allocationManager .SetAllocatedResources (pod ); err != nil {
2951
2961
return nil , err
2952
2962
}
2963
+ kl .statusManager .ClearPodResizePendingCondition (pod .UID )
2953
2964
for i , container := range pod .Spec .Containers {
2954
- if ! apiequality .Semantic .DeepEqual (container .Resources , allocatedPod .Spec .Containers [i ].Resources ) {
2965
+ if ! apiequality .Semantic .DeepEqual (container .Resources , podFromAllocation .Spec .Containers [i ].Resources ) {
2955
2966
key := kuberuntime .GetStableKey (pod , & container )
2956
2967
kl .crashLoopBackOff .Reset (key )
2957
2968
}
2958
2969
}
2959
2970
for i , container := range pod .Spec .InitContainers {
2960
2971
if podutil .IsRestartableInitContainer (& container ) {
2961
- if ! apiequality .Semantic .DeepEqual (container .Resources , allocatedPod .Spec .InitContainers [i ].Resources ) {
2972
+ if ! apiequality .Semantic .DeepEqual (container .Resources , podFromAllocation .Spec .InitContainers [i ].Resources ) {
2962
2973
key := kuberuntime .GetStableKey (pod , & container )
2963
2974
kl .crashLoopBackOff .Reset (key )
2964
2975
}
2965
2976
}
2966
2977
}
2967
- allocatedPod = pod
2968
-
2969
- // Special case when the updated allocation matches the actuated resources. This can occur
2970
- // when reverting a resize that hasn't been actuated, or when making an equivalent change
2971
- // (such as CPU requests below MinShares). This is an optimization to clear the resize
2972
- // status immediately, rather than waiting for the next SyncPod iteration.
2973
- if ! kl .isPodResizeInProgress (allocatedPod , podStatus ) {
2974
- // In this case, consider the resize complete.
2975
- kl .statusManager .SetPodResizeStatus (pod .UID , "" )
2976
- return allocatedPod , nil
2977
- }
2978
- }
2979
- if resizeStatus != "" {
2980
- kl .statusManager .SetPodResizeStatus (pod .UID , resizeStatus )
2981
- if resizeMsg != "" {
2982
- switch resizeStatus {
2983
- case v1 .PodResizeStatusDeferred :
2984
- kl .recorder .Eventf (pod , v1 .EventTypeWarning , events .ResizeDeferred , resizeMsg )
2985
- case v1 .PodResizeStatusInfeasible :
2986
- kl .recorder .Eventf (pod , v1 .EventTypeWarning , events .ResizeInfeasible , resizeMsg )
2987
- }
2988
- }
2978
+ return pod , nil
2979
+ }
2980
+
2981
+ if reason != "" {
2982
+ kl .statusManager .SetPodResizePendingCondition (pod .UID , reason , message )
2989
2983
}
2990
- return allocatedPod , nil
2984
+
2985
+ return podFromAllocation , nil
2991
2986
}
2992
2987
2993
2988
// isPodResizingInProgress checks whether the actuated resizable resources differ from the allocated resources
0 commit comments