Feroze Mohideen il y a 2 ans
Parent
commit
85ee08a339
1 fichiers modifiés avec 24 ajouts et 22 suppressions
  1. 24 22
      dashboard/src/lib/hooks/useClusterResourceLimits.ts

+ 24 - 22
dashboard/src/lib/hooks/useClusterResourceLimits.ts

@@ -218,29 +218,31 @@ export const useClusterResourceLimits = ({
   useEffect(() => {
     if (getClusterNodes.isSuccess) {
       const data = getClusterNodes.data;
-      // this logic handles CPU and RAM independently - we might want to change this later
-      const maxCPU = data.reduce((acc, curr) => {
-        return Math.max(acc, curr.maxCPU);
-      }, 0);
-      const maxRAM = data.reduce((acc, curr) => {
-        return Math.max(acc, curr.maxRAM);
-      }, 0);
-      let maxMultiplier = SMALL_INSTANCE_UPPER_BOUND;
-      // if the instance type has more than 4 GB ram, we use 90% of the ram/cpu
-      // otherwise, we use 75%
-      if (maxRAM > 4) {
-        maxMultiplier = LARGE_INSTANCE_UPPER_BOUND;
+      if (data.length) {
+        // this logic handles CPU and RAM independently - we might want to change this later
+        const maxCPU = data.reduce((acc, curr) => {
+          return Math.max(acc, curr.maxCPU);
+        }, 0);
+        const maxRAM = data.reduce((acc, curr) => {
+          return Math.max(acc, curr.maxRAM);
+        }, 0);
+        let maxMultiplier = SMALL_INSTANCE_UPPER_BOUND;
+        // if the instance type has more than 4 GB ram, we use 90% of the ram/cpu
+        // otherwise, we use 75%
+        if (maxRAM > 4) {
+          maxMultiplier = LARGE_INSTANCE_UPPER_BOUND;
+        }
+        // round down to nearest 0.5 cores
+        const newMaxCPU = Math.floor(maxCPU * maxMultiplier * 2) / 2;
+        // round down to nearest 100 MB
+        const newMaxRAM =
+          Math.round((convert(maxRAM, "GiB").to("MB") * maxMultiplier) / 100) *
+          100;
+        setMaxCPU(newMaxCPU);
+        setMaxRAM(newMaxRAM);
+        setDefaultCPU(Number((newMaxCPU * DEFAULT_MULTIPLIER).toFixed(2)));
+        setDefaultRAM(Number((newMaxRAM * DEFAULT_MULTIPLIER).toFixed(0)));
       }
-      // round down to nearest 0.5 cores
-      const newMaxCPU = Math.floor(maxCPU * maxMultiplier * 2) / 2;
-      // round down to nearest 100 MB
-      const newMaxRAM =
-        Math.round((convert(maxRAM, "GiB").to("MB") * maxMultiplier) / 100) *
-        100;
-      setMaxCPU(newMaxCPU);
-      setMaxRAM(newMaxRAM);
-      setDefaultCPU(Number((newMaxCPU * DEFAULT_MULTIPLIER).toFixed(2)));
-      setDefaultRAM(Number((newMaxRAM * DEFAULT_MULTIPLIER).toFixed(0)));
     }
   }, [getClusterNodes]);