plugin-kubernetes: fix div by zero pod resources

When pods have no resources set, currentToDeclaredResourceToPerc would
throw div by zero, added check

Signed-off-by: Manuel Stein <manuel.stein@nokia-bell-labs.com>
This commit is contained in:
Manuel Stein
2022-03-17 21:59:09 +02:00
parent ffaaec5950
commit f616d99f6f
2 changed files with 7 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes': patch
---
Fix division by zero in currentToDeclaredResourceToPerc when pod resources weren't set
+2
View File
@@ -118,6 +118,8 @@ export const currentToDeclaredResourceToPerc = (
current: number | string,
resource: number | string,
): string => {
if(Number(resource) == 0) return `0%`;
if (typeof current === 'number' && typeof resource === 'number') {
return `${Math.round((current / resource) * 100)}%`;
}