Unverified Commit b6824afa authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #58574 from yastij/fix-kubelet-podRequest

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. fixing array out of bound by checking initContainers instead of containers **What this PR does / why we need it**: **Which issue(s) this PR fixes** : Fixes #58541 **Special notes for your reviewer**: **Release note**: ```release-note None ```
parents 88abb431 ed8e75a1
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment