diff --git a/src/app/frontend/podlist/podcardlist_component.js b/src/app/frontend/podlist/podcardlist_component.js
index e1544b207380..2a687f3e240b 100644
--- a/src/app/frontend/podlist/podcardlist_component.js
+++ b/src/app/frontend/podlist/podcardlist_component.js
@@ -108,6 +108,50 @@ export class PodCardListController {
stateName, new StateParams(pod.objectMeta.namespace, pod.objectMeta.name));
}
+ /**
+ * Returns a displayable status message for the pod.
+ * @param {!backendApi.Pod} pod
+ * @return {string}
+ * @export
+ */
+ getDisplayStatus(pod) {
+ let msgState = 'running';
+ let reason = undefined;
+ for (let i = pod.podStatus.containerStates.length - 1; i >= 0; i--) {
+ let state = pod.podStatus.containerStates[i];
+
+ if (state.waiting) {
+ msgState = 'waiting';
+ reason = state.waiting.reason;
+ }
+ if (state.terminated) {
+ msgState = 'terminated';
+ reason = state.terminated.reason;
+ if (!reason) {
+ if (state.terminated.signal) {
+ reason = 'Signal:${state.terminated.signal}';
+ } else {
+ reason = 'ExitCode:${state.terminated.exitCode}';
+ }
+ }
+ }
+ }
+
+ /** @type {string} @desc Status message showing a waiting status with [reason].*/
+ let MSG_POD_LIST_POD_WAITING_STATUS = goog.getMsg('Waiting: {$reason}', {'reason': reason});
+ /** @type {string} @desc Status message showing a terminated status with [reason].*/
+ let MSG_POD_LIST_POD_TERMINATED_STATUS =
+ goog.getMsg('Terminated: {$reason}', {'reason': reason});
+
+ if (msgState === 'waiting') {
+ return MSG_POD_LIST_POD_WAITING_STATUS;
+ }
+ if (msgState === 'terminated') {
+ return MSG_POD_LIST_POD_TERMINATED_STATUS;
+ }
+ return pod.podStatus.podPhase;
+ }
+
/**
* Checks if pod status is successful, i.e. running or succeeded.
* @param pod
@@ -115,7 +159,7 @@ export class PodCardListController {
* @export
*/
isStatusSuccessful(pod) {
- return pod.podPhase === 'Running' || pod.podPhase === 'Succeeded';
+ return pod.podStatus.podPhase === 'Running' || pod.podStatus.podPhase === 'Succeeded';
}
/**
@@ -125,7 +169,7 @@ export class PodCardListController {
* @export
*/
isStatusPending(pod) {
- return pod.podPhase === 'Pending';
+ return pod.podStatus.podPhase === 'Pending';
}
/**
@@ -135,7 +179,7 @@ export class PodCardListController {
* @export
*/
isStatusFailed(pod) {
- return pod.podPhase === 'Failed';
+ return pod.podStatus.podPhase === 'Failed';
}
/**
diff --git a/src/test/backend/resource/pod/podcommon_test.go b/src/test/backend/resource/pod/podcommon_test.go
index 01b906f2c967..d93464ad7e22 100644
--- a/src/test/backend/resource/pod/podcommon_test.go
+++ b/src/test/backend/resource/pod/podcommon_test.go
@@ -23,6 +23,56 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
)
+// TestToPodContainerStates tests that ToPod returns the correct container states
+func TestToPodContainerStates(t *testing.T) {
+ pod := &api.Pod{
+ Status: api.PodStatus{
+ Phase: api.PodRunning,
+ ContainerStatuses: []api.ContainerStatus{
+ api.ContainerStatus{
+ State: api.ContainerState{
+ Terminated: &api.ContainerStateTerminated{
+ Reason: "Terminated Test Reason",
+ },
+ },
+ },
+ api.ContainerStatus{
+ State: api.ContainerState{
+ Waiting: &api.ContainerStateWaiting{
+ Reason: "Waiting Test Reason",
+ },
+ },
+ },
+ },
+ },
+ }
+
+ expected := Pod{
+ TypeMeta: common.TypeMeta{Kind: common.ResourceKindPod},
+ PodStatus: PodStatus{
+ PodPhase: api.PodRunning,
+ ContainerStates: []api.ContainerState{
+ api.ContainerState{
+ Terminated: &api.ContainerStateTerminated{
+ Reason: "Terminated Test Reason",
+ },
+ },
+ api.ContainerState{
+ Waiting: &api.ContainerStateWaiting{
+ Reason: "Waiting Test Reason",
+ },
+ },
+ },
+ },
+ }
+
+ actual := ToPod(pod, &common.MetricsByPod{})
+
+ if !reflect.DeepEqual(actual, expected) {
+ t.Errorf("ToPod(%#v) == \ngot %#v, \nexpected %#v", pod, actual, expected)
+ }
+}
+
func TestGetPodDetail(t *testing.T) {
cases := []struct {
pod *api.Pod
diff --git a/src/test/frontend/podlist/podcardlist_component_test.js b/src/test/frontend/podlist/podcardlist_component_test.js
index bc6d68cde028..b6e721dac327 100644
--- a/src/test/frontend/podlist/podcardlist_component_test.js
+++ b/src/test/frontend/podlist/podcardlist_component_test.js
@@ -55,53 +55,85 @@ describe('Pod card list controller', () => {
})).toBe('#/pod/foo-namespace/foo-pod');
});
+ it('should show display status correctly (running container)', () => {
+ // Output is expected to be equal to the podPhase.
+ expect(ctrl.getDisplayStatus({
+ podStatus: {podPhase: 'Test Phase', containerStates: [{running: {}}]},
+ })).toBe('Test Phase');
+ });
+
+ it('should show display status correctly (waiting container)', () => {
+ expect(ctrl.getDisplayStatus({
+ podStatus: {
+ podPhase: 'Test Phase',
+ containerStates: [{
+ waiting: {
+ reason: 'Test Reason',
+ },
+ }],
+ },
+ })).toBe('Waiting: Test Reason');
+ });
+
+ it('should show display status correctly (terminated container)', () => {
+ expect(ctrl.getDisplayStatus({
+ podStatus: {
+ podPhase: 'Test Phase',
+ containerStates: [{
+ terminated: {
+ reason: 'Test Reason',
+ },
+ }],
+ },
+ })).toBe('Terminated: Test Reason');
+ });
+
+ it('should show display status correctly (multi container)', () => {
+ expect(ctrl.getDisplayStatus({
+ podStatus: {
+ podPhase: 'Test Phase',
+ containerStates: [
+ {running: {}},
+ {
+ terminated: {
+ reason: 'Test Terminated Reason',
+ },
+ },
+ {waiting: {reason: 'Test Waiting Reason'}},
+ ],
+ },
+ })).toBe('Terminated: Test Terminated Reason');
+ });
+
it('should check pod status correctly (succeeded is successful)', () => {
- expect(ctrl.isStatusSuccessful({
- name: 'test-pod',
- podPhase: 'Succeeded',
- })).toBeTruthy();
+ expect(ctrl.isStatusSuccessful({name: 'test-pod', podStatus: {podPhase: 'Succeeded'}}))
+ .toBeTruthy();
});
it('should check pod status correctly (running is successful)', () => {
- expect(ctrl.isStatusSuccessful({
- name: 'test-pod',
- podPhase: 'Running',
- })).toBeTruthy();
+ expect(ctrl.isStatusSuccessful({name: 'test-pod', podStatus: {podPhase: 'Running'}}))
+ .toBeTruthy();
});
it('should check pod status correctly (failed isn\'t successful)', () => {
- expect(ctrl.isStatusSuccessful({
- name: 'test-pod',
- podPhase: 'Failed',
- })).toBeFalsy();
+ expect(ctrl.isStatusSuccessful({name: 'test-pod', podStatus: {podPhase: 'Failed'}}))
+ .toBeFalsy();
});
it('should check pod status correctly (pending is pending)', () => {
- expect(ctrl.isStatusPending({
- name: 'test-pod',
- podPhase: 'Pending',
- })).toBeTruthy();
+ expect(ctrl.isStatusPending({name: 'test-pod', podStatus: {podPhase: 'Pending'}})).toBeTruthy();
});
it('should check pod status correctly (failed isn\'t pending)', () => {
- expect(ctrl.isStatusPending({
- name: 'test-pod',
- podPhase: 'Failed',
- })).toBeFalsy();
+ expect(ctrl.isStatusPending({name: 'test-pod', podStatus: {podPhase: 'Failed'}})).toBeFalsy();
});
it('should check pod status correctly (failed is failed)', () => {
- expect(ctrl.isStatusFailed({
- name: 'test-pod',
- podPhase: 'Failed',
- })).toBeTruthy();
+ expect(ctrl.isStatusFailed({name: 'test-pod', podStatus: {podPhase: 'Failed'}})).toBeTruthy();
});
it('should check pod status correctly (running isn\'t failed)', () => {
- expect(ctrl.isStatusFailed({
- name: 'test-pod',
- podPhase: 'Running',
- })).toBeFalsy();
+ expect(ctrl.isStatusFailed({name: 'test-pod', podStatus: {podPhase: 'Running'}})).toBeFalsy();
});
it('should format the "pod start date" tooltip correctly', () => {