/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ 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 { observable, reaction, makeObservable } from "mobx"; import { IPodMetrics, nodesApi, Pod, pvcApi, configMapApi, getMetricsForPods } from "../../../common/k8s-api/endpoints"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { boundMethod, cssNames, 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 type { KubeObjectDetailsProps } from "../kube-object-details"; import { getItemMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { PodCharts, podMetricTabs } from "./pod-charts"; import { KubeObjectMeta } from "../kube-object-meta"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { getDetailsUrl } from "../kube-detail-params"; import logger from "../../../common/logger"; interface Props extends KubeObjectDetailsProps { } @observer export class PodDetails extends React.Component { @observable metrics: IPodMetrics; @observable containerMetrics: IPodMetrics; constructor(props: Props) { super(props); makeObservable(this); } componentDidMount() { disposeOnUnmount(this, [ reaction(() => this.props.object, () => { this.metrics = null; this.containerMetrics = null; }), ]); } @boundMethod async loadMetrics() { const { object: pod } = this.props; this.metrics = await getMetricsForPods([pod], pod.getNs()); this.containerMetrics = await getMetricsForPods([pod], pod.getNs(), "container, namespace"); } render() { const { object: pod } = this.props; if (!pod) { return null; } if (!(pod instanceof Pod)) { logger.error("[PodDetails]: passed object that is not an instanceof Pod", 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 isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Pod); return (
{!isMetricHidden && ( )} {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} )}
); })} )}
); } }