Skip to content

Commit bfb3fb5

Browse files
authored
Merge pull request kubernetes#88240 from soltysh/pod_conditions
Present more concrete information about pod readiness
2 parents 62dc3ea + e77df88 commit bfb3fb5

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
@@ -767,7 +767,11 @@ func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow
767767

768768
// change pod status back to "Running" if there is at least one container still reporting as "Running" status
769769
if reason == "Completed" && hasRunning {
770-
reason = "Running"
770+
if hasPodReadyCondition(pod.Status.Conditions) {
771+
reason = "Running"
772+
} else {
773+
reason = "NotReady"
774+
}
771775
}
772776
}
773777

@@ -818,6 +822,15 @@ func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow
818822
return []metav1.TableRow{row}, nil
819823
}
820824

825+
func hasPodReadyCondition(conditions []api.PodCondition) bool {
826+
for _, condition := range conditions {
827+
if condition.Type == api.PodReady && condition.Status == api.ConditionTrue {
828+
return true
829+
}
830+
}
831+
return false
832+
}
833+
821834
func printPodTemplate(obj *api.PodTemplate, options printers.GenerateOptions) ([]metav1.TableRow, error) {
822835
row := metav1.TableRow{
823836
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
@@ -1130,7 +1130,7 @@ func TestPrintPod(t *testing.T) {
11301130
[]metav1.TableRow{{Cells: []interface{}{"test5", "1/2", "podReason", int64(6), "<unknown>"}}},
11311131
},
11321132
{
1133-
// Test pod has 2 containers, one is running and the other is completed.
1133+
// Test pod has 2 containers, one is running and the other is completed, w/o ready condition
11341134
api.Pod{
11351135
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
11361136
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
@@ -1143,6 +1143,25 @@ func TestPrintPod(t *testing.T) {
11431143
},
11441144
},
11451145
},
1146+
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "NotReady", int64(6), "<unknown>"}}},
1147+
},
1148+
{
1149+
// Test pod has 2 containers, one is running and the other is completed, with ready condition
1150+
api.Pod{
1151+
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
1152+
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
1153+
Status: api.PodStatus{
1154+
Phase: "Running",
1155+
Reason: "",
1156+
ContainerStatuses: []api.ContainerStatus{
1157+
{Ready: true, RestartCount: 3, State: api.ContainerState{Terminated: &api.ContainerStateTerminated{Reason: "Completed", ExitCode: 0}}},
1158+
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
1159+
},
1160+
Conditions: []api.PodCondition{
1161+
{Type: api.PodReady, Status: api.ConditionTrue, LastProbeTime: metav1.Time{Time: time.Now()}},
1162+
},
1163+
},
1164+
},
11461165
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "Running", int64(6), "<unknown>"}}},
11471166
},
11481167
}

0 commit comments

Comments
 (0)