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

Add negation to filters #971

Merged
merged 1 commit into from Mar 23, 2022

Conversation

rvandernoort
Copy link
Contributor

This PR closes this issue, which adds a negation option to all filters for the podman images --filter command. I tested this locally by building an image with a label of version:0.1 and running bin/podman images --filter 'label=version=0.1' gives me only this image listed and running bin/podman images --filter 'label!=version=0.1' gives me all other images listed. I also tested the other filter options, and they all have the same effect!

Signed-off-by: rvandernoort s.r.vandernoort@student.tudelft.nl

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you add a couple of tests to libimage/filters_test.go to make sure it's working as expected and that we won't regress in the future?

@rvandernoort
Copy link
Contributor Author

rvandernoort commented Mar 21, 2022

Yeah of course, but I was thinking about it, is there any image that has like a testable label I could use for it? Because as an example, build-testimage only has these two labels, which are not really great for it.

LABEL created_by=$create_script
LABEL created_at=$create_time_z

libimage/filters.go Outdated Show resolved Hide resolved
libimage/filters.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Mar 21, 2022

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 21, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan, rvandernoort

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhatdan
Copy link
Member

rhatdan commented Mar 22, 2022

LGTM

@rhatdan
Copy link
Member

rhatdan commented Mar 22, 2022

@vrothberg @giuseppe PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM but we need tests.

@rvandernoort
Copy link
Contributor Author

@vrothberg I created a test for it now locally, but as I stated I need a testimage with a label, which I couldn't find. I created a simple Dockerfile for it now, can I upload this or something similar somewhere in the lipbod registry on quay to retrieve it in the test?

FROM alpine:latest

LABEL test=1

RUN apk update && \
    apk add git

ENTRYPOINT ["git"]
CMD ["--help"]

@vrothberg
Copy link
Member

@rvandernoort, there are other filters that we can (and should) use for testing.

For testing the label filter, you could use the following one:

~ $ skopeo inspect docker://quay.io/libpod/alpine_labels
{
    "Name": "quay.io/libpod/alpine_labels",
    "Digest": "sha256:30358dabe30a2e61968ad5b1deb1b8a988affb9db6e0c0efd6bad214d6c33284",
    "RepoTags": [
        "master",
        "latest"
    ],
    "Created": "2022-02-14T19:00:12.512223338Z",
    "DockerVersion": "20.10.6",
    "Labels": {
        "PODMAN": "/usr/bin/podman run -it --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE echo podman",
        "install": "docker run -it --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE echo install",
        "options": "/usr/bin/podman run -it --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE echo $OPT1 ",
        "run": "docker run -it --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE echo RUN",
        "uninstall": "/usr/bin/docker run -it --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE echo uninstall",
        "useradds": "/usr/bin/docker run -it IMAGE echo"
    },
    "Architecture": "amd64",
    "Os": "linux",
    "Layers": [
        "sha256:59bf1c3509f33515622619af21ed55bbe26d24913cedbca106468a5fb37a50c3"
    ],
    "Env": [
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ]
}

@rvandernoort
Copy link
Contributor Author

rvandernoort commented Mar 22, 2022

Yes perfect thank you! I've pushed the first test with the label filter, I'll make the remainder of the tests for the different filters soon.

@rvandernoort
Copy link
Contributor Author

Alright so I updated the test suite to cover more labels with and without negation. I did get stuck with running a container inside the unit tests here for the specific images in order to test the containers, dangling, intermediate, and readonly filter, any suggestions on how I should do this, because I could not find any example in the tests so far.

libimage/filters_test.go Outdated Show resolved Hide resolved
@vrothberg
Copy link
Member

Thanks a lot, @rvandernoort! Just one minor nit and then we can merge.

Signed-off-by: rvandernoort <s.r.vandernoort@student.tudelft.nl>
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold
Thank you!

@vrothberg
Copy link
Member

/hold cancel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to filter images without specific labels
4 participants