From ad63ba63c88a45fcf7a292f295efccc4ebcd6ed3 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Mon, 6 Mar 2017 03:01:47 +0800 Subject: [PATCH] Fixed pod has no ip (#139) (#141) Fixes #139. The code before this change was saving up pointers to the loop variable in a slice. So loop was useless and we always chose the last pod in the list, whether it was ready or not. With this fix, choosePod should always return a ready pod. Also adds a check for the pod phase, before looping over the containers in the pod, and discard pods that aren't running yet. --- poolmgr/gp.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/poolmgr/gp.go b/poolmgr/gp.go index cf8a6ee5..49678a23 100644 --- a/poolmgr/gp.go +++ b/poolmgr/gp.go @@ -40,6 +40,7 @@ import ( ) const POOLMGR_INSTANCEID_LABEL string = "poolmgrInstanceId" +const POD_PHASE_RUNNING string = "Running" type ( GenericPool struct { @@ -166,9 +167,11 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*v1.Pod, error) return nil, err } readyPods := make([]*v1.Pod, 0, len(podList.Items)) - for _, pod := range podList.Items { + 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 { + if len(pod.Status.PodIP) == 0 || string(pod.Status.Phase) != POD_PHASE_RUNNING { continue }