mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #130604 from tallclair/allocated-status
Always report pod status resources consistent with the current pod sync
This commit is contained in:
commit
25104fabcb
@ -2065,6 +2065,11 @@ func (kl *Kubelet) SyncTerminatingPod(_ context.Context, pod *v1.Pod, podStatus
|
||||
klog.V(4).InfoS("SyncTerminatingPod enter", "pod", klog.KObj(pod), "podUID", pod.UID)
|
||||
defer klog.V(4).InfoS("SyncTerminatingPod exit", "pod", klog.KObj(pod), "podUID", pod.UID)
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
|
||||
// We don't evaluate pending resizes for terminating pods - proceed with the allocated resources.
|
||||
pod, _ = kl.allocationManager.UpdatePodFromAllocation(pod)
|
||||
}
|
||||
|
||||
apiPodStatus := kl.generateAPIPodStatus(pod, podStatus, false)
|
||||
if podStatusFn != nil {
|
||||
podStatusFn(&apiPodStatus)
|
||||
@ -2210,6 +2215,11 @@ func (kl *Kubelet) SyncTerminatedPod(ctx context.Context, pod *v1.Pod, podStatus
|
||||
klog.V(4).InfoS("SyncTerminatedPod enter", "pod", klog.KObj(pod), "podUID", pod.UID)
|
||||
defer klog.V(4).InfoS("SyncTerminatedPod exit", "pod", klog.KObj(pod), "podUID", pod.UID)
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
|
||||
// Terminated pods can no longer be resized. Proceed with the allocated resources.
|
||||
pod, _ = kl.allocationManager.UpdatePodFromAllocation(pod)
|
||||
}
|
||||
|
||||
// generate the final status of the pod
|
||||
// TODO: should we simply fold this into TerminatePod? that would give a single pod update
|
||||
apiPodStatus := kl.generateAPIPodStatus(pod, podStatus, true)
|
||||
|
@ -2130,7 +2130,8 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
|
||||
return status
|
||||
}
|
||||
|
||||
convertContainerStatusResources := func(cName string, status *v1.ContainerStatus, cStatus *kubecontainer.Status, oldStatuses map[string]v1.ContainerStatus) *v1.ResourceRequirements {
|
||||
convertContainerStatusResources := func(allocatedContainer *v1.Container, status *v1.ContainerStatus, cStatus *kubecontainer.Status, oldStatuses map[string]v1.ContainerStatus) *v1.ResourceRequirements {
|
||||
cName := allocatedContainer.Name
|
||||
// oldStatus should always exist if container is running
|
||||
oldStatus, oldStatusFound := oldStatuses[cName]
|
||||
|
||||
@ -2147,17 +2148,9 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
|
||||
}
|
||||
}
|
||||
|
||||
// Always set the status to the latest allocated resources, even if it differs from the
|
||||
// allocation used by the current sync loop.
|
||||
alloc, found := kl.allocationManager.GetContainerResourceAllocation(pod.UID, cName)
|
||||
if !found {
|
||||
// This case is expected for non-resizable containers (ephemeral & non-restartable init containers).
|
||||
// Don't set status.Resources in this case.
|
||||
return nil
|
||||
}
|
||||
if cStatus.State != kubecontainer.ContainerStateRunning {
|
||||
// If the container isn't running, just use the allocated resources.
|
||||
return &alloc
|
||||
return allocatedContainer.Resources.DeepCopy()
|
||||
}
|
||||
if oldStatus.Resources == nil {
|
||||
oldStatus.Resources = &v1.ResourceRequirements{}
|
||||
@ -2166,7 +2159,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
|
||||
// Status resources default to the allocated resources.
|
||||
// For non-running containers this will be the reported values.
|
||||
// For non-resizable resources, these values will also be used.
|
||||
resources := alloc
|
||||
resources := allocatedContainer.Resources.DeepCopy()
|
||||
if resources.Limits != nil {
|
||||
if cStatus.Resources != nil && cStatus.Resources.CPULimit != nil {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
return &resources
|
||||
return resources
|
||||
}
|
||||
|
||||
convertContainerStatusUser := func(cStatus *kubecontainer.Status) *v1.ContainerUser {
|
||||
@ -2366,11 +2359,11 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
|
||||
}
|
||||
status := convertContainerStatus(cStatus, oldStatusPtr)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
|
||||
status.Resources = convertContainerStatusResources(cName, status, cStatus, oldStatuses)
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScalingAllocatedStatus) {
|
||||
if alloc, found := kl.allocationManager.GetContainerResourceAllocation(pod.UID, cName); found {
|
||||
status.AllocatedResources = alloc.Requests
|
||||
allocatedContainer := kubecontainer.GetContainerSpec(pod, cName)
|
||||
if allocatedContainer != nil {
|
||||
status.Resources = convertContainerStatusResources(allocatedContainer, status, cStatus, oldStatuses)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScalingAllocatedStatus) {
|
||||
status.AllocatedResources = allocatedContainer.Resources.Requests
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user