From 5936bc37df883b57af7aaacd096750de4436ccd7 Mon Sep 17 00:00:00 2001 From: Olivier Tardieu Date: Fri, 30 Aug 2024 18:57:31 -0400 Subject: [PATCH] Simplify parsing of container resources in cluster-checker tool (#45) --- tools/cluster-checker/checker.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/cluster-checker/checker.js b/tools/cluster-checker/checker.js index 1bc1b51..eb3b997 100644 --- a/tools/cluster-checker/checker.js +++ b/tools/cluster-checker/checker.js @@ -73,19 +73,11 @@ function reservation (pod) { let gpus = 0 // compute sum of regular containers for (const container of pod.spec.containers) { - if (container.resources?.requests?.['nvidia.com/gpu'] > 0) { - gpus += parseInt(container.resources?.requests?.['nvidia.com/gpu']) - } else if (container.resources?.limits?.['nvidia.com/gpu'] > 0) { - gpus += parseInt(container.resources?.limits?.['nvidia.com/gpu']) - } + gpus += parseInt(container.resources?.limits?.['nvidia.com/gpu'] ?? "0") } // compute max with init containers for (const container of pod.spec.initContainers ?? []) { - if (container.resources?.requests?.['nvidia.com/gpu'] > gpus) { - gpus = parseInt(container.resources?.requests?.['nvidia.com/gpu']) - } else if (container.resources?.limits?.['nvidia.com/gpu'] > gpus) { - gpus = parseInt(container.resources?.limits?.['nvidia.com/gpu']) - } + gpus = Math.max(gpus, parseInt(container.resources?.limits?.['nvidia.com/gpu'] ?? "0")) } return gpus }