Skip to content

Commit 3d17fd5

Browse files
authored
Merge pull request kubernetes#81929 from egernst/kubectl-overhead
Kubectl: take pod overhead into account for node info
2 parents 443002f + 7922d73 commit 3d17fd5

File tree

1 file changed

+15
-1
lines changed
  • staging/src/k8s.io/kubectl/pkg/util/resource

1 file changed

+15
-1
lines changed

staging/src/k8s.io/kubectl/pkg/util/resource/resource.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import (
2828
)
2929

3030
// PodRequestsAndLimits returns a dictionary of all defined resources summed up for all
31-
// containers of the pod.
31+
// containers of the pod. If pod overhead is non-nil, the pod overhead is added to the
32+
// total container resource requests and to the total container limits which have a
33+
// non-zero quantity.
3234
func PodRequestsAndLimits(pod *corev1.Pod) (reqs, limits corev1.ResourceList) {
3335
reqs, limits = corev1.ResourceList{}, corev1.ResourceList{}
3436
for _, container := range pod.Spec.Containers {
@@ -40,6 +42,18 @@ func PodRequestsAndLimits(pod *corev1.Pod) (reqs, limits corev1.ResourceList) {
4042
maxResourceList(reqs, container.Resources.Requests)
4143
maxResourceList(limits, container.Resources.Limits)
4244
}
45+
46+
// Add overhead for running a pod to the sum of requests and to non-zero limits:
47+
if pod.Spec.Overhead != nil {
48+
addResourceList(reqs, pod.Spec.Overhead)
49+
50+
for name, quantity := range pod.Spec.Overhead {
51+
if value, ok := limits[name]; ok && !value.IsZero() {
52+
value.Add(quantity)
53+
limits[name] = value
54+
}
55+
}
56+
}
4357
return
4458
}
4559

0 commit comments

Comments
 (0)