/** * Copyright (c) 2021 OpenLens Authors * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import "./node-details.scss"; import React from "react"; import upperFirst from "lodash/upperFirst"; import kebabCase from "lodash/kebabCase"; import { disposeOnUnmount, observer } from "mobx-react"; import { DrawerItem, DrawerItemLabels } from "../drawer"; import { Badge } from "../badge"; import { nodesStore } from "./nodes.store"; import { ResourceMetrics } from "../resource-metrics"; import { podsStore } from "../+workloads-pods/pods.store"; import type { KubeObjectDetailsProps } from "../kube-object"; import type { Node } from "../../api/endpoints"; import { NodeCharts } from "./node-charts"; import { reaction } from "mobx"; import { PodDetailsList } from "../+workloads-pods/pod-details-list"; import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeEventDetails } from "../+events/kube-event-details"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting"; import { ClusterStore } from "../../../common/cluster-store"; interface Props extends KubeObjectDetailsProps { } @observer export class NodeDetails extends React.Component { @disposeOnUnmount clean = reaction(() => this.props.object.getName(), () => { nodesStore.nodeMetrics = null; }); async componentDidMount() { podsStore.reloadAll(); } componentWillUnmount() { nodesStore.nodeMetrics = null; } render() { const { object: node } = this.props; if (!node) return null; const { status } = node; const { nodeInfo, addresses, capacity, allocatable } = status; const conditions = node.getActiveConditions(); const taints = node.getTaints(); const childPods = podsStore.getPodsByNode(node.getName()); const metrics = nodesStore.nodeMetrics; const metricTabs = [ "CPU", "Memory", "Disk", "Pods", ]; const isMetricHidden = ClusterStore.getInstance().isMetricHidden(ResourceType.Node); return (
{!isMetricHidden && podsStore.isLoaded && ( nodesStore.loadMetrics(node.getName())} tabs={metricTabs} object={node} params={{ metrics }} > )} CPU: {capacity.cpu},{" "} Memory: {Math.floor(parseInt(capacity.memory) / 1024)}Mi,{" "} Pods: {capacity.pods} CPU: {allocatable.cpu},{" "} Memory: {Math.floor(parseInt(allocatable.memory) / 1024)}Mi,{" "} Pods: {allocatable.pods} {addresses && { addresses.map(({ type, address }) => (

{type}: {address}

)) }
} {nodeInfo.operatingSystem} ({nodeInfo.architecture}) {nodeInfo.osImage} {nodeInfo.kernelVersion} {nodeInfo.containerRuntimeVersion} {nodeInfo.kubeletVersion} {taints.length > 0 && ( { taints.map(({ key, effect, value }) => ( )) } )} {conditions && { conditions.map(condition => { const { type } = condition; return (
{upperFirst(key)}
{value}
) }} /> ); }) }
}
); } } kubeObjectDetailRegistry.add({ kind: "Node", apiVersions: ["v1"], components: { Details: (props) => } }); kubeObjectDetailRegistry.add({ kind: "Node", apiVersions: ["v1"], priority: 5, components: { Details: (props) => } });