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.
This commit is contained in:
Ta-Ching Chen
2017-03-05 11:01:47 -08:00
committed by Soam Vasani
parent 6af605bfe8
commit ad63ba63c8
+5 -2
View File
@@ -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
}