Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 9279954

Browse files
author
aiordache
committed
Check the status of pod containers on compose up
Signed-off-by: aiordache <[email protected]>
1 parent d0e8ebe commit 9279954

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

kube/client/utils.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,27 @@ import (
2828
)
2929

3030
func podToContainerSummary(pod corev1.Pod) compose.ContainerSummary {
31+
state := compose.RUNNING
32+
33+
if pod.DeletionTimestamp != nil {
34+
state = compose.REMOVING
35+
} else {
36+
for _, container := range pod.Status.ContainerStatuses {
37+
if container.State.Waiting != nil || container.State.Terminated != nil {
38+
state = compose.UPDATING
39+
break
40+
}
41+
}
42+
if state == compose.RUNNING && pod.Status.Phase != corev1.PodRunning {
43+
state = string(pod.Status.Phase)
44+
}
45+
}
46+
3147
return compose.ContainerSummary{
3248
ID: pod.GetObjectMeta().GetName(),
3349
Name: pod.GetObjectMeta().GetName(),
3450
Service: pod.GetObjectMeta().GetLabels()[compose.ServiceTag],
35-
State: string(pod.Status.Phase),
51+
State: state,
3652
Project: pod.GetObjectMeta().GetLabels()[compose.ProjectTag],
3753
}
3854
}
@@ -46,6 +62,13 @@ func checkPodsState(services []string, pods []corev1.Pod, status string) (bool,
4662
if len(services) > 0 && !utils.StringContains(services, service) {
4763
continue
4864
}
65+
containersRunning := true
66+
for _, container := range pod.Status.ContainerStatuses {
67+
if container.State.Running == nil {
68+
containersRunning = false
69+
break
70+
}
71+
}
4972
servicePods[service] = pod.Status.Message
5073

5174
if status == compose.REMOVING {
@@ -54,7 +77,7 @@ func checkPodsState(services []string, pods []corev1.Pod, status string) (bool,
5477
if pod.Status.Phase == corev1.PodFailed {
5578
return false, servicePods, fmt.Errorf(pod.Status.Reason)
5679
}
57-
if status == compose.RUNNING && pod.Status.Phase != corev1.PodRunning {
80+
if status == compose.RUNNING && (pod.Status.Phase != corev1.PodRunning || !containersRunning) {
5881
stateReached = false
5982
}
6083
}

0 commit comments

Comments
 (0)