Consider AllocatableResources when computing pod requests

Kubernetes-commit: c2927727107cc8123c2688ea571f464650df6b2b
This commit is contained in:
Tim Allclair 2025-03-17 21:23:32 -07:00 committed by Kubernetes Publisher
parent 0d5516dcdc
commit f38b1de6c2
1 changed files with 7 additions and 18 deletions

View File

@ -144,28 +144,17 @@ func podLimits(pod *corev1.Pod) corev1.ResourceList {
// determineContainerReqs will return a copy of the container requests based on if resizing is feasible or not.
func determineContainerReqs(pod *corev1.Pod, container *corev1.Container, cs *corev1.ContainerStatus) corev1.ResourceList {
if helpers.IsPodResizeInfeasible(pod) {
return cs.Resources.Requests.DeepCopy()
return max(cs.Resources.Requests, cs.AllocatedResources)
}
return max(container.Resources.Requests, cs.Resources.Requests)
return max(container.Resources.Requests, cs.Resources.Requests, cs.AllocatedResources)
}
// max returns the result of max(a, b) for each named resource and is only used if we can't
// max returns the result of max(a, b...) for each named resource and is only used if we can't
// accumulate into an existing resource list
func max(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
result := corev1.ResourceList{}
for key, value := range a {
if other, found := b[key]; found {
if value.Cmp(other) <= 0 {
result[key] = other.DeepCopy()
continue
}
}
result[key] = value.DeepCopy()
}
for key, value := range b {
if _, found := result[key]; !found {
result[key] = value.DeepCopy()
}
func max(a corev1.ResourceList, b ...corev1.ResourceList) corev1.ResourceList {
result := a.DeepCopy()
for _, other := range b {
maxResourceList(result, other)
}
return result
}