Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly filter terminated pods in kubectl #48786

Merged
merged 1 commit into from Jul 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 8 additions & 11 deletions pkg/kubectl/resource_filter.go
Expand Up @@ -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
}
Expand Down