summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-03-27 15:18:27 +0100
committerGitHub <noreply@github.com>2020-03-27 15:18:27 +0100
commit3ddb5b10d53df54346a6d795047124fc4e995699 (patch)
tree0dc5f6d72264aea17e0c33b708bd462983c19909 /cmd
parent7007680bfdee8c36b855a97ee45d268b24bde7d3 (diff)
parentdf568e4963944d36f877aa36831e2f6892dbaf04 (diff)
downloadpodman-3ddb5b10d53df54346a6d795047124fc4e995699.tar.gz
podman-3ddb5b10d53df54346a6d795047124fc4e995699.tar.bz2
podman-3ddb5b10d53df54346a6d795047124fc4e995699.zip
Merge pull request #5595 from stefano-pogliani/pod-ps-filter-label
Support label filters for podman pod ps
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/shared/pod.go18
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)
}