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

Use Regexp in volume ls --filter name #14597

Merged
merged 1 commit into from
Jun 28, 2022
Merged

Use Regexp in volume ls --filter name #14597

merged 1 commit into from
Jun 28, 2022

Conversation

boaz0
Copy link
Collaborator

@boaz0 boaz0 commented Jun 15, 2022

closes #14583

Does this PR introduce a user-facing change?

Added Regexp support to filtering volumes by name

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2022

This needs glob support not regex support. This also needs tests added.

You can use filepath.Match I believe.

@boaz0
Copy link
Collaborator Author

boaz0 commented Jun 15, 2022

@rhatdan
Oh, sorry. I will fix this and almost done with the testing.

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2022

Great thanks.

@Luap99
Copy link
Member

Luap99 commented Jun 15, 2022

The man page says regex and the other commands use regex so this is fine.

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2022

Docker supports GLOB and we were looking for compatibility. We could perhaps support both, but I believe GLOB is always much more easily understood by the average computer user the regex. And working with shell makes the most sense.

@Luap99
Copy link
Member

Luap99 commented Jun 15, 2022

I am pretty sure that docker uses regex not glob.

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2022

$ docker volume list --filter name=testvolume_*
DRIVER VOLUME NAME
local testvolume_1
local testvolume_2

A Regex would have only matched testvolume testvolume_ testvolume__ ...
IT should not match 1 and 2.

@Luap99
Copy link
Member

Luap99 commented Jun 15, 2022

No, your regex matches everything which contains testvolume_ or testvolume__. What you want is this regex: ^testvolume_*$.
Just try out testvolume_[12], it will work because it uses regex not glob

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2022

Ok as long as that test case works then I am fine with regex.

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2022

My understanding of * in regex matches this description from Wikipedia But I am missing something.

* | The asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches "ac", "abc", "abbc", "abbbc", and so on.

@edsantiago
Copy link
Member

@boaz0 please rebase on latest main (08f35da) to fix CI breakage

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.

@boaz0 Could you please squash the commit.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 16, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: boaz0, flouthoc

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-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2022
Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of nits. Nice work.

is "$output" "${prefix}_1_${suffix}.*${prefix}_2_${suffix}$" "--filter name=${prefix}* shows ${prefix}_1 and ${prefix}_2"

for i in 1 2; do
run_podman volume rm ${prefix}_${i}
Copy link
Member

Choose a reason for hiding this comment

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

This squicks me out. It works, but (apparently) only because podman does some internal disambiguation. I would like this either to be changed to rm ${prefix}_${i}_${suffix} or for you to add a comment such as

  # side effect: test podman volume disambiguation (unique prefix)

Copy link
Collaborator Author

@boaz0 boaz0 Jun 22, 2022

Choose a reason for hiding this comment

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

Woow! Good catch, I was too focus on playing with the containers names that I forgot to update this part as well! 😓
I will update this
+1 on explaining why it worked anyway.
Thanks.

run_podman volume ls --filter name=${prefix}_1.+ --format "{{.Name}}"
is "$output" "${prefix}_1_${suffix}" "--filter name=${prefix}_1.+ shows only one volume"

run_podman volume ls --filter name=${prefix}* --format "{{.Name}}"
Copy link
Member

Choose a reason for hiding this comment

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

Since you're adding regex, not glob, I would like to see this changed to name=${prefix}_1* with a comment loudly stating something like "yes, the '1' is intentional, blah blah this is regex". That will hammer the point to a casual reader who might be expecting globs.

@boaz0 boaz0 force-pushed the closes_14583 branch 2 times, most recently from be582bf to 5a66856 Compare June 22, 2022 10:11
@boaz0 boaz0 requested review from edsantiago and nalind June 22, 2022 10:11
@flouthoc
Copy link
Collaborator

Failing test was a flake restarted.


# The _1* is intentional as asterisk has different meaning in glob and regexp. Make sure this is regexp
run_podman volume ls --filter name=${prefix}_1* --format "{{.Name}}"
is "$output" "${prefix}_1_${suffix}" "--filter name=${prefix}_1* shows only one volume"
Copy link
Member

Choose a reason for hiding this comment

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

This is EXACTLY why I requested the change I requested: because regexps are counterintuitive to many people. _1* will (and should) match BOTH volumes, because 1* means "zero or more instances of the character 1`.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, which is why I like Globs.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have access to docker/moby any more, but maybe this is a good opportunity to triple-confirm that we are implementing this feature in a way that is compatible with them.

Copy link
Member

Choose a reason for hiding this comment

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

yes we are, docker uses regex and we also use regex for all other commands.
I have no idea where the glob idea comes from, anyway this is the filter line in moby: https://github.com/moby/moby/blob/c17a566b0dc5074de8ce25a88ba1d43e10667d19/api/types/filters/parse.go#L190

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, my bad. I accidentally copied the wrong line. I updated the expected results.

@edsantiago
Copy link
Member

/lgtm
/hold

@openshift-ci openshift-ci bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Jun 22, 2022
@edsantiago
Copy link
Member

LGTM and CI is green; but I'd like one more set of eyeballs simply because anything using regexps is fraught with peril.

if err != nil {
return false
}
return match
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be faster to use regex.Compile() to compile the expression into a new Regexp object outside of the new anonymous filter function. This would also give us the opportunity to flag any syntax errors while we're still in GenerateVolumeFilters().

The anonymous filter function that's created here would then call that Regexp object's MatchString() method instead of calling the regexp package's MatchString() function, which I expect has to compile the regex every time it's called.

It looks like libpod.Runtime.Volumes() will call each of these filter functions for every volume, and that's got to add up.

Copy link
Collaborator Author

@boaz0 boaz0 Jun 23, 2022

Choose a reason for hiding this comment

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

I thought about it, the problem I still need to pass the pattern which is available only inside the scope of GenerateVolumeFilters() - nameVal := val which means it will be Compiled everytime GenerateVolumeFilters() is called. Unless, I can "cache" this in a map.

Or maybe I am missing something. Lemme know. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

The anonymous function (I looked it up and it turns out I should have used the phrase "function literal") can access variables defined in GenerateVolumeFilters() so long as the function itself is within the scope where the variable exists, as described at https://go.dev/ref/spec#Function_literals.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh right! This will work because vfs holds anonymous functions. Yes, that'll work. Thanks for the suggestions.

is "$output" "${prefix}_1_${suffix}" "--filter name=${prefix}_1.+ shows only one volume"

# The _1* is intentional as asterisk has different meaning in glob and regexp. Make sure this is regexp
run_podman volume ls --filter name=${prefix}_1* --format "{{.Name}}"
Copy link
Member

Choose a reason for hiding this comment

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

Should the "name=" argument be quoted here?

Copy link
Collaborator Author

@boaz0 boaz0 Jun 23, 2022

Choose a reason for hiding this comment

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

I'm not sure... 🤷‍♂️

//cc @edsantiago what do you think?

Copy link
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

Two suggested changes that would let us call out invalid patterns instead of silently failing to match against them.

pkg/domain/filters/volumes.go Outdated Show resolved Hide resolved
pkg/domain/filters/volumes.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 27, 2022
@boaz0 boaz0 requested review from nalind, edsantiago and Luap99 June 27, 2022 18:30
@edsantiago
Copy link
Member

LGTM but there's a merge conflict; you need to rebase.

@rhatdan
Copy link
Member

rhatdan commented Jun 27, 2022

/lgtm
/hold

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 27, 2022
@edsantiago
Copy link
Member

eeeek, timeouts. Right after #14685. @mheon how certain are you that you found all the deadlocks?

@mheon
Copy link
Member

mheon commented Jun 27, 2022

Could be related, but it's a very different presentation than what we saw in that bug. Have we seen this anywhere else?

@edsantiago
Copy link
Member

This seems surprising, but I've double-checked a different way: cirrus-flake-grep "sending signal" finds no relevant hits.

@mheon
Copy link
Member

mheon commented Jun 27, 2022

I'm going to rerun and hope it goes away, but if we see this again I'll take a more detailed look.

@edsantiago
Copy link
Member

/hold cancel

It passed on rerun, but I'm betting this is going to come back.

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 28, 2022
@openshift-ci openshift-ci bot merged commit d095053 into main Jun 28, 2022
@edsantiago
Copy link
Member

P.S. thank you @boaz for your initiative and perseverance

@vrothberg vrothberg deleted the closes_14583 branch June 28, 2022 07:43
@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 Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman volume list, filtering by wildcard in name
7 participants