/** * 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 "./pod-details.scss"; import React from "react"; import kebabCase from "lodash/kebabCase"; import { disposeOnUnmount, observer } from "mobx-react"; import { Link } from "react-router-dom"; import { autorun, observable, reaction, makeObservable } from "mobx"; import { IPodMetrics, nodesApi, Pod, pvcApi, configMapApi } from "../../api/endpoints"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { boundMethod, cssNames, interval, toJS } from "../../utils"; import { PodDetailsContainer } from "./pod-details-container"; import { PodDetailsAffinities } from "./pod-details-affinities"; import { PodDetailsTolerations } from "./pod-details-tolerations"; import { Icon } from "../icon"; import { PodDetailsSecrets } from "./pod-details-secrets"; import { ResourceMetrics } from "../resource-metrics"; import { podsStore } from "./pods.store"; import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object"; import { getItemMetrics } from "../../api/endpoints/metrics.api"; import { PodCharts, podMetricTabs } from "./pod-charts"; import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../main/cluster"; interface Props extends KubeObjectDetailsProps { } @observer export class PodDetails extends React.Component { @observable containerMetrics: IPodMetrics; private watcher = interval(60, () => this.loadMetrics()); constructor(props: Props) { super(props); makeObservable(this); } componentDidMount() { disposeOnUnmount(this, [ autorun(() => { this.containerMetrics = null; this.loadMetrics(); }), reaction(() => this.props.object, () => { podsStore.reset(); }) ]); this.watcher.start(); } componentWillUnmount() { podsStore.reset(); } @boundMethod async loadMetrics() { const { object: pod } = this.props; this.containerMetrics = await podsStore.loadContainerMetrics(pod); } render() { const { object: pod } = this.props; if (!pod) return null; const { status, spec } = pod; const { conditions, podIP } = status; const podIPs = pod.getIPs(); const { nodeName } = spec; const nodeSelector = pod.getNodeSelectors(); const volumes = pod.getVolumes(); const metrics = podsStore.metrics; const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Pod); return (
{!isMetricHidden && ( podsStore.loadMetrics(pod)} tabs={podMetricTabs} object={pod} params={{ metrics }} > )} {pod.getStatusMessage()} {nodeName && ( {nodeName} )} {podIP} {pod.getPriorityClassName()} {pod.getQosClass()} {conditions && { conditions.map(condition => { const { type, status, lastTransitionTime } = condition; return ( ); }) } } {nodeSelector.length > 0 && { nodeSelector.map(label => ( )) } } {pod.getSecrets().length > 0 && ( )} {pod.getInitContainers() && pod.getInitContainers().length > 0 && } { pod.getInitContainers() && pod.getInitContainers().map(container => { return ; }) } { pod.getContainers().map(container => { const { name } = container; const metrics = getItemMetrics(toJS(this.containerMetrics), name); return ( ); }) } {volumes.length > 0 && ( <> {volumes.map(volume => { const claimName = volume.persistentVolumeClaim ? volume.persistentVolumeClaim.claimName : null; const configMap = volume.configMap ? volume.configMap.name : null; const type = Object.keys(volume)[1]; return (
{volume.name}
{type} { type == "configMap" && (
{configMap && ( {configMap} )}
)} { type === "emptyDir" && (
{ volume.emptyDir.medium && ( {volume.emptyDir.medium} )} { volume.emptyDir.sizeLimit && ( {volume.emptyDir.sizeLimit} )}
)} {claimName && ( {claimName} )}
); })} )}
); } }