Skip to content

Commit 460db5c

Browse files
committed
Always use allocated resources for pods that don't support resize
1 parent 6df3ea4 commit 460db5c

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

pkg/kubelet/kubelet.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ func (kl *Kubelet) SyncPod(ctx context.Context, updateType kubetypes.SyncPodType
18831883
// handlePodResourcesResize updates the pod to use the allocated resources. This should come
18841884
// before the main business logic of SyncPod, so that a consistent view of the pod is used
18851885
// across the sync loop.
1886-
if kuberuntime.IsInPlacePodVerticalScalingAllowed(pod) {
1886+
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
18871887
// Handle pod resize here instead of doing it in HandlePodUpdates because
18881888
// this conveniently retries any Deferred resize requests
18891889
// TODO(vinaykul,InPlacePodVerticalScaling): Investigate doing this in HandlePodUpdates + periodic SyncLoop scan
@@ -2816,10 +2816,6 @@ func (kl *Kubelet) HandlePodSyncs(pods []*v1.Pod) {
28162816
// pod should hold the desired (pre-allocated) spec.
28172817
// Returns true if the resize can proceed.
28182818
func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus, string) {
2819-
if goos == "windows" {
2820-
return false, v1.PodResizeStatusInfeasible, "Resizing Windows pods is not supported"
2821-
}
2822-
28232819
if v1qos.GetPodQOS(pod) == v1.PodQOSGuaranteed && !utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScalingExclusiveCPUs) {
28242820
if utilfeature.DefaultFeatureGate.Enabled(features.CPUManager) {
28252821
if kl.containerManager.GetNodeConfig().CPUManagerPolicy == "static" {
@@ -2877,6 +2873,27 @@ func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus, string)
28772873
// the allocation decision and pod status.
28782874
func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod, podStatus *kubecontainer.PodStatus) (*v1.Pod, error) {
28792875
allocatedPod, updated := kl.allocationManager.UpdatePodFromAllocation(pod)
2876+
// Keep this logic in sync with kuberuntime.isInPlacePodVerticalScalingAllowed
2877+
if goos == "windows" || kubetypes.IsStaticPod(pod) {
2878+
if updated {
2879+
// A resize is requested but not supported.
2880+
var msg string
2881+
switch {
2882+
case goos == "windows":
2883+
msg = "Resizing Windows pods is not supported"
2884+
case kubetypes.IsStaticPod(pod):
2885+
msg = "Resizing static pods is not supported"
2886+
default:
2887+
msg = "Resizing this pod is not supported"
2888+
}
2889+
kl.recorder.Eventf(pod, v1.EventTypeWarning, events.ResizeInfeasible, msg)
2890+
kl.statusManager.SetPodResizeStatus(pod.UID, v1.PodResizeStatusInfeasible)
2891+
} else {
2892+
kl.statusManager.SetPodResizeStatus(pod.UID, "")
2893+
}
2894+
return allocatedPod, nil
2895+
}
2896+
28802897
if !updated {
28812898
// Desired resources == allocated resources. Check whether a resize is in progress.
28822899
resizeInProgress := !allocatedResourcesMatchStatus(allocatedPod, podStatus)

pkg/kubelet/kubelet_pods.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,10 +1748,6 @@ func getPhase(pod *v1.Pod, info []v1.ContainerStatus, podIsTerminal bool) v1.Pod
17481748
}
17491749

17501750
func (kl *Kubelet) determinePodResizeStatus(allocatedPod *v1.Pod, podStatus *kubecontainer.PodStatus, podIsTerminal bool) v1.PodResizeStatus {
1751-
if kubetypes.IsStaticPod(allocatedPod) {
1752-
return ""
1753-
}
1754-
17551751
// If pod is terminal, clear the resize status.
17561752
if podIsTerminal {
17571753
kl.statusManager.SetPodResizeStatus(allocatedPod.UID, "")

pkg/kubelet/kubelet_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,7 @@ func TestHandlePodResourcesResize(t *testing.T) {
27122712
expectedResize v1.PodResizeStatus
27132713
expectBackoffReset bool
27142714
goos string
2715+
annotations map[string]string
27152716
}{
27162717
{
27172718
name: "Request CPU and memory decrease - expect InProgress",
@@ -2788,6 +2789,14 @@ func TestHandlePodResourcesResize(t *testing.T) {
27882789
expectedResize: v1.PodResizeStatusInfeasible,
27892790
goos: "windows",
27902791
},
2792+
{
2793+
name: "static pod, expect Infeasible",
2794+
originalRequests: v1.ResourceList{v1.ResourceCPU: cpu1000m, v1.ResourceMemory: mem1000M},
2795+
newRequests: v1.ResourceList{v1.ResourceCPU: cpu500m, v1.ResourceMemory: mem500M},
2796+
expectedAllocatedReqs: v1.ResourceList{v1.ResourceCPU: cpu1000m, v1.ResourceMemory: mem1000M},
2797+
expectedResize: v1.PodResizeStatusInfeasible,
2798+
annotations: map[string]string{kubetypes.ConfigSourceAnnotationKey: kubetypes.FileSource},
2799+
},
27912800
{
27922801
name: "Increase CPU from min shares",
27932802
originalRequests: v1.ResourceList{v1.ResourceCPU: cpu2m},
@@ -2889,6 +2898,7 @@ func TestHandlePodResourcesResize(t *testing.T) {
28892898
originalPod = testPod1.DeepCopy()
28902899
originalCtr = &originalPod.Spec.Containers[0]
28912900
}
2901+
originalPod.Annotations = tt.annotations
28922902
originalCtr.Resources.Requests = tt.originalRequests
28932903
originalCtr.Resources.Limits = tt.originalLimits
28942904

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func containerSucceeded(c *v1.Container, podStatus *kubecontainer.PodStatus) boo
551551
return cStatus.State == kubecontainer.ContainerStateExited && cStatus.ExitCode == 0
552552
}
553553

554-
func IsInPlacePodVerticalScalingAllowed(pod *v1.Pod) bool {
554+
func isInPlacePodVerticalScalingAllowed(pod *v1.Pod) bool {
555555
return utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) &&
556556
!types.IsStaticPod(pod) &&
557557
runtime.GOOS != "windows"
@@ -561,7 +561,7 @@ func IsInPlacePodVerticalScalingAllowed(pod *v1.Pod) bool {
561561
// Returns whether to keep (true) or restart (false) the container.
562562
// TODO(vibansal): Make this function to be agnostic to whether it is dealing with a restartable init container or not (i.e. remove the argument `isRestartableInitContainer`).
563563
func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containerIdx int, isRestartableInitContainer bool, kubeContainerStatus *kubecontainer.Status, changes *podActions) (keepContainer bool) {
564-
if !IsInPlacePodVerticalScalingAllowed(pod) {
564+
if !isInPlacePodVerticalScalingAllowed(pod) {
565565
return true
566566
}
567567

@@ -998,7 +998,7 @@ func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod *
998998
}
999999
}
10001000

1001-
if IsInPlacePodVerticalScalingAllowed(pod) {
1001+
if isInPlacePodVerticalScalingAllowed(pod) {
10021002
changes.ContainersToUpdate = make(map[v1.ResourceName][]containerToUpdateInfo)
10031003
}
10041004

@@ -1414,7 +1414,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(ctx context.Context, pod *v1.Pod, po
14141414
}
14151415

14161416
// Step 7: For containers in podContainerChanges.ContainersToUpdate[CPU,Memory] list, invoke UpdateContainerResources
1417-
if IsInPlacePodVerticalScalingAllowed(pod) {
1417+
if isInPlacePodVerticalScalingAllowed(pod) {
14181418
if len(podContainerChanges.ContainersToUpdate) > 0 || podContainerChanges.UpdatePodResources {
14191419
m.doPodResizeAction(pod, podContainerChanges, &result)
14201420
}

0 commit comments

Comments
 (0)