diff options
author | Stefano Pogliani <stefano@spogliani.net> | 2020-03-23 20:54:19 +0000 |
---|---|---|
committer | Stefano Pogliani <stefano@spogliani.net> | 2020-03-26 23:11:07 +0000 |
commit | df568e4963944d36f877aa36831e2f6892dbaf04 (patch) | |
tree | 35df2a738d1e60d49936c4ad64cfec86e5bdd732 /cmd/podman/shared/pod.go | |
parent | 6a46a87d08bd1e9ddda3dd3c9c30d21d2226a654 (diff) | |
download | podman-df568e4963944d36f877aa36831e2f6892dbaf04.tar.gz podman-df568e4963944d36f877aa36831e2f6892dbaf04.tar.bz2 podman-df568e4963944d36f877aa36831e2f6892dbaf04.zip |
Support label filters for podman pod ps.
Update the podman pod ps command to support filtering by labels.
This brings the command in line with the documentation as well as
the functionality by the containers equivalent podman ps.
Signed-off-by: Stefano Pogliani <stefano@spogliani.net>
Diffstat (limited to 'cmd/podman/shared/pod.go')
-rw-r--r-- | cmd/podman/shared/pod.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cmd/podman/shared/pod.go b/cmd/podman/shared/pod.go index 3046953b5..50bd88e08 100644 --- a/cmd/podman/shared/pod.go +++ b/cmd/podman/shared/pod.go @@ -162,7 +162,7 @@ func FilterAllPodsWithFilterFunc(r *libpod.Runtime, filters ...libpod.PodFilter) func GenerateFilterFunction(r *libpod.Runtime, filters []string) ([]libpod.PodFilter, error) { var filterFuncs []libpod.PodFilter for _, f := range filters { - filterSplit := strings.Split(f, "=") + filterSplit := strings.SplitN(f, "=", 2) if len(filterSplit) < 2 { return nil, errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f) } @@ -256,6 +256,22 @@ func generatePodFilterFuncs(filter, filterValue string) ( } return false }, nil + case "label": + var filterArray = strings.SplitN(filterValue, "=", 2) + var filterKey = filterArray[0] + if len(filterArray) > 1 { + filterValue = filterArray[1] + } else { + filterValue = "" + } + return func(p *libpod.Pod) bool { + for labelKey, labelValue := range p.Labels() { + if labelKey == filterKey && ("" == filterValue || labelValue == filterValue) { + return true + } + } + return false + }, nil } return nil, errors.Errorf("%s is an invalid filter", filter) } |