@@ -119,6 +119,7 @@ import (
119
119
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
120
120
"k8s.io/kubernetes/pkg/kubelet/userns"
121
121
"k8s.io/kubernetes/pkg/kubelet/util"
122
+ "k8s.io/kubernetes/pkg/kubelet/util/format"
122
123
"k8s.io/kubernetes/pkg/kubelet/util/manager"
123
124
"k8s.io/kubernetes/pkg/kubelet/util/queue"
124
125
"k8s.io/kubernetes/pkg/kubelet/util/sliceutils"
@@ -2838,34 +2839,47 @@ func isPodResizeInProgress(pod *v1.Pod, podStatus *kubecontainer.PodStatus) bool
2838
2839
// canResizePod determines if the requested resize is currently feasible.
2839
2840
// pod should hold the desired (pre-allocated) spec.
2840
2841
// Returns true if the resize can proceed.
2841
- func (kl * Kubelet ) canResizePod (pod * v1.Pod ) (bool , v1.PodResizeStatus ) {
2842
+ func (kl * Kubelet ) canResizePod (pod * v1.Pod ) (bool , v1.PodResizeStatus , string ) {
2843
+ if goos == "windows" {
2844
+ return false , v1 .PodResizeStatusInfeasible , "Resizing Windows pods is not supported"
2845
+ }
2846
+
2842
2847
if v1qos .GetPodQOS (pod ) == v1 .PodQOSGuaranteed && ! utilfeature .DefaultFeatureGate .Enabled (features .InPlacePodVerticalScalingExclusiveCPUs ) {
2843
2848
if utilfeature .DefaultFeatureGate .Enabled (features .CPUManager ) {
2844
2849
if kl .containerManager .GetNodeConfig ().CPUManagerPolicy == "static" {
2845
- klog .V (3 ).InfoS ("Resize is infeasible for Guaranteed Pods alongside CPU Manager static policy" )
2846
- return false , v1 .PodResizeStatusInfeasible
2850
+ msg := "Resize is infeasible for Guaranteed Pods alongside CPU Manager static policy"
2851
+ klog .V (3 ).InfoS (msg , "pod" , format .Pod (pod ))
2852
+ return false , v1 .PodResizeStatusInfeasible , msg
2847
2853
}
2848
2854
}
2849
2855
if utilfeature .DefaultFeatureGate .Enabled (features .MemoryManager ) {
2850
2856
if kl .containerManager .GetNodeConfig ().ExperimentalMemoryManagerPolicy == "static" {
2851
- klog .V (3 ).InfoS ("Resize is infeasible for Guaranteed Pods alongside Memory Manager static policy" )
2852
- return false , v1 .PodResizeStatusInfeasible
2857
+ msg := "Resize is infeasible for Guaranteed Pods alongside Memory Manager static policy"
2858
+ klog .V (3 ).InfoS (msg , "pod" , format .Pod (pod ))
2859
+ return false , v1 .PodResizeStatusInfeasible , msg
2853
2860
}
2854
2861
}
2855
2862
}
2856
2863
2857
2864
node , err := kl .getNodeAnyWay ()
2858
2865
if err != nil {
2859
2866
klog .ErrorS (err , "getNodeAnyway function failed" )
2860
- return false , ""
2867
+ return false , "" , ""
2861
2868
}
2862
2869
cpuAvailable := node .Status .Allocatable .Cpu ().MilliValue ()
2863
2870
memAvailable := node .Status .Allocatable .Memory ().Value ()
2864
2871
cpuRequests := resource .GetResourceRequest (pod , v1 .ResourceCPU )
2865
2872
memRequests := resource .GetResourceRequest (pod , v1 .ResourceMemory )
2866
2873
if cpuRequests > cpuAvailable || memRequests > memAvailable {
2867
- klog .V (3 ).InfoS ("Resize is not feasible as request exceeds allocatable node resources" , "pod" , klog .KObj (pod ))
2868
- return false , v1 .PodResizeStatusInfeasible
2874
+ var msg string
2875
+ if memRequests > memAvailable {
2876
+ msg = fmt .Sprintf ("memory, requested: %d, capacity: %d" , memRequests , memAvailable )
2877
+ } else {
2878
+ msg = fmt .Sprintf ("cpu, requested: %d, capacity: %d" , cpuRequests , cpuAvailable )
2879
+ }
2880
+ msg = "Node didn't have enough capacity: " + msg
2881
+ klog .V (3 ).InfoS (msg , "pod" , klog .KObj (pod ))
2882
+ return false , v1 .PodResizeStatusInfeasible , msg
2869
2883
}
2870
2884
2871
2885
// Treat the existing pod needing resize as a new pod with desired resources seeking admit.
@@ -2876,10 +2890,10 @@ func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus) {
2876
2890
if ok , failReason , failMessage := kl .canAdmitPod (allocatedPods , pod ); ! ok {
2877
2891
// Log reason and return. Let the next sync iteration retry the resize
2878
2892
klog .V (3 ).InfoS ("Resize cannot be accommodated" , "pod" , klog .KObj (pod ), "reason" , failReason , "message" , failMessage )
2879
- return false , v1 .PodResizeStatusDeferred
2893
+ return false , v1 .PodResizeStatusDeferred , failMessage
2880
2894
}
2881
2895
2882
- return true , v1 .PodResizeStatusInProgress
2896
+ return true , v1 .PodResizeStatusInProgress , ""
2883
2897
}
2884
2898
2885
2899
// handlePodResourcesResize returns the "allocated pod", which should be used for all resource
@@ -2900,15 +2914,11 @@ func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod, podStatus *kubecontaine
2900
2914
// Pod allocation does not need to be updated.
2901
2915
return allocatedPod , nil
2902
2916
}
2903
- if goos == "windows" {
2904
- kl .statusManager .SetPodResizeStatus (pod .UID , v1 .PodResizeStatusInfeasible )
2905
- return allocatedPod , nil
2906
- }
2907
2917
2908
2918
kl .podResizeMutex .Lock ()
2909
2919
defer kl .podResizeMutex .Unlock ()
2910
2920
// Desired resources != allocated resources. Can we update the allocation to the desired resources?
2911
- fit , resizeStatus := kl .canResizePod (pod )
2921
+ fit , resizeStatus , resizeMsg := kl .canResizePod (pod )
2912
2922
if fit {
2913
2923
// Update pod resource allocation checkpoint
2914
2924
if err := kl .statusManager .SetPodAllocation (pod ); err != nil {
@@ -2934,6 +2944,14 @@ func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod, podStatus *kubecontaine
2934
2944
}
2935
2945
if resizeStatus != "" {
2936
2946
kl .statusManager .SetPodResizeStatus (pod .UID , resizeStatus )
2947
+ if resizeMsg != "" {
2948
+ switch resizeStatus {
2949
+ case v1 .PodResizeStatusDeferred :
2950
+ kl .recorder .Eventf (pod , v1 .EventTypeWarning , events .ResizeDeferred , resizeMsg )
2951
+ case v1 .PodResizeStatusInfeasible :
2952
+ kl .recorder .Eventf (pod , v1 .EventTypeWarning , events .ResizeInfeasible , resizeMsg )
2953
+ }
2954
+ }
2937
2955
}
2938
2956
return allocatedPod , nil
2939
2957
}
0 commit comments