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

fix: event --filter volume=vol-name should compare the event name with volume name #18619

Merged

Conversation

vyasgun
Copy link
Member

@vyasgun vyasgun commented May 18, 2023

Fixes: #18618

Does this PR introduce a user-facing change?

Yes

None

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

Not sure but shouldn't it handle additional case for Name, instead of replacing ID with Name

diff --git a/libpod/events/filters.go b/libpod/events/filters.go
index 9057c9b79..5ed09b461 100644
--- a/libpod/events/filters.go
+++ b/libpod/events/filters.go
@@ -52,6 +52,9 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
                       if e.Type != Volume {
                               return false
                       }
+                       if e.Name == filterValue {
+                               return true
+                       }
                       return strings.HasPrefix(e.ID, filterValue)
               }, nil
       case "TYPE":

Again I have not tried above patch, just a hunch.

@edsantiago
Copy link
Member

I'm not sure what's the best way to fix this, and I'm really uncomfortable with the Prefix thing... but I'm uncomfortablest with NO-TESTS. Here's a test, suitable for 090-events.bats. It passes with your PR, fails on main.

@test "events - volume events" {
    local vname=v$(random_string 10)
    run_podman volume create $vname
    run_podman volume rm $vname

    run_podman events --since=1m --stream=false --filter volume=$vname
    notrunc_results="$output"
    assert "${lines[0]}" =~ ".* volume create $vname"
    assert "${lines[1]}" =~ ".* volume remove $vname"

    # Prefix test
    run_podman events --since=1m --stream=false --filter volume=${vname:0:5}
    assert "$output" = "$notrunc_results"
}

@vyasgun
Copy link
Member Author

vyasgun commented May 18, 2023

@flouthoc The ID is not being set in the code for volume events so it is always blank. In the pod and image cases also, the name is being used for comparison before ID.

@vyasgun
Copy link
Member Author

vyasgun commented May 18, 2023

@edsantiago @flouthoc The prefix check is being used in all other cases but with IDs. I don't see an ID field in the Volume type so I added it for the Name field but it sounds better to change it to a == check instead.

Thanks for the feedback, I'll add some tests.

@flouthoc
Copy link
Collaborator

flouthoc commented May 18, 2023

@vyasgun

If two volumes are created with name

* volume1: hello
* volume2: helloworld

Wouldn't filter --filter=hello will filter event both for volume hello and helloworld ?

My idea with the patch suggested here #18619 (review) was if user specifies a Name it should always do explicit match and if ID is selected then maybe fallback to prefix match. Since docs says either ID or Name https://docs.podman.io/en/latest/markdown/podman-events.1.html

But again I have not played with filter and the part of code being discussed here enough so I could be missing bits.

@flouthoc
Copy link
Collaborator

flouthoc commented May 18, 2023

Ignore my previous comment it seems libpod.Volumes don't have an ID, they only have Name so maybe

diff --git a/libpod/events/filters.go b/libpod/events/filters.go
index 9057c9b79..4a836d817 100644
--- a/libpod/events/filters.go
+++ b/libpod/events/filters.go
@@ -52,7 +52,10 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
                        if e.Type != Volume {
                                return false
                        }
-                       return strings.HasPrefix(e.ID, filterValue)
+                       if e.Name == filterValue {
+                               return true
+                       }
+                       return false
                }, nil
        case "TYPE":
                return func(e *Event) bool {

@vyasgun
Copy link
Member Author

vyasgun commented May 18, 2023

@flouthoc I have changed it to == in my recent commit.

@flouthoc
Copy link
Collaborator

LGTM other than adding tests as suggested by @edsantiago

@vyasgun vyasgun force-pushed the pr/events-volume-name branch 2 times, most recently from e2ac946 to 7c486c5 Compare May 19, 2023 13:19
libpod/events/filters.go Show resolved Hide resolved
@@ -225,6 +225,17 @@ EOF
is "${lines[-1]}" "{\"ID\":\"$ctrID\",\"Image\":\"$IMAGE\",\"Name\":\".*\",\"Status\":\"remove\",\"Time\":\".*\",\"Type\":\"container\",\"Attributes\":{.*}}"
}

@test "events - volume events" {
local vname=v$(random_string 10)
run_podman volume create $vname
Copy link
Member

Choose a reason for hiding this comment

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

Let's also record the id here id=$(output) and filter it as well.

@vrothberg
Copy link
Member

@flouthoc The ID is not being set in the code for volume events so it is always blank. In the pod and image cases also, the name is being used for comparison before ID.

Ah, OK. It looks like name and ID are the same.

How does Docker behave when filtering for name or ID?

@vyasgun can you squash the two commits into one in the next push?

@vyasgun
Copy link
Member Author

vyasgun commented May 22, 2023

@vrothberg docker is doing a prefix match when filtering for "volume=volume-name".

$ docker events --filter volume=abc
2023-05-22T18:10:39.330449408+05:30 volume destroy abcd (driver=local)

In Podman, the ID is not being set for volume events since the volume object does not have an ID. Should it be set to the volume name? Or is it better to leave it blank?

@vrothberg
Copy link
Member

In Podman, the ID is not being set for volume events since the volume object does not have an ID. Should it be set to the volume name? Or is it better to leave it blank?

We can leave it blank but we need to be compatible with Docker. So I think we need to keep the prefix check but compare with .Name isntead of .ID.

@vyasgun vyasgun force-pushed the pr/events-volume-name branch from 7c486c5 to a5902ba Compare May 22, 2023 13:39
@vyasgun vyasgun force-pushed the pr/events-volume-name branch from a5902ba to 5f29c7b Compare May 22, 2023 13:41
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, thanks!

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2023
@TomSweeneyRedHat
Copy link
Member

LGTM
I'll rerun the failing test, it looks like a flake

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

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 23, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 23, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vrothberg, vyasgun

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

@openshift-merge-robot openshift-merge-robot merged commit ca7d012 into containers:main May 23, 2023
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman events --filter doesn't work for "volume" as a key
6 participants