From 9279954193dc35687d2a6228b4b081101c07cff2 Mon Sep 17 00:00:00 2001 From: aiordache Date: Tue, 20 Apr 2021 10:26:48 +0200 Subject: [PATCH] Check the status of pod containers on `compose up` Signed-off-by: aiordache --- kube/client/utils.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/kube/client/utils.go b/kube/client/utils.go index dbe302f89..4368dc7a6 100644 --- a/kube/client/utils.go +++ b/kube/client/utils.go @@ -28,11 +28,27 @@ import ( ) func podToContainerSummary(pod corev1.Pod) compose.ContainerSummary { + state := compose.RUNNING + + if pod.DeletionTimestamp != nil { + state = compose.REMOVING + } else { + for _, container := range pod.Status.ContainerStatuses { + if container.State.Waiting != nil || container.State.Terminated != nil { + state = compose.UPDATING + break + } + } + if state == compose.RUNNING && pod.Status.Phase != corev1.PodRunning { + state = string(pod.Status.Phase) + } + } + return compose.ContainerSummary{ ID: pod.GetObjectMeta().GetName(), Name: pod.GetObjectMeta().GetName(), Service: pod.GetObjectMeta().GetLabels()[compose.ServiceTag], - State: string(pod.Status.Phase), + State: state, Project: pod.GetObjectMeta().GetLabels()[compose.ProjectTag], } } @@ -46,6 +62,13 @@ func checkPodsState(services []string, pods []corev1.Pod, status string) (bool, if len(services) > 0 && !utils.StringContains(services, service) { continue } + containersRunning := true + for _, container := range pod.Status.ContainerStatuses { + if container.State.Running == nil { + containersRunning = false + break + } + } servicePods[service] = pod.Status.Message if status == compose.REMOVING { @@ -54,7 +77,7 @@ func checkPodsState(services []string, pods []corev1.Pod, status string) (bool, if pod.Status.Phase == corev1.PodFailed { return false, servicePods, fmt.Errorf(pod.Status.Reason) } - if status == compose.RUNNING && pod.Status.Phase != corev1.PodRunning { + if status == compose.RUNNING && (pod.Status.Phase != corev1.PodRunning || !containersRunning) { stateReached = false } }