diff --git a/src/common/k8s-api/endpoints/pods.api.ts b/src/common/k8s-api/endpoints/pods.api.ts index bdcddf035d..361e72ca54 100644 --- a/src/common/k8s-api/endpoints/pods.api.ts +++ b/src/common/k8s-api/endpoints/pods.api.ts @@ -165,40 +165,40 @@ interface IContainerProbe { failureThreshold?: number; } +export interface ContainerStateRunning { + startedAt: string; +} + +export interface ContainerStateWaiting { + reason: string; + message: string; +} + +export interface ContainerStateTerminated { + startedAt: string; + finishedAt: string; + exitCode: number; + reason: string; + containerID?: string; + message?: string; + signal?: number; +} + +/** + * ContainerState holds a possible state of container. Only one of its members + * may be specified. If none of them is specified, the default one is + * `ContainerStateWaiting`. + */ +export interface ContainerState { + running?: ContainerStateRunning; + waiting?: ContainerStateWaiting; + terminated?: ContainerStateTerminated; +} + export interface IPodContainerStatus { name: string; - state?: { - [index: string]: object; - running?: { - startedAt: string; - }; - waiting?: { - reason: string; - message: string; - }; - terminated?: { - startedAt: string; - finishedAt: string; - exitCode: number; - reason: string; - }; - }; - lastState?: { - [index: string]: object; - running?: { - startedAt: string; - }; - waiting?: { - reason: string; - message: string; - }; - terminated?: { - startedAt: string; - finishedAt: string; - exitCode: number; - reason: string; - }; - }; + state?: ContainerState; + lastState?: ContainerState; ready: boolean; restartCount: number; image: string; @@ -373,23 +373,16 @@ export class Pod extends WorkloadKubeObject { } // Returns pod phase or container error if occurred - getStatusMessage() { - if (this.getReason() === PodStatus.EVICTED) return "Evicted"; - if (this.metadata.deletionTimestamp) return "Terminating"; - - const statuses = this.getContainerStatuses(false); // not including initContainers - - for (const { state } of statuses.reverse()) { - if (state.waiting) { - return state.waiting.reason || "Waiting"; - } - - if (state.terminated) { - return state.terminated.reason || "Terminated"; - } + getStatusMessage(): string { + if (this.getReason() === PodStatus.EVICTED) { + return "Evicted"; } - return this.getStatusPhase(); + if (this.metadata.deletionTimestamp) { + return "Terminating"; + } + + return this.getStatusPhase() || "Waiting"; } getStatusPhase() { diff --git a/src/renderer/components/+workloads-pods/pods.tsx b/src/renderer/components/+workloads-pods/pods.tsx index a7f3a46a62..7688861cdc 100644 --- a/src/renderer/components/+workloads-pods/pods.tsx +++ b/src/renderer/components/+workloads-pods/pods.tsx @@ -69,7 +69,7 @@ export class Pods extends React.Component { formatters: { tableView: true, }, - children: Object.keys(state).map(status => ( + children: Object.keys(state).map((status: keyof typeof state) => (
{name} ({status}{ready ? ", ready" : ""})