From 2939329455abbefac2e608549b45d02b8b6ecc26 Mon Sep 17 00:00:00 2001 From: Jeff McCoy Date: Sun, 27 Feb 2022 02:29:37 -0600 Subject: [PATCH] Handle empty return fields for some pod & node views Signed-off-by: Jeff McCoy --- client/src/components/nodeCpuChart.tsx | 6 +++--- client/src/components/nodeRamChart.tsx | 6 +++--- client/src/views/node.tsx | 12 +++++++----- client/src/views/pod.tsx | 16 +++++++++++----- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/client/src/components/nodeCpuChart.tsx b/client/src/components/nodeCpuChart.tsx index f1039616..52ff4040 100644 --- a/client/src/components/nodeCpuChart.tsx +++ b/client/src/components/nodeCpuChart.tsx @@ -24,9 +24,9 @@ export default function NodeCpuChart({items, metrics}: {items?: Node[], metrics? function getNodeCpuTotals(items?: Node[], metrics?: _.Dictionary) { if (!items || !metrics) return null; - const metricValues = Object.values(metrics); - const used = _.sumBy(metricValues, x => parseCpu(x.usage.cpu)) / TO_ONE_CPU; - const available = _.sumBy(items, x => parseCpu(x.status.capacity.cpu)) / TO_ONE_CPU; + const metricValues = Object.values(metrics) || []; + const used = _.sumBy(metricValues, x => parseCpu(_.get(x, 'usage.cpu'))) / TO_ONE_CPU; + const available = _.sumBy(items, x => parseCpu(_.get(x, 'status.capacity.cpu'))) / TO_ONE_CPU; return {used, available}; } diff --git a/client/src/components/nodeRamChart.tsx b/client/src/components/nodeRamChart.tsx index 4896da32..8b248f94 100644 --- a/client/src/components/nodeRamChart.tsx +++ b/client/src/components/nodeRamChart.tsx @@ -33,9 +33,9 @@ export default function NodeRamChart({items, metrics}: {items?: Node[], metrics? function getNodeRamTotals(items?: Node[], metrics?: _.Dictionary) { if (!items || !metrics) return undefined; - const metricValues = Object.values(metrics); - const used = _.sumBy(metricValues, x => parseRam(x.usage.memory)); - const available = _.sumBy(items, x => parseRam(x.status.capacity.memory)); + const metricValues = Object.values(metrics) || []; + const used = _.sumBy(metricValues, x => parseRam(_.get(x, 'usage.memory'))); + const available = _.sumBy(items, x => parseRam(_.get(x, 'status.capacity.memory'))); return {used, available}; } diff --git a/client/src/views/node.tsx b/client/src/views/node.tsx index 4da933e6..e56a73a7 100644 --- a/client/src/views/node.tsx +++ b/client/src/views/node.tsx @@ -60,7 +60,7 @@ export default class NodeView extends Base {
- {item ? ( + {item && item.status ? ( {getUptime(item)} ) : ( @@ -84,7 +84,8 @@ export default class NodeView extends Base {
- {!item ? : ( + {!item && } + {item && item.status ? (
@@ -96,12 +97,13 @@ export default class NodeView extends Base { {getTaints(item)}
- )} + ) : null}
Conditions
- {!item ? : ( + {!item && } + {item && item.status ? ( @@ -124,7 +126,7 @@ export default class NodeView extends Base { ))}
- )} + ) : null}
Pods
diff --git a/client/src/views/pod.tsx b/client/src/views/pod.tsx index b84deefe..aeae8725 100644 --- a/client/src/views/pod.tsx +++ b/client/src/views/pod.tsx @@ -50,9 +50,14 @@ export default class PodView extends Base { const {item, metrics, events} = this.state || {}; const errors = getErrors(item); - const filteredEvents = filterByOwner(events, item); - // @ts-ignore - const filteredMetrics = getMetrics(item && [item], metrics && [metrics]); + let filteredEvents; + let filteredMetrics; + + if (item?.metadata) { + filteredEvents = filterByOwner(events, item); + // @ts-ignore + filteredMetrics = getMetrics(item && [item], metrics && [metrics]); + } return (
@@ -87,7 +92,8 @@ export default class PodView extends Base {
- {!item ? : ( + {!item && } + {item && item.status ? (
@@ -123,7 +129,7 @@ export default class PodView extends Base { {objectMap(item.spec.nodeSelector)}
- )} + ) : null}