Skip to content

Commit f38b1de

Browse files
tallclairk8s-publishing-bot
authored andcommitted
Consider AllocatableResources when computing pod requests
Kubernetes-commit: c2927727107cc8123c2688ea571f464650df6b2b
1 parent 0d5516d commit f38b1de

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

pkg/util/resource/resource.go

+7-18
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,17 @@ func podLimits(pod *corev1.Pod) corev1.ResourceList {
144144
// determineContainerReqs will return a copy of the container requests based on if resizing is feasible or not.
145145
func determineContainerReqs(pod *corev1.Pod, container *corev1.Container, cs *corev1.ContainerStatus) corev1.ResourceList {
146146
if helpers.IsPodResizeInfeasible(pod) {
147-
return cs.Resources.Requests.DeepCopy()
147+
return max(cs.Resources.Requests, cs.AllocatedResources)
148148
}
149-
return max(container.Resources.Requests, cs.Resources.Requests)
149+
return max(container.Resources.Requests, cs.Resources.Requests, cs.AllocatedResources)
150150
}
151151

152-
// max returns the result of max(a, b) for each named resource and is only used if we can't
152+
// max returns the result of max(a, b...) for each named resource and is only used if we can't
153153
// accumulate into an existing resource list
154-
func max(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
155-
result := corev1.ResourceList{}
156-
for key, value := range a {
157-
if other, found := b[key]; found {
158-
if value.Cmp(other) <= 0 {
159-
result[key] = other.DeepCopy()
160-
continue
161-
}
162-
}
163-
result[key] = value.DeepCopy()
164-
}
165-
for key, value := range b {
166-
if _, found := result[key]; !found {
167-
result[key] = value.DeepCopy()
168-
}
154+
func max(a corev1.ResourceList, b ...corev1.ResourceList) corev1.ResourceList {
155+
result := a.DeepCopy()
156+
for _, other := range b {
157+
maxResourceList(result, other)
169158
}
170159
return result
171160
}

0 commit comments

Comments
 (0)