import "./pod-details.scss" import * as React from "react"; import kebabCase from "lodash/kebabCase"; import { disposeOnUnmount, observer } from "mobx-react"; import { Link } from "react-router-dom"; import { autorun, observable, reaction, toJS } from "mobx"; import { Trans } from "@lingui/macro"; import { IPodMetrics, nodesApi, Pod, podsApi, pvcApi } from "../../api/endpoints"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { autobind, cssNames, interval } 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 { KubeEventDetails } from "../+events/kube-event-details"; import { PodDetailsSecrets } from "./pod-details-secrets"; import { ResourceMetrics } from "../resource-metrics"; import { podsStore } from "./pods.store"; import { getDetailsUrl } from "../../navigation"; import { KubeObjectDetailsProps } from "../kube-object"; import { getItemMetrics } from "../../api/endpoints/metrics.api"; import { PodCharts, podMetricTabs } from "./pod-charts"; import { lookupApiLink } from "../../api/kube-api"; import { apiManager } from "../../api/api-manager"; import { KubeObjectMeta } from "../kube-object/kube-object-meta"; interface Props extends KubeObjectDetailsProps { } @observer export class PodDetails extends React.Component { @observable containerMetrics: IPodMetrics; private watcher = interval(60, () => this.loadMetrics()); componentDidMount() { disposeOnUnmount(this, [ autorun(() => { this.containerMetrics = null; this.loadMetrics(); }), reaction(() => this.props.object, () => { podsStore.reset(); }) ]); this.watcher.start(); } componentWillUnmount() { podsStore.reset(); } @autobind() 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 { nodeName } = spec; const ownerRefs = pod.getOwnerRefs(); const nodeSelector = pod.getNodeSelectors(); const volumes = pod.getVolumes(); const labels = pod.getLabels(); const metrics = podsStore.metrics; return (
podsStore.loadMetrics(pod)} tabs={podMetricTabs} object={pod} params={{ metrics }} > Status}> {pod.getStatusMessage()} Node}> {nodeName && ( {nodeName} )} Pod IP}> {podIP} Priority Class}> {pod.getPriorityClassName()} QoS Class}> {pod.getQosClass()} {conditions && Conditions} className="conditions" labelsOnly> { conditions.map(condition => { const { type, status, lastTransitionTime } = condition; return ( Last transition time: {lastTransitionTime}} /> ) }) } } {nodeSelector.length > 0 && Node Selector}> { nodeSelector.map(label => ( )) } } {ownerRefs.length > 0 && Controlled By}> { ownerRefs.map(ref => { const { name, kind } = ref; const ownerDetailsUrl = getDetailsUrl(lookupApiLink(ref, pod)); return (

{kind} {name}

); }) }
} {pod.getSecrets().length > 0 && ( Secrets}> )} {pod.getInitContainers() && pod.getInitContainers().length > 0 && Init Containers}/> } { pod.getInitContainers() && pod.getInitContainers().map(container => { return }) } Containers}/> { pod.getContainers().map(container => { const { name } = container; const metrics = getItemMetrics(toJS(this.containerMetrics), name); return ( ) }) } {volumes.length > 0 && ( <> Volumes}/> {volumes.map(volume => { const claimName = volume.persistentVolumeClaim ? volume.persistentVolumeClaim.claimName : null; return (
{volume.name}
Type}> {Object.keys(volume)[1]} {claimName && ( Claim Name}> {claimName} )}
) })} )}
) } } apiManager.registerViews(podsApi, { Details: PodDetails })