diff options
author | baude <bbaude@redhat.com> | 2020-12-22 09:15:28 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-12-22 09:40:39 -0600 |
commit | c50c75419b80791d6dd086ced608c41b2f3d96b6 (patch) | |
tree | 5c09faf305f4073f89a302d7c30a9019d2e99878 /libpod | |
parent | 182646b01a4544902c9fdf9326889a0ced7d9a8e (diff) | |
download | podman-c50c75419b80791d6dd086ced608c41b2f3d96b6.tar.gz podman-c50c75419b80791d6dd086ced608c41b2f3d96b6.tar.bz2 podman-c50c75419b80791d6dd086ced608c41b2f3d96b6.zip |
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 <bbaude@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/filters/containers.go | 31 |
1 files changed, 31 insertions, 0 deletions
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) } |