Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow consistent exclusion filters between 'podman container list' & 'podman image list' #21398

Open
GrabbenD opened this issue Jan 28, 2024 · 7 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@GrabbenD
Copy link

GrabbenD commented Jan 28, 2024

Feature request description

$ podman image list allows the following syntax:

image filter "intermediate": must be in the format "filter=value or filter!=value"

Here's a working example:

podman image list \
    --filter='containers!=true' \
    --no-trunc='1' \
    --quiet='1'

However, currently when using $ podman container list this syntax only works for label filter:

Error: status! is an invalid filter

Providing a consistent filtering experience would allow us to transform this:

podman container list \
    --external='1' \
    --filter='status=created' \
    --filter='status=exited' \
    --filter='status=paused' \
    --filter='status=unknown' \
    --no-trunc='1' \
    --quiet='1'

Into:

podman container list \
    --external='1' \
    --filter='status!=running' \
    --no-trunc='1' \
    --quiet='1'

Suggest potential solution

Re-use code from podman image list --filter flag in $ podman container list --filter

Have you considered any alternatives?

Specifying filters manually by hand as shown above

Additional context

N/A

@GrabbenD GrabbenD added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 28, 2024
@GrabbenD GrabbenD changed the title Use consistent exclusion filters between podman container list Allow consistent exclusion filters between 'podman container list' & 'podman image list' Jan 28, 2024
@robbmanes
Copy link
Contributor

robbmanes commented Jan 29, 2024

Containers are filtered using a container-specific filter in GenerateContainerFilterFuncs

func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpod.Runtime) (func(container *libpod.Container) bool, error) {
whereas the images filter is from compileImageFilters https://github.com/containers/common/blob/179239ade65265594d3fb0495f0c4599a85dfa50/libimage/filters.go#L75 in c/common AFAIK. Even if merging the two routes would be ill advised, sharing syntax would be nice IMHO.

"Quick" fix would be adding negate logic to the GenerateContainerFilterFuncs to execute like the compileImageFilters logic has. Not as robust as sharing the same paths but would theoretically produce the same outputs.

@robbmanes
Copy link
Contributor

Talked with @mheon; I'm going to try and rectify the c/common/filters package into this so we have a unified filter method going forward, instead of the quick fix. We could just add negate logic in c/podman for just the status term to get the behavior you described for both commands but then we're still likely to drift into different filter values as time goes on between listing containers and images. That will probably happen anyway over time due to the nature of listing containers being different than what c/common would need, but worth a shot regardless to try and unify them now for cleanliness/robustness.

@mtrmac
Copy link
Collaborator

mtrmac commented Jan 30, 2024

FWIW, compare containers/common#1800 . The filters don’t really have a regular syntax, reference=foo,reference=bar is an OR, but (in Podman) reference!=foo,reference!=bar is an AND … and they can be both present simultaneously.

That might well be a unique special case for reference, I don’t know. Just a thing to keep in mind.

Copy link

github-actions bot commented Mar 1, 2024

A friendly reminder that this issue had no activity for 30 days.

@GrabbenD
Copy link
Author

GrabbenD commented Mar 1, 2024

Bump

@rhatdan
Copy link
Member

rhatdan commented Mar 1, 2024

@robbmanes any progress?

@robbmanes
Copy link
Contributor

Sorry everyone; I've been sick lately and out of work. Healthy and back now.

Reusing the code between c/image/filters and c/common/libimage/filters operations along with some other syntax as mentioned by @mtrmac for each different podman X command is proving difficult, and as I was warned when I accepted this, "has dragons". I have a stopgap of just adding the negate logic to podman container list to match what c/image/filters provides, but it's not a merging of the two. I don't know if we want to accept this or work on the larger project of setting common syntax between the various filter mechanisms. Nonetheless I think it will be okay for just merging behavior now and working on a more robust method later if we all agree.

I'll try to push it tomorrow or Tuesday for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

4 participants