1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use .status.phase instead of computing it for Pod.getStatusMessage (#4286)

This commit is contained in:
Sebastian Malton 2021-11-09 09:33:42 -05:00 committed by GitHub
parent b52bd29784
commit 200061d386
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 48 deletions

View File

@ -165,40 +165,40 @@ interface IContainerProbe {
failureThreshold?: number; 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 { export interface IPodContainerStatus {
name: string; name: string;
state?: { state?: ContainerState;
[index: string]: object; lastState?: ContainerState;
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;
};
};
ready: boolean; ready: boolean;
restartCount: number; restartCount: number;
image: string; image: string;
@ -373,23 +373,16 @@ export class Pod extends WorkloadKubeObject {
} }
// Returns pod phase or container error if occurred // Returns pod phase or container error if occurred
getStatusMessage() { getStatusMessage(): string {
if (this.getReason() === PodStatus.EVICTED) return "Evicted"; if (this.getReason() === PodStatus.EVICTED) {
if (this.metadata.deletionTimestamp) return "Terminating"; return "Evicted";
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) { if (this.metadata.deletionTimestamp) {
return state.terminated.reason || "Terminated"; return "Terminating";
}
} }
return this.getStatusPhase(); return this.getStatusPhase() || "Waiting";
} }
getStatusPhase() { getStatusPhase() {

View File

@ -69,7 +69,7 @@ export class Pods extends React.Component<Props> {
formatters: { formatters: {
tableView: true, tableView: true,
}, },
children: Object.keys(state).map(status => ( children: Object.keys(state).map((status: keyof typeof state) => (
<Fragment key={status}> <Fragment key={status}>
<div className="title"> <div className="title">
{name} <span className="text-secondary">({status}{ready ? ", ready" : ""})</span> {name} <span className="text-secondary">({status}{ready ? ", ready" : ""})</span>