Skip to content

Commit 25104fa

Browse files
authored
Merge pull request kubernetes#130604 from tallclair/allocated-status
Always report pod status resources consistent with the current pod sync
2 parents d3548f4 + ed326fe commit 25104fa

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

pkg/kubelet/kubelet.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,11 @@ func (kl *Kubelet) SyncTerminatingPod(_ context.Context, pod *v1.Pod, podStatus
20652065
klog.V(4).InfoS("SyncTerminatingPod enter", "pod", klog.KObj(pod), "podUID", pod.UID)
20662066
defer klog.V(4).InfoS("SyncTerminatingPod exit", "pod", klog.KObj(pod), "podUID", pod.UID)
20672067

2068+
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
2069+
// We don't evaluate pending resizes for terminating pods - proceed with the allocated resources.
2070+
pod, _ = kl.allocationManager.UpdatePodFromAllocation(pod)
2071+
}
2072+
20682073
apiPodStatus := kl.generateAPIPodStatus(pod, podStatus, false)
20692074
if podStatusFn != nil {
20702075
podStatusFn(&apiPodStatus)
@@ -2210,6 +2215,11 @@ func (kl *Kubelet) SyncTerminatedPod(ctx context.Context, pod *v1.Pod, podStatus
22102215
klog.V(4).InfoS("SyncTerminatedPod enter", "pod", klog.KObj(pod), "podUID", pod.UID)
22112216
defer klog.V(4).InfoS("SyncTerminatedPod exit", "pod", klog.KObj(pod), "podUID", pod.UID)
22122217

2218+
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
2219+
// Terminated pods can no longer be resized. Proceed with the allocated resources.
2220+
pod, _ = kl.allocationManager.UpdatePodFromAllocation(pod)
2221+
}
2222+
22132223
// generate the final status of the pod
22142224
// TODO: should we simply fold this into TerminatePod? that would give a single pod update
22152225
apiPodStatus := kl.generateAPIPodStatus(pod, podStatus, true)

pkg/kubelet/kubelet_pods.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,8 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
21302130
return status
21312131
}
21322132

2133-
convertContainerStatusResources := func(cName string, status *v1.ContainerStatus, cStatus *kubecontainer.Status, oldStatuses map[string]v1.ContainerStatus) *v1.ResourceRequirements {
2133+
convertContainerStatusResources := func(allocatedContainer *v1.Container, status *v1.ContainerStatus, cStatus *kubecontainer.Status, oldStatuses map[string]v1.ContainerStatus) *v1.ResourceRequirements {
2134+
cName := allocatedContainer.Name
21342135
// oldStatus should always exist if container is running
21352136
oldStatus, oldStatusFound := oldStatuses[cName]
21362137

@@ -2147,17 +2148,9 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
21472148
}
21482149
}
21492150

2150-
// Always set the status to the latest allocated resources, even if it differs from the
2151-
// allocation used by the current sync loop.
2152-
alloc, found := kl.allocationManager.GetContainerResourceAllocation(pod.UID, cName)
2153-
if !found {
2154-
// This case is expected for non-resizable containers (ephemeral & non-restartable init containers).
2155-
// Don't set status.Resources in this case.
2156-
return nil
2157-
}
21582151
if cStatus.State != kubecontainer.ContainerStateRunning {
21592152
// If the container isn't running, just use the allocated resources.
2160-
return &alloc
2153+
return allocatedContainer.Resources.DeepCopy()
21612154
}
21622155
if oldStatus.Resources == nil {
21632156
oldStatus.Resources = &v1.ResourceRequirements{}
@@ -2166,7 +2159,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
21662159
// Status resources default to the allocated resources.
21672160
// For non-running containers this will be the reported values.
21682161
// For non-resizable resources, these values will also be used.
2169-
resources := alloc
2162+
resources := allocatedContainer.Resources.DeepCopy()
21702163
if resources.Limits != nil {
21712164
if cStatus.Resources != nil && cStatus.Resources.CPULimit != nil {
21722165
// If both the allocated & actual resources are at or below the minimum effective limit, preserve the
@@ -2197,7 +2190,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
21972190
}
21982191
}
21992192

2200-
return &resources
2193+
return resources
22012194
}
22022195

22032196
convertContainerStatusUser := func(cStatus *kubecontainer.Status) *v1.ContainerUser {
@@ -2366,11 +2359,11 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
23662359
}
23672360
status := convertContainerStatus(cStatus, oldStatusPtr)
23682361
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
2369-
status.Resources = convertContainerStatusResources(cName, status, cStatus, oldStatuses)
2370-
2371-
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScalingAllocatedStatus) {
2372-
if alloc, found := kl.allocationManager.GetContainerResourceAllocation(pod.UID, cName); found {
2373-
status.AllocatedResources = alloc.Requests
2362+
allocatedContainer := kubecontainer.GetContainerSpec(pod, cName)
2363+
if allocatedContainer != nil {
2364+
status.Resources = convertContainerStatusResources(allocatedContainer, status, cStatus, oldStatuses)
2365+
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScalingAllocatedStatus) {
2366+
status.AllocatedResources = allocatedContainer.Resources.Requests
23742367
}
23752368
}
23762369
}

0 commit comments

Comments
 (0)