From a4f58fbf100a4272d5f246ba0a8df7d68d0905d4 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Fri, 7 Sep 2018 22:17:07 +0800 Subject: [PATCH] Check pod container ready state (#861) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure pod is ready by checking pod’s containers state and deletionTimestamp --- common.go | 9 ++++++++- executor/poolmgr/gp.go | 16 +++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/common.go b/common.go index 83ce6f47..e925490e 100644 --- a/common.go +++ b/common.go @@ -108,13 +108,20 @@ func IsNetworkDialError(err error) bool { return false } -// IsReadyPod checks that all containers in a pod are ready and returns true if so +// IsReadyPod checks both all containers in a pod are ready and whether +// the .metadata.DeletionTimestamp is nil. func IsReadyPod(pod *apiv1.Pod) bool { // since its a utility function, just ensuring there is no nil pointer exception if pod == nil { return false } + // pod is in "Terminating" status if deletionTimestamp is not nil + // https://github.com/kubernetes/kubernetes/issues/61376 + if pod.ObjectMeta.DeletionTimestamp != nil { + return false + } + for _, cStatus := range pod.Status.ContainerStatuses { if !cStatus.Ready { return false diff --git a/executor/poolmgr/gp.go b/executor/poolmgr/gp.go index 5923e4d6..8277a2b8 100644 --- a/executor/poolmgr/gp.go +++ b/executor/poolmgr/gp.go @@ -47,8 +47,6 @@ import ( "github.com/fission/fission/executor/util" ) -const POD_PHASE_RUNNING string = "Running" - type ( GenericPool struct { env *crd.Environment @@ -228,21 +226,13 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro for i := range podList.Items { pod := podList.Items[i] - // If a pod has no IP it's not ready - if len(pod.Status.PodIP) == 0 || string(pod.Status.Phase) != POD_PHASE_RUNNING { + // Ignore not ready pod here + if !fission.IsReadyPod(&pod) { continue } - // Wait for all containers in the pod to be ready - podReady := true - for _, cs := range pod.Status.ContainerStatuses { - podReady = podReady && cs.Ready - } - // add it to the list of ready pods - if podReady { - readyPods = append(readyPods, &pod) - } + readyPods = append(readyPods, &pod) } log.Printf("[%v] found %v ready pods of %v total", newLabels, len(readyPods), len(podList.Items))