mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Present more concrete information about pod readiness
This commit is contained in:
parent
3ed0f1bec1
commit
e77df88200
@ -756,7 +756,11 @@ func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow
|
|||||||
|
|
||||||
// change pod status back to "Running" if there is at least one container still reporting as "Running" status
|
// change pod status back to "Running" if there is at least one container still reporting as "Running" status
|
||||||
if reason == "Completed" && hasRunning {
|
if reason == "Completed" && hasRunning {
|
||||||
reason = "Running"
|
if hasPodReadyCondition(pod.Status.Conditions) {
|
||||||
|
reason = "Running"
|
||||||
|
} else {
|
||||||
|
reason = "NotReady"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,6 +811,15 @@ func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow
|
|||||||
return []metav1.TableRow{row}, nil
|
return []metav1.TableRow{row}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasPodReadyCondition(conditions []api.PodCondition) bool {
|
||||||
|
for _, condition := range conditions {
|
||||||
|
if condition.Type == api.PodReady && condition.Status == api.ConditionTrue {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func printPodTemplate(obj *api.PodTemplate, options printers.GenerateOptions) ([]metav1.TableRow, error) {
|
func printPodTemplate(obj *api.PodTemplate, options printers.GenerateOptions) ([]metav1.TableRow, error) {
|
||||||
row := metav1.TableRow{
|
row := metav1.TableRow{
|
||||||
Object: runtime.RawExtension{Object: obj},
|
Object: runtime.RawExtension{Object: obj},
|
||||||
|
@ -1064,7 +1064,7 @@ func TestPrintPod(t *testing.T) {
|
|||||||
[]metav1.TableRow{{Cells: []interface{}{"test5", "1/2", "podReason", int64(6), "<unknown>"}}},
|
[]metav1.TableRow{{Cells: []interface{}{"test5", "1/2", "podReason", int64(6), "<unknown>"}}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test pod has 2 containers, one is running and the other is completed.
|
// Test pod has 2 containers, one is running and the other is completed, w/o ready condition
|
||||||
api.Pod{
|
api.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
|
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
|
||||||
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||||
@ -1077,6 +1077,25 @@ func TestPrintPod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "NotReady", int64(6), "<unknown>"}}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Test pod has 2 containers, one is running and the other is completed, with ready condition
|
||||||
|
api.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "test6"},
|
||||||
|
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||||
|
Status: api.PodStatus{
|
||||||
|
Phase: "Running",
|
||||||
|
Reason: "",
|
||||||
|
ContainerStatuses: []api.ContainerStatus{
|
||||||
|
{Ready: true, RestartCount: 3, State: api.ContainerState{Terminated: &api.ContainerStateTerminated{Reason: "Completed", ExitCode: 0}}},
|
||||||
|
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||||
|
},
|
||||||
|
Conditions: []api.PodCondition{
|
||||||
|
{Type: api.PodReady, Status: api.ConditionTrue, LastProbeTime: metav1.Time{Time: time.Now()}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "Running", int64(6), "<unknown>"}}},
|
[]metav1.TableRow{{Cells: []interface{}{"test6", "1/2", "Running", int64(6), "<unknown>"}}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user