Skip to content

Commit e77df88

Browse files
committed
Present more concrete information about pod readiness
1 parent 3ed0f1b commit e77df88

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pkg/printers/internalversion/printers.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,11 @@ func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow
756756

757757
// change pod status back to "Running" if there is at least one container still reporting as "Running" status
758758
if reason == "Completed" && hasRunning {
759-
reason = "Running"
759+
if hasPodReadyCondition(pod.Status.Conditions) {
760+
reason = "Running"
761+
} else {
762+
reason = "NotReady"
763+
}
760764
}
761765
}
762766

@@ -807,6 +811,15 @@ func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow
807811
return []metav1.TableRow{row}, nil
808812
}
809813

814+
func hasPodReadyCondition(conditions []api.PodCondition) bool {
815+
for _, condition := range conditions {
816+
if condition.Type == api.PodReady && condition.Status == api.ConditionTrue {
817+
return true
818+
}
819+
}
820+
return false
821+
}
822+
810823
func printPodTemplate(obj *api.PodTemplate, options printers.GenerateOptions) ([]metav1.TableRow, error) {
811824
row := metav1.TableRow{
812825
Object: runtime.RawExtension{Object: obj},

pkg/printers/internalversion/printers_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ func TestPrintPod(t *testing.T) {
10641064
[]metav1.TableRow{{Cells: []interface{}{"test5", "1/2", "podReason", int64(6), "<unknown>"}}},
10651065
},
10661066
{
1067-
// Test pod has 2 containers, one is running and the other is completed.
1067+
// Test pod has 2 containers, one is running and the other is completed, w/o ready condition
10681068
api.Pod{
10691069
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
10701070
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
@@ -1077,6 +1077,25 @@ func TestPrintPod(t *testing.T) {
10771077
},
10781078
},
10791079
},
1080+
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "NotReady", int64(6), "<unknown>"}}},
1081+
},
1082+
{
1083+
// Test pod has 2 containers, one is running and the other is completed, with ready condition
1084+
api.Pod{
1085+
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
1086+
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
1087+
Status: api.PodStatus{
1088+
Phase: "Running",
1089+
Reason: "",
1090+
ContainerStatuses: []api.ContainerStatus{
1091+
{Ready: true, RestartCount: 3, State: api.ContainerState{Terminated: &api.ContainerStateTerminated{Reason: "Completed", ExitCode: 0}}},
1092+
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
1093+
},
1094+
Conditions: []api.PodCondition{
1095+
{Type: api.PodReady, Status: api.ConditionTrue, LastProbeTime: metav1.Time{Time: time.Now()}},
1096+
},
1097+
},
1098+
},
10801099
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "Running", int64(6), "<unknown>"}}},
10811100
},
10821101
}

0 commit comments

Comments
 (0)