Skip to content

Commit

Permalink
Simplify parsing of container resources in cluster-checker tool (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
tardieu authored Aug 30, 2024
1 parent ff6aa71 commit 5936bc3
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions tools/cluster-checker/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5936bc3

Please sign in to comment.