From 76afb50f3ae41a3cc43fca8cc41a2d2f1f1b6dcc Mon Sep 17 00:00:00 2001 From: Baron Lenardson Date: Tue, 22 Dec 2020 20:29:31 -0600 Subject: [PATCH] Consolidate filter logic to pkg subdirectory Per the conversation on pull/8724 I am consolidating filter logic and helper functions under the pkg/domain/filters dir. Signed-off-by: Baron Lenardson --- cmd/podman/system/prune.go | 4 ++-- libpod/filters/helpers.go | 20 -------------------- pkg/api/handlers/compat/containers_prune.go | 4 ++-- pkg/api/handlers/utils/pods.go | 4 ++-- {libpod => pkg/domain}/filters/containers.go | 2 +- {libpod => pkg/domain}/filters/pods.go | 2 +- pkg/domain/infra/abi/containers.go | 4 ++-- pkg/domain/infra/abi/pods.go | 4 ++-- pkg/ps/ps.go | 6 +++--- 9 files changed, 15 insertions(+), 35 deletions(-) delete mode 100644 libpod/filters/helpers.go rename {libpod => pkg/domain}/filters/containers.go (99%) rename {libpod => pkg/domain}/filters/pods.go (99%) diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go index a74363684a..93b4a1157c 100644 --- a/cmd/podman/system/prune.go +++ b/cmd/podman/system/prune.go @@ -11,8 +11,8 @@ import ( "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/validate" - lpfilters "github.com/containers/podman/v2/libpod/filters" "github.com/containers/podman/v2/pkg/domain/entities" + dfilters "github.com/containers/podman/v2/pkg/domain/filters" "github.com/spf13/cobra" ) @@ -80,7 +80,7 @@ Are you sure you want to continue? [y/N] `, volumeString) } } - pruneOptions.Filters, err = lpfilters.ParseFilterArgumentsIntoFilters(filters) + pruneOptions.Filters, err = dfilters.ParseFilterArgumentsIntoFilters(filters) if err != nil { return err } diff --git a/libpod/filters/helpers.go b/libpod/filters/helpers.go deleted file mode 100644 index 859db3a9aa..0000000000 --- a/libpod/filters/helpers.go +++ /dev/null @@ -1,20 +0,0 @@ -package lpfilters - -import ( - "net/url" - "strings" - - "github.com/pkg/errors" -) - -func ParseFilterArgumentsIntoFilters(filters []string) (url.Values, error) { - parsedFilters := make(url.Values) - for _, f := range filters { - t := strings.SplitN(f, "=", 2) - if len(t) < 2 { - return parsedFilters, errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f) - } - parsedFilters.Add(t[0], t[1]) - } - return parsedFilters, nil -} diff --git a/pkg/api/handlers/compat/containers_prune.go b/pkg/api/handlers/compat/containers_prune.go index 2cfeebcce3..a1e35dd972 100644 --- a/pkg/api/handlers/compat/containers_prune.go +++ b/pkg/api/handlers/compat/containers_prune.go @@ -4,9 +4,9 @@ import ( "net/http" "github.com/containers/podman/v2/libpod" - lpfilters "github.com/containers/podman/v2/libpod/filters" "github.com/containers/podman/v2/pkg/api/handlers/utils" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/containers/podman/v2/pkg/domain/filters" "github.com/docker/docker/api/types" "github.com/gorilla/schema" "github.com/pkg/errors" @@ -29,7 +29,7 @@ func PruneContainers(w http.ResponseWriter, r *http.Request) { } filterFuncs := make([]libpod.ContainerFilter, 0, len(query.Filters)) for k, v := range query.Filters { - generatedFunc, err := lpfilters.GenerateContainerFilterFuncs(k, v, runtime) + generatedFunc, err := filters.GenerateContainerFilterFuncs(k, v, runtime) if err != nil { utils.InternalServerError(w, err) return diff --git a/pkg/api/handlers/utils/pods.go b/pkg/api/handlers/utils/pods.go index 7506dbfd1f..0fe3a308ba 100644 --- a/pkg/api/handlers/utils/pods.go +++ b/pkg/api/handlers/utils/pods.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/containers/podman/v2/libpod" - lpfilters "github.com/containers/podman/v2/libpod/filters" "github.com/containers/podman/v2/pkg/domain/entities" + dfilters "github.com/containers/podman/v2/pkg/domain/filters" "github.com/gorilla/schema" ) @@ -31,7 +31,7 @@ func GetPods(w http.ResponseWriter, r *http.Request) ([]*entities.ListPodsReport filters := make([]libpod.PodFilter, 0, len(query.Filters)) for k, v := range query.Filters { - f, err := lpfilters.GeneratePodFilterFunc(k, v) + f, err := dfilters.GeneratePodFilterFunc(k, v) if err != nil { return nil, err } diff --git a/libpod/filters/containers.go b/pkg/domain/filters/containers.go similarity index 99% rename from libpod/filters/containers.go rename to pkg/domain/filters/containers.go index 505429de67..6abdd6b577 100644 --- a/libpod/filters/containers.go +++ b/pkg/domain/filters/containers.go @@ -1,4 +1,4 @@ -package lpfilters +package filters import ( "strconv" diff --git a/libpod/filters/pods.go b/pkg/domain/filters/pods.go similarity index 99% rename from libpod/filters/pods.go rename to pkg/domain/filters/pods.go index 17b3f3ca9c..7e6b7f2cc1 100644 --- a/libpod/filters/pods.go +++ b/pkg/domain/filters/pods.go @@ -1,4 +1,4 @@ -package lpfilters +package filters import ( "strconv" diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index efb4f866f0..cfb3421bae 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -16,12 +16,12 @@ import ( "github.com/containers/podman/v2/libpod" "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/libpod/events" - lpfilters "github.com/containers/podman/v2/libpod/filters" "github.com/containers/podman/v2/libpod/image" "github.com/containers/podman/v2/libpod/logs" "github.com/containers/podman/v2/pkg/cgroups" "github.com/containers/podman/v2/pkg/checkpoint" "github.com/containers/podman/v2/pkg/domain/entities" + dfilters "github.com/containers/podman/v2/pkg/domain/filters" "github.com/containers/podman/v2/pkg/domain/infra/abi/terminal" parallelctr "github.com/containers/podman/v2/pkg/parallel/ctr" "github.com/containers/podman/v2/pkg/ps" @@ -207,7 +207,7 @@ func (ic *ContainerEngine) ContainerStop(ctx context.Context, namesOrIds []strin func (ic *ContainerEngine) ContainerPrune(ctx context.Context, options entities.ContainerPruneOptions) (*entities.ContainerPruneReport, error) { filterFuncs := make([]libpod.ContainerFilter, 0, len(options.Filters)) for k, v := range options.Filters { - generatedFunc, err := lpfilters.GenerateContainerFilterFuncs(k, v, ic.Libpod) + generatedFunc, err := dfilters.GenerateContainerFilterFuncs(k, v, ic.Libpod) if err != nil { return nil, err } diff --git a/pkg/domain/infra/abi/pods.go b/pkg/domain/infra/abi/pods.go index 11374e5132..f108b770c3 100644 --- a/pkg/domain/infra/abi/pods.go +++ b/pkg/domain/infra/abi/pods.go @@ -5,8 +5,8 @@ import ( "github.com/containers/podman/v2/libpod" "github.com/containers/podman/v2/libpod/define" - lpfilters "github.com/containers/podman/v2/libpod/filters" "github.com/containers/podman/v2/pkg/domain/entities" + dfilters "github.com/containers/podman/v2/pkg/domain/filters" "github.com/containers/podman/v2/pkg/signal" "github.com/containers/podman/v2/pkg/specgen" "github.com/containers/podman/v2/pkg/specgen/generate" @@ -288,7 +288,7 @@ func (ic *ContainerEngine) PodPs(ctx context.Context, options entities.PodPSOpti filters := make([]libpod.PodFilter, 0, len(options.Filters)) for k, v := range options.Filters { - f, err := lpfilters.GeneratePodFilterFunc(k, v) + f, err := dfilters.GeneratePodFilterFunc(k, v) if err != nil { return nil, err } diff --git a/pkg/ps/ps.go b/pkg/ps/ps.go index 6c26e8708f..9e0dcb7281 100644 --- a/pkg/ps/ps.go +++ b/pkg/ps/ps.go @@ -11,8 +11,8 @@ import ( "github.com/containers/podman/v2/libpod" "github.com/containers/podman/v2/libpod/define" - lpfilters "github.com/containers/podman/v2/libpod/filters" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/containers/podman/v2/pkg/domain/filters" psdefine "github.com/containers/podman/v2/pkg/ps/define" "github.com/containers/storage" "github.com/pkg/errors" @@ -27,7 +27,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp all := options.All || options.Last > 0 if len(options.Filters) > 0 { for k, v := range options.Filters { - generatedFunc, err := lpfilters.GenerateContainerFilterFuncs(k, v, runtime) + generatedFunc, err := filters.GenerateContainerFilterFuncs(k, v, runtime) if err != nil { return nil, err } @@ -41,7 +41,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp all = true } if !all { - runningOnly, err := lpfilters.GenerateContainerFilterFuncs("status", []string{define.ContainerStateRunning.String()}, runtime) + runningOnly, err := filters.GenerateContainerFilterFuncs("status", []string{define.ContainerStateRunning.String()}, runtime) if err != nil { return nil, err }