diff --git a/pkg/wasp/pod-ranker/rank_utils.go b/pkg/wasp/pod-ranker/rank_utils.go index 82ee84da..301825a3 100644 --- a/pkg/wasp/pod-ranker/rank_utils.go +++ b/pkg/wasp/pod-ranker/rank_utils.go @@ -134,7 +134,12 @@ func exceedMemoryLimits(summary summaryFunc) cmpFunc { func hasContainerExceedMemoryLimits(pod *v1.Pod, summary stats_collector.PodSummary) bool { for _, container := range pod.Spec.Containers { if rQuantity, ok := container.Resources.Limits[v1.ResourceMemory]; ok { - memoryAndSwapSumQuantity := memoryAndSwapUsage(*summary.Containers[container.Name].MemoryWorkingSetBytes, *summary.Containers[container.Name].MemorySwapCurrentBytes) + containerStats, exists := summary.Containers[container.Name] + if !exists { + continue + } + memoryAndSwapSumQuantity := + memoryAndSwapUsage(*containerStats.MemoryWorkingSetBytes, *containerStats.MemorySwapCurrentBytes) if memoryAndSwapSumQuantity.Cmp(rQuantity) == 1 { return true } @@ -143,7 +148,12 @@ func hasContainerExceedMemoryLimits(pod *v1.Pod, summary stats_collector.PodSumm for _, container := range pod.Spec.InitContainers { if rQuantity, ok := container.Resources.Limits[v1.ResourceMemory]; ok { - memoryAndSwapSumQuantity := memoryAndSwapUsage(*summary.Containers[container.Name].MemoryWorkingSetBytes, *summary.Containers[container.Name].MemorySwapCurrentBytes) + containerStats, exists := summary.Containers[container.Name] + if !exists { + continue + } + memoryAndSwapSumQuantity := + memoryAndSwapUsage(*containerStats.MemoryWorkingSetBytes, *containerStats.MemorySwapCurrentBytes) if memoryAndSwapSumQuantity.Cmp(rQuantity) == 1 { return true }