@@ -2130,7 +2130,8 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
2130
2130
return status
2131
2131
}
2132
2132
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
2134
2135
// oldStatus should always exist if container is running
2135
2136
oldStatus , oldStatusFound := oldStatuses [cName ]
2136
2137
@@ -2147,17 +2148,9 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
2147
2148
}
2148
2149
}
2149
2150
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
- }
2158
2151
if cStatus .State != kubecontainer .ContainerStateRunning {
2159
2152
// If the container isn't running, just use the allocated resources.
2160
- return & alloc
2153
+ return allocatedContainer . Resources . DeepCopy ()
2161
2154
}
2162
2155
if oldStatus .Resources == nil {
2163
2156
oldStatus .Resources = & v1.ResourceRequirements {}
@@ -2166,7 +2159,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
2166
2159
// Status resources default to the allocated resources.
2167
2160
// For non-running containers this will be the reported values.
2168
2161
// For non-resizable resources, these values will also be used.
2169
- resources := alloc
2162
+ resources := allocatedContainer . Resources . DeepCopy ()
2170
2163
if resources .Limits != nil {
2171
2164
if cStatus .Resources != nil && cStatus .Resources .CPULimit != nil {
2172
2165
// 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
2197
2190
}
2198
2191
}
2199
2192
2200
- return & resources
2193
+ return resources
2201
2194
}
2202
2195
2203
2196
convertContainerStatusUser := func (cStatus * kubecontainer.Status ) * v1.ContainerUser {
@@ -2366,11 +2359,11 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
2366
2359
}
2367
2360
status := convertContainerStatus (cStatus , oldStatusPtr )
2368
2361
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
2374
2367
}
2375
2368
}
2376
2369
}
0 commit comments