Repository navigation
Modify docker volume inspect to return existed volumes and the names of the unexsited volumes - #17788
Conversation
|
hm I'm not sure; why would we output an error, and still continue? how does, e.g |
|
@thaJeztah ,docker inspect return errors and the names of the unexisted containers or images and continue to return the existed containers or images,like below root@324fca3aedab:/go/src/github.com/docker/docker# docker ps root@324fca3aedab:/go/src/github.com/docker/docker# docker inspect hao1 hao It return errors and the name of the unexisted container "Error: No such image or container: hao1",then continue to return the existed container.So I think docker volume inspect should also be like this |
|
|
|
it makes me sad that we're not using the response status code to check if the volume exists or not, but this is not the only place where we have this hack 😭 So, it LGTM, I guess. |
|
Why aren't we? This should be giving a proper 404 |
|
@cpuguy83 Is it? Then PR should be changed to check status instead of |
|
@haoshuwei Would you mind to try status instead of strings comparison? |
|
@LK4D4 @cpuguy83 @calavera @vdemeester @thaJeztah it is not only the "docker volume inspect " use strings comparison to check if volumes are existed or not,but also others like "docker network inspect“ and "docker inspect".So should i try to modify all of them to check status on the client? |
|
@haoshuwei let's focus on this one first. You don't need to modify anything in the api, just check if It would also be great if you could add a test case. |
|
The one thing we don't an API test for for volumes :( |
|
Yep, it is a 404. |
|
I have modified the client to check statuscode to see if volumes are existed. |
I'm okay with having the same behavior than the other commands, although I don't like it very much. Just a minor comment about the message, but otherwise LGTM |
There was a problem hiding this comment.
can we use the previous message, it's more self explanatory than this 404: volume not found: %s\n.
|
Modified to use message "Error: No such volume: %s\n". |
|
@haoshuwei it's better to have independent PRs for each change. It looks like the code is not properly formatted: Can you also add a test in the integration-cli suite, otherwise, we cannot guarantee that this behavior works. You can copy part of the code in this test: |
|
Sorry,i forget to check code style. Have go-fmt the file and submmit a test in the integration-cli suite |
There was a problem hiding this comment.
Also, minor style nit:
if err != nil {
if resp.statusCode != http.StatusNotFound {
return err
}
status = 1
fmt.Fprintf(cli.err, "Error: No such volume: %s\n", name)
continue
}Signed-off-by: Shuwei Hao <[email protected]>
|
Recommit the code following cpuguy83's comments |
|
LGTM |
|
em, is this patch ok to be merged? |
|
LGTM 🐰 |
|
Let's merge! Thanks @haoshuwei!! |
Modify docker volume inspect to return existed volumes and the names of the unexsited volumes
|
Oh.. weirdly enough the CI might have been wrong because now any build is red because of this 😓 (see https://jenkins.dockerproject.org/job/Docker-PRs/20656/console). Fixing it in #18458 😅 |
|
Oh, that's weird, because Janky was green on this one? |
|
Oh that's because a related (but different set of code) change was merged after these tests were run that fixed how we handle missing volumes on the client. |
|
Hmm, this fails on Windows CI now 100% :( [Yes, there's a bug in Windows CI which causes a false positive if there's a test failure - have a script update to Jess out for that] |
|
Oh, @vdemeester - yes, #18458 😺 |
|
Thanks @cpuguy83, makes sense now! (And thanks for the fix @vdemeester) |
When I used the "docker volume inspect" command to get the info about volumes,I found that if I give an existed volume name and an unexisted volume name,it returns only error infos,like below:
root@324fca3aedab:/go/src/github.com/docker/docker# docker volume ls
DRIVER VOLUME NAME
local hao
local hao1
local hao3
root@324fca3aedab:/go/src/github.com/docker/docker# docker volume inspect hao
[
{
"Name": "hao",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/hao/_data"
}
]
root@324fca3aedab:/go/src/github.com/docker/docker# docker volume inspect hao hao2
Error response from daemon: no such volume
So I modify the command to return the existed volumes even when I give an unexisted volume name,like below:
root@3c7deed66fd2:/go/src/github.com/docker/docker# docker volume inspect hao1 hao4
Error:No such volume: hao4
[
{
"Name": "hao1",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/hao1/_data"
}
]
Signed-off-by: Shuwei Hao [email protected]