From 019159e54965104384a9349fdb5663dc7b37074d Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Mon, 12 Jun 2017 16:19:51 -0500 Subject: [PATCH] UPSTREAM: 44898: while calculating pod's cpu limits, need to count in init-container --- .../pkg/kubelet/cm/helpers_linux.go | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/cm/helpers_linux.go b/vendor/k8s.io/kubernetes/pkg/kubelet/cm/helpers_linux.go index 2e0d41b9c52f..ca2f7235ca0a 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubelet/cm/helpers_linux.go +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/cm/helpers_linux.go @@ -26,6 +26,7 @@ import ( libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups" "k8s.io/kubernetes/pkg/api/v1" + "k8s.io/kubernetes/pkg/api/v1/resource" "k8s.io/kubernetes/pkg/kubelet/qos" ) @@ -84,28 +85,41 @@ func MilliCPUToShares(milliCPU int64) int64 { // ResourceConfigForPod takes the input pod and outputs the cgroup resource config. func ResourceConfigForPod(pod *v1.Pod) *ResourceConfig { - // sum requests and limits, track if limits were applied for each resource. + // sum requests and limits. + reqs, limits, err := resource.PodRequestsAndLimits(pod) + if err != nil { + return &ResourceConfig{} + } + cpuRequests := int64(0) cpuLimits := int64(0) memoryLimits := int64(0) + if request, found := reqs[v1.ResourceCPU]; found { + cpuRequests = request.MilliValue() + } + if limit, found := limits[v1.ResourceCPU]; found { + cpuLimits = limit.MilliValue() + } + if limit, found := limits[v1.ResourceMemory]; found { + memoryLimits = limit.Value() + } + + // convert to CFS values + cpuShares := MilliCPUToShares(cpuRequests) + cpuQuota, cpuPeriod := MilliCPUToQuota(cpuLimits) + + // track if limits were applied for each resource. memoryLimitsDeclared := true cpuLimitsDeclared := true for _, container := range pod.Spec.Containers { - cpuRequests += container.Resources.Requests.Cpu().MilliValue() - cpuLimits += container.Resources.Limits.Cpu().MilliValue() if container.Resources.Limits.Cpu().IsZero() { cpuLimitsDeclared = false } - memoryLimits += container.Resources.Limits.Memory().Value() if container.Resources.Limits.Memory().IsZero() { memoryLimitsDeclared = false } } - // convert to CFS values - cpuShares := MilliCPUToShares(cpuRequests) - cpuQuota, cpuPeriod := MilliCPUToQuota(cpuLimits) - // determine the qos class qosClass := qos.GetPodQOS(pod)