Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.4] Bug 1823593: Align console pod status with CLI #5043

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions frontend/__tests__/module/k8s/pods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ describe('podPhase', () => {
expect(phase).toEqual('Terminating');
});

it('returns `Unknown` if given pod has reason `NodeLost`', () => {
pod.status.reason = 'NodeLost';
const phase: string = podPhase(pod);

expect(phase).toEqual('Unknown');
});

it('returns the pod status phase', () => {
pod.status.phase = 'Pending';
const phase: string = podPhase(pod);
Expand All @@ -40,22 +47,15 @@ describe('podPhase', () => {
expect(phase).toEqual(pod.status.reason);
});

it('returns the state reason of the last waiting or terminated container in the pod', () => {
it('returns the state reason of the first waiting or terminated container in the pod', () => {
pod.status.containerStatuses = [
{ state: { running: {} } },
{ state: { waiting: { reason: 'Unschedulable' } } },
{ state: { terminated: { reason: 'Initialized' } } },
{ state: { waiting: { reason: 'Ready' } } },
{ state: { running: {} } },
];
const expectedPhase: string = pod.status.containerStatuses
.filter(({ state }) => state.waiting !== undefined || state.terminated !== undefined)
.map(({ state }) =>
state.waiting !== undefined ? state.waiting.reason : state.terminated.reason,
)
.slice(-1)[0];
const phase: string = podPhase(pod);

expect(phase).toEqual(expectedPhase);
expect(phase).toEqual('Unschedulable');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export const Status: React.FC<StatusProps> = ({ status, title, children, iconOnl
case 'ContainerCannotRun':
case 'CrashLoopBackOff':
case 'Critical':
case 'ErrImagePull':
case 'Error':
case 'ErrorImagePull':
case 'Failed':
case 'ImagePullBackOff':
case 'InstallCheckFailed':
Expand Down
20 changes: 14 additions & 6 deletions frontend/public/module/k8s/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export const podReadiness = (pod: PodKind): { readyCount: number; totalContainer
);
};

// This logic is replicated from k8s (at this writing, Kubernetes 1.15)
// (See https://github.com/kubernetes/kubernetes/blob/release-1.15/pkg/printers/internalversion/printers.go)
// This logic is replicated from k8s (at this writing, Kubernetes 1.17)
// (See https://github.com/kubernetes/kubernetes/blob/release-1.17/pkg/printers/internalversion/printers.go)
export const podPhase = (pod: PodKind): PodPhase => {
if (!pod || !pod.status) {
return '';
Expand All @@ -217,6 +217,10 @@ export const podPhase = (pod: PodKind): PodPhase => {
return 'Terminating';
}

if (pod.status.reason === 'NodeLost') {
return 'Unknown';
}

if (pod.status.reason === 'Evicted') {
return 'Evicted';
}
Expand Down Expand Up @@ -247,8 +251,12 @@ export const podPhase = (pod: PodKind): PodPhase => {

if (!initializing) {
let hasRunning = false;
_.each(pod.status.containerStatuses, (container: ContainerStatus) => {
const { running, terminated, waiting } = container.state;
const containerStatuses = pod.status.containerStatuses || [];
for (let i = containerStatuses.length - 1; i >= 0; i--) {
const {
state: { running, terminated, waiting },
ready,
} = containerStatuses[i];
if (terminated && terminated.reason) {
phase = terminated.reason;
} else if (waiting && waiting.reason) {
Expand All @@ -257,10 +265,10 @@ export const podPhase = (pod: PodKind): PodPhase => {
phase = terminated.signal
? `Signal:${terminated.signal}`
: `ExitCode:${terminated.exitCode}`;
} else if (running && container.ready) {
} else if (running && ready) {
hasRunning = true;
}
});
}

// Change pod status back to "Running" if there is at least one container
// still reporting as "Running" status.
Expand Down