aboutsummaryrefslogtreecommitdiff
path: root/pkg/domain/filters
diff options
context:
space:
mode:
authorJakub Guzik <jakubmguzik@gmail.com>2021-03-30 10:19:22 +0200
committerJakub Guzik <jakubmguzik@gmail.com>2021-03-30 10:19:22 +0200
commitf7d82a1f30d31830de18da14c61e85d2a0688605 (patch)
tree86be25e45d7564afc183e43df0ce5c4d3a12135b /pkg/domain/filters
parent08eab3f8f77d8206e3c788fa0a8f455ef854db1c (diff)
downloadpodman-f7d82a1f30d31830de18da14c61e85d2a0688605.tar.gz
podman-f7d82a1f30d31830de18da14c61e85d2a0688605.tar.bz2
podman-f7d82a1f30d31830de18da14c61e85d2a0688605.zip
Containers prune endpoint should use only prune filters
Containers endpoints for HTTP compad and libpod APIs allowed usage of list HTTP endpoint filter funcs. Documentation in case of libpod and compat API does not allow that. This commit aligns code with the documentation. Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
Diffstat (limited to 'pkg/domain/filters')
-rw-r--r--pkg/domain/filters/containers.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go
index 84cf03764..19d704da1 100644
--- a/pkg/domain/filters/containers.go
+++ b/pkg/domain/filters/containers.go
@@ -165,16 +165,7 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
return false
}, nil
case "until":
- until, err := util.ComputeUntilTimestamp(filterValues)
- if err != nil {
- return nil, err
- }
- return func(c *libpod.Container) bool {
- if !until.IsZero() && c.CreatedTime().After((until)) {
- return true
- }
- return false
- }, nil
+ return prepareUntilFilterFunc(filterValues)
case "pod":
var pods []*libpod.Pod
for _, podNameOrID := range filterValues {
@@ -226,3 +217,29 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
}
return nil, errors.Errorf("%s is an invalid filter", filter)
}
+
+// GeneratePruneContainerFilterFuncs return ContainerFilter functions based of filter for prune operation
+func GeneratePruneContainerFilterFuncs(filter string, filterValues []string, r *libpod.Runtime) (func(container *libpod.Container) bool, error) {
+ switch filter {
+ case "label":
+ return func(c *libpod.Container) bool {
+ return util.MatchLabelFilters(filterValues, c.Labels())
+ }, nil
+ case "until":
+ return prepareUntilFilterFunc(filterValues)
+ }
+ return nil, errors.Errorf("%s is an invalid filter", filter)
+}
+
+func prepareUntilFilterFunc(filterValues []string) (func(container *libpod.Container) bool, error) {
+ until, err := util.ComputeUntilTimestamp(filterValues)
+ if err != nil {
+ return nil, err
+ }
+ return func(c *libpod.Container) bool {
+ if !until.IsZero() && c.CreatedTime().After((until)) {
+ return true
+ }
+ return false
+ }, nil
+}