/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./pod-details-container.scss"; import React from "react"; import type { IPodContainer, IPodContainerStatus, Pod } from "../../../common/k8s-api/endpoints"; import { DrawerItem } from "../drawer"; import { cssNames } from "../../utils"; import { StatusBrick } from "../status-brick"; import { Badge } from "../badge"; import { ContainerEnvironment } from "./pod-container-env"; import { PodContainerPort } from "./pod-container-port"; import { ResourceMetrics } from "../resource-metrics"; import type { IMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { ContainerCharts } from "./container-charts"; import { LocaleDate } from "../locale-date"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import type { PortForwardStore } from "../../port-forward"; import { disposeOnUnmount, observer } from "mobx-react"; import { withInjectables } from "@ogre-tools/injectable-react"; import portForwardStoreInjectable from "../../port-forward/port-forward-store/port-forward-store.injectable"; export interface PodDetailsContainerProps { pod: Pod; container: IPodContainer; metrics?: { [key: string]: IMetrics }; } interface Dependencies { portForwardStore: PortForwardStore; } @observer class NonInjectedPodDetailsContainer extends React.Component { componentDidMount() { disposeOnUnmount(this, [ this.props.portForwardStore.watch(), ]); } renderStatus(state: string, status: IPodContainerStatus) { const ready = status ? status.ready : ""; return ( {state}{ready ? `, ready` : ""} {state === "terminated" ? ` - ${status.state.terminated.reason} (exit code: ${status.state.terminated.exitCode})` : ""} ); } renderLastState(lastState: string, status: IPodContainerStatus) { if (lastState === "terminated") { return ( {lastState}
Reason: {status.lastState.terminated.reason} - exit code: {status.lastState.terminated.exitCode}
Started at: {}
Finished at: {}
); } return null; } render() { const { pod, container, metrics } = this.props; if (!pod || !container) return null; const { name, image, imagePullPolicy, ports, volumeMounts, command, args } = container; const status = pod.getContainerStatuses().find(status => status.name === container.name); const state = status ? Object.keys(status.state)[0] : ""; const lastState = status ? Object.keys(status.lastState)[0] : ""; const ready = status ? status.ready : ""; const imageId = status? status.imageID : ""; const liveness = pod.getLivenessProbe(container); const readiness = pod.getReadinessProbe(container); const startup = pod.getStartupProbe(container); const isInitContainer = !!pod.getInitContainers().find(c => c.name == name); const metricTabs = [ "CPU", "Memory", "Filesystem", ]; const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Container); return (
{name}
{!isMetricHidden && !isInitContainer && } {status && {this.renderStatus(state, status)} } {lastState && {this.renderLastState(lastState, status)} } {imagePullPolicy && imagePullPolicy !== "IfNotPresent" && {imagePullPolicy} } {ports && ports.length > 0 && { ports.map((port) => { const key = `${container.name}-port-${port.containerPort}-${port.protocol}`; return ( ); }) } } {} {volumeMounts && volumeMounts.length > 0 && { volumeMounts.map(mount => { const { name, mountPath, readOnly } = mount; return ( {mountPath} from {name} ({readOnly ? "ro" : "rw"}) ); }) } } {liveness.length > 0 && { liveness.map((value, index) => ( )) } } {readiness.length > 0 && { readiness.map((value, index) => ( )) } } {startup.length > 0 && { startup.map((value, index) => ( )) } } {command && {command.join(" ")} } {args && {args.join(" ")} }
); } } export const PodDetailsContainer = withInjectables( NonInjectedPodDetailsContainer, { getProps: (di, props) => ({ portForwardStore: di.inject(portForwardStoreInjectable), ...props, }), }, );