Skip to content

Commit

Permalink
Fix for #2842, instead of returning the first Pod, return the one whi… (
Browse files Browse the repository at this point in the history
#2846)

* Fix for #2842, instead of returning the first Pod, return the one which is Running

* a more memory efficient version of the fix, string -> bool

* fix with no extra fields in struct, return nil at Pod conversion if Pod is not Running

* let Kuberneretes filter for Running Pods using FieldSelector

* filter for Pods that are Running and Pending (implicit)
  • Loading branch information
zendai authored and miekg committed May 29, 2019
1 parent 4e6c2b4 commit 7dde3f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugin/kubernetes/controller.go
Expand Up @@ -214,6 +214,10 @@ func podListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(meta
if s != nil {
opts.LabelSelector = s.String()
}
if len(opts.FieldSelector) > 0 {
opts.FieldSelector = opts.FieldSelector + ","
}
opts.FieldSelector = opts.FieldSelector + "status.phase!=Succeeded,status.phase!=Failed,status.phase!=Unknown"
listV1, err := c.CoreV1().Pods(ns).List(opts)
return listV1, err
}
Expand Down
4 changes: 4 additions & 0 deletions plugin/kubernetes/watch.go
Expand Up @@ -22,6 +22,10 @@ func podWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(opt
if s != nil {
options.LabelSelector = s.String()
}
if len(options.FieldSelector) > 0 {
options.FieldSelector = options.FieldSelector + ","
}
options.FieldSelector = options.FieldSelector + "status.phase!=Succeeded,status.phase!=Failed,status.phase!=Unknown"
w, err := c.CoreV1().Pods(ns).Watch(options)
return w, err
}
Expand Down

0 comments on commit 7dde3f3

Please sign in to comment.