Skip to content

Commit

Permalink
Merge pull request #5043 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…4878-to-release-4.4

[release-4.4] Bug 1823593: Align console pod status with CLI
  • Loading branch information
openshift-merge-robot committed Apr 15, 2020
2 parents 0f885d1 + 87ccd85 commit d61a594
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
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

0 comments on commit d61a594

Please sign in to comment.