Merge pull request #48786 from janetkuo/show-all-fix

Automatic merge from submit-queue (batch tested with PRs 48672, 47140, 48709, 48786, 48757)

Correctly filter terminated pods in kubectl

We shouldn't use `Status.Reason` to determine whether the pod has terminated or not.
This commit is contained in:
Kubernetes Submit Queue 2017-07-12 09:02:57 -07:00 committed by GitHub
commit b996d8abce

View File

@ -38,21 +38,18 @@ func NewResourceFilter() Filters {
}
// filterPods returns true if a pod should be skipped.
// defaults to true for terminated pods
// If show-all is true, the pod will be never be skipped (return false);
// otherwise, skip terminated pod.
func filterPods(obj runtime.Object, options printers.PrintOptions) bool {
if options.ShowAll {
return false
}
switch p := obj.(type) {
case *v1.Pod:
reason := string(p.Status.Phase)
if p.Status.Reason != "" {
reason = p.Status.Reason
}
return !options.ShowAll && (reason == string(v1.PodSucceeded) || reason == string(v1.PodFailed))
return p.Status.Phase == v1.PodSucceeded || p.Status.Phase == v1.PodFailed
case *api.Pod:
reason := string(p.Status.Phase)
if p.Status.Reason != "" {
reason = p.Status.Reason
}
return !options.ShowAll && (reason == string(api.PodSucceeded) || reason == string(api.PodFailed))
return p.Status.Phase == api.PodSucceeded || p.Status.Phase == api.PodFailed
}
return false
}