|
@@ -1,26 +1,19 @@
|
|
|
import React, { useContext, useEffect, useMemo, useState } from "react";
|
|
import React, { useContext, useEffect, useMemo, useState } from "react";
|
|
|
|
|
|
|
|
import Table from "components/Table";
|
|
import Table from "components/Table";
|
|
|
-import { Column } from "react-table";
|
|
|
|
|
|
|
+import { Column, Row } from "react-table";
|
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
|
import api from "shared/api";
|
|
import api from "shared/api";
|
|
|
import { Context } from "shared/Context";
|
|
import { Context } from "shared/Context";
|
|
|
-import { NodeStatusModal } from "./NodeStatusModal";
|
|
|
|
|
|
|
+import { pushFiltered } from "shared/routing";
|
|
|
|
|
+import { useHistory, useLocation } from "react-router";
|
|
|
|
|
|
|
|
const NodeList: React.FC = () => {
|
|
const NodeList: React.FC = () => {
|
|
|
const context = useContext(Context);
|
|
const context = useContext(Context);
|
|
|
const [nodeList, setNodeList] = useState([]);
|
|
const [nodeList, setNodeList] = useState([]);
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
- const [selectedNode, setSelectedNode] = useState<any>(undefined);
|
|
|
|
|
-
|
|
|
|
|
- const triggerPopUp = (node?: any) => {
|
|
|
|
|
- if (node) {
|
|
|
|
|
- setSelectedNode(node);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- setSelectedNode(undefined);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const history = useHistory();
|
|
|
|
|
+ const location = useLocation();
|
|
|
|
|
|
|
|
const columns = useMemo<Column<any>[]>(
|
|
const columns = useMemo<Column<any>[]>(
|
|
|
() => [
|
|
() => [
|
|
@@ -28,6 +21,10 @@ const NodeList: React.FC = () => {
|
|
|
Header: "Node name",
|
|
Header: "Node name",
|
|
|
accessor: "name",
|
|
accessor: "name",
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ Header: "Machine type",
|
|
|
|
|
+ accessor: "machine_type",
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
Header: "CPU Usage",
|
|
Header: "CPU Usage",
|
|
|
accessor: "cpu_usage",
|
|
accessor: "cpu_usage",
|
|
@@ -42,10 +39,7 @@ const NodeList: React.FC = () => {
|
|
|
Cell: ({ row }) => {
|
|
Cell: ({ row }) => {
|
|
|
return (
|
|
return (
|
|
|
<StatusButtonWrapper>
|
|
<StatusButtonWrapper>
|
|
|
- <StatusButton
|
|
|
|
|
- success={row.values.is_node_healthy}
|
|
|
|
|
- onClick={() => triggerPopUp(row.original)}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <StatusButton success={row.values.is_node_healthy}>
|
|
|
{row.values.is_node_healthy ? "Healthy" : "Unhealthy"}
|
|
{row.values.is_node_healthy ? "Healthy" : "Unhealthy"}
|
|
|
</StatusButton>
|
|
</StatusButton>
|
|
|
</StatusButtonWrapper>
|
|
</StatusButtonWrapper>
|
|
@@ -60,12 +54,17 @@ const NodeList: React.FC = () => {
|
|
|
const percentFormatter = (number: number) =>
|
|
const percentFormatter = (number: number) =>
|
|
|
`${Number(number).toFixed(2)}%`;
|
|
`${Number(number).toFixed(2)}%`;
|
|
|
|
|
|
|
|
|
|
+ const getMachineType = (labels: any) => {
|
|
|
|
|
+ return (labels && labels["node.kubernetes.io/instance-type"]) || "N/A";
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return nodeList
|
|
return nodeList
|
|
|
.map((node) => {
|
|
.map((node) => {
|
|
|
return {
|
|
return {
|
|
|
name: node.name,
|
|
name: node.name,
|
|
|
- cpu_usage: percentFormatter(node.cpu_reqs),
|
|
|
|
|
- ram_usage: percentFormatter(node.memory_reqs),
|
|
|
|
|
|
|
+ machine_type: getMachineType(node?.labels),
|
|
|
|
|
+ cpu_usage: percentFormatter(node.fraction_cpu_reqs),
|
|
|
|
|
+ ram_usage: percentFormatter(node.fraction_memory_reqs),
|
|
|
node_conditions: node.node_conditions,
|
|
node_conditions: node.node_conditions,
|
|
|
is_node_healthy: node.node_conditions.reduce(
|
|
is_node_healthy: node.node_conditions.reduce(
|
|
|
(prevValue: boolean, current: any) => {
|
|
(prevValue: boolean, current: any) => {
|
|
@@ -113,14 +112,27 @@ const NodeList: React.FC = () => {
|
|
|
.finally(() => setLoading(false));
|
|
.finally(() => setLoading(false));
|
|
|
}, [context, setNodeList]);
|
|
}, [context, setNodeList]);
|
|
|
|
|
|
|
|
|
|
+ const handleOnRowClick = (row: any) => {
|
|
|
|
|
+ pushFiltered(
|
|
|
|
|
+ {
|
|
|
|
|
+ history,
|
|
|
|
|
+ location,
|
|
|
|
|
+ },
|
|
|
|
|
+ `/cluster-dashboard/node-view/${row.original.name}`,
|
|
|
|
|
+ []
|
|
|
|
|
+ );
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<NodeListWrapper>
|
|
<NodeListWrapper>
|
|
|
<StyledChart>
|
|
<StyledChart>
|
|
|
- <Table columns={columns} data={data} isLoading={loading} />
|
|
|
|
|
|
|
+ <Table
|
|
|
|
|
+ columns={columns}
|
|
|
|
|
+ data={data}
|
|
|
|
|
+ isLoading={loading}
|
|
|
|
|
+ onRowClick={handleOnRowClick}
|
|
|
|
|
+ />
|
|
|
</StyledChart>
|
|
</StyledChart>
|
|
|
- {selectedNode && (
|
|
|
|
|
- <NodeStatusModal node={selectedNode} onClose={() => triggerPopUp()} />
|
|
|
|
|
- )}
|
|
|
|
|
</NodeListWrapper>
|
|
</NodeListWrapper>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|