mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
kubectl: take pod overhead into account
Signed-off-by: Eric Ernst <eric.ernst@intel.com>
This commit is contained in:
parent
a76d7fdf64
commit
7922d73f98
@ -28,7 +28,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// PodRequestsAndLimits returns a dictionary of all defined resources summed up for all
|
// PodRequestsAndLimits returns a dictionary of all defined resources summed up for all
|
||||||
// containers of the pod.
|
// containers of the pod. If pod overhead is non-nil, the pod overhead is added to the
|
||||||
|
// total container resource requests and to the total container limits which have a
|
||||||
|
// non-zero quantity.
|
||||||
func PodRequestsAndLimits(pod *corev1.Pod) (reqs, limits corev1.ResourceList) {
|
func PodRequestsAndLimits(pod *corev1.Pod) (reqs, limits corev1.ResourceList) {
|
||||||
reqs, limits = corev1.ResourceList{}, corev1.ResourceList{}
|
reqs, limits = corev1.ResourceList{}, corev1.ResourceList{}
|
||||||
for _, container := range pod.Spec.Containers {
|
for _, container := range pod.Spec.Containers {
|
||||||
@ -40,6 +42,18 @@ func PodRequestsAndLimits(pod *corev1.Pod) (reqs, limits corev1.ResourceList) {
|
|||||||
maxResourceList(reqs, container.Resources.Requests)
|
maxResourceList(reqs, container.Resources.Requests)
|
||||||
maxResourceList(limits, container.Resources.Limits)
|
maxResourceList(limits, container.Resources.Limits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add overhead for running a pod to the sum of requests and to non-zero limits:
|
||||||
|
if pod.Spec.Overhead != nil {
|
||||||
|
addResourceList(reqs, pod.Spec.Overhead)
|
||||||
|
|
||||||
|
for name, quantity := range pod.Spec.Overhead {
|
||||||
|
if value, ok := limits[name]; ok && !value.IsZero() {
|
||||||
|
value.Add(quantity)
|
||||||
|
limits[name] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user