From ed8e75a15c5b93b5e7f9fa0839c2fccea150f776 Mon Sep 17 00:00:00 2001 From: Yassine TIJANI Date: Sun, 21 Jan 2018 02:08:53 +0100 Subject: [PATCH] fixing array out of bound by checking initContainers instead of containers --- pkg/kubelet/eviction/helpers.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/kubelet/eviction/helpers.go b/pkg/kubelet/eviction/helpers.go index 4376c842882..43b82ff6fe3 100644 --- a/pkg/kubelet/eviction/helpers.go +++ b/pkg/kubelet/eviction/helpers.go @@ -590,7 +590,7 @@ func memory(stats statsFunc) cmpFunc { } // podRequest returns the total resource request of a pod which is the -// max(sum of init container requests, sum of container requests) +// max(max of init container requests, sum of container requests) func podRequest(pod *v1.Pod, resourceName v1.ResourceName) resource.Quantity { containerValue := resource.Quantity{Format: resource.BinarySI} if resourceName == resourceDisk && !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) { @@ -609,9 +609,13 @@ func podRequest(pod *v1.Pod, resourceName v1.ResourceName) resource.Quantity { for i := range pod.Spec.InitContainers { switch resourceName { case v1.ResourceMemory: - containerValue.Add(*pod.Spec.Containers[i].Resources.Requests.Memory()) + if initValue.Cmp(*pod.Spec.InitContainers[i].Resources.Requests.Memory()) < 0 { + initValue = *pod.Spec.InitContainers[i].Resources.Requests.Memory() + } case resourceDisk: - containerValue.Add(*pod.Spec.Containers[i].Resources.Requests.StorageEphemeral()) + if initValue.Cmp(*pod.Spec.InitContainers[i].Resources.Requests.StorageEphemeral()) < 0 { + initValue = *pod.Spec.InitContainers[i].Resources.Requests.StorageEphemeral() + } } } if containerValue.Cmp(initValue) > 0 {