From c50c75419b80791d6dd086ced608c41b2f3d96b6 Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 22 Dec 2020 09:15:28 -0600 Subject: add pod filter for ps adds the ability to filter containers based on the filter "pod". the value can be a pod name or its full or partial id. Fixes: #8512 Signed-off-by: baude --- libpod/filters/containers.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libpod/filters') diff --git a/libpod/filters/containers.go b/libpod/filters/containers.go index 2520c4f30..505429de6 100644 --- a/libpod/filters/containers.go +++ b/libpod/filters/containers.go @@ -203,6 +203,37 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo } return false }, nil + case "pod": + var pods []*libpod.Pod + for _, podNameOrID := range filterValues { + p, err := r.LookupPod(podNameOrID) + if err != nil { + if errors.Cause(err) == define.ErrNoSuchPod { + continue + } + return nil, err + } + pods = append(pods, p) + } + return func(c *libpod.Container) bool { + // if no pods match, quick out + if len(pods) < 1 { + return false + } + // if the container has no pod id, quick out + if len(c.PodID()) < 1 { + return false + } + for _, p := range pods { + // we already looked up by name or id, so id match + // here is ok + if p.ID() == c.PodID() { + return true + } + } + return false + }, nil + } return nil, errors.Errorf("%s is an invalid filter", filter) } -- cgit v1.2.3-54-g00ecf