-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
This needs glob support not regex support. This also needs tests added. You can use filepath.Match I believe. |
@rhatdan |
Great thanks. |
The man page says regex and the other commands use regex so this is fine. |
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. |
I am pretty sure that docker uses regex not glob. |
$ docker volume list --filter name=testvolume_* A Regex would have only matched testvolume testvolume_ testvolume__ ... |
No, your regex matches everything which contains |
Ok as long as that test case works then I am fine with regex. |
My understanding of * in regex matches this description from Wikipedia But I am missing something.
|
There was a problem hiding this 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.
[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 |
There was a problem hiding this 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.
test/system/160-volumes.bats
Outdated
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} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
test/system/160-volumes.bats
Outdated
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}}" |
There was a problem hiding this comment.
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.
be582bf
to
5a66856
Compare
Failing test was a flake restarted. |
test/system/160-volumes.bats
Outdated
|
||
# 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" |
There was a problem hiding this comment.
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`.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
/lgtm |
LGTM and CI is green; but I'd like one more set of eyeballs simply because anything using regexps is fraught with peril. |
pkg/domain/filters/volumes.go
Outdated
if err != nil { | ||
return false | ||
} | ||
return match |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 Compile
d everytime GenerateVolumeFilters()
is called. Unless, I can "cache" this in a map.
Or maybe I am missing something. Lemme know. Thanks.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}}" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
Signed-off-by: Boaz Shuster <[email protected]>
LGTM but there's a merge conflict; you need to rebase. |
/lgtm |
Could be related, but it's a very different presentation than what we saw in that bug. Have we seen this anywhere else? |
This seems surprising, but I've double-checked a different way: |
I'm going to rerun and hope it goes away, but if we see this again I'll take a more detailed look. |
/hold cancel It passed on rerun, but I'm betting this is going to come back. |
P.S. thank you @boaz for your initiative and perseverance |
closes #14583
Does this PR introduce a user-facing change?