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
volume create error on conflict option #16009
Conversation
Can you add a test case for this change just to make sure the command errors out correctly? Btw the linked issue seems to have a broader scope in making sure conflicting options errors out, does that only apply to driver names? |
c564cd9
to
1e9a6a2
Compare
added test. :) |
@@ -18,6 +18,18 @@ func (s *DockerSuite) TestVolumeCliCreate(c *check.C) { | |||
c.Assert(name, check.Equals, "test") | |||
} | |||
|
|||
func (s *DockerSuite) TestVolumeCliCreateOptionConflict(c *check.C) { | |||
dockerCmd(c, "volume", "create") |
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.
is this really needed?
just two small comments, ping @cpuguy83 @thaJeztah |
1e9a6a2
to
1a1dfbe
Compare
@@ -136,6 +136,9 @@ func (s *volumeStore) Create(name, driverName string, opts map[string]string) (v | |||
if vc, exists := s.vols[name]; exists { | |||
v := vc.Volume | |||
s.mu.Unlock() | |||
if driverName != v.DriverName() { |
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 should go in daemon.VolumeCreate (in daemon/create.go) instead of here.
In cases where you have docker run -v some_name:/foo --volume-driver other_driver
and some_name
is an existing volume but on a different driver, this should work.
At this moment, yes, only the driver: Docker doesn't keep track of other options (e.g. driver-options used to create the volume), so it's not possible to check if a user is trying to create a volume with the same name, but different options. |
@thaJeztah gotcha thanks |
1a1dfbe
to
825ecb8
Compare
change to daemon/create.go :) @cpuguy83 |
@@ -139,6 +139,15 @@ func (daemon *Daemon) VolumeCreate(name, driverName string, opts map[string]stri | |||
name = stringid.GenerateNonCryptoID() | |||
} | |||
|
|||
daemon.volumes.mu.Lock() |
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.
Sorry, this is not quite correct.
We can remove all this low-level check here and just check if the volume returned by daemon.volumes.Create
has the same driver as driverName
.
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.
@cpuguy83 I guess the problem with that is that you'd still end up creating the volume, and we want to avoid it.
I agree though that this might not be the right place to put this code. What do you think about adding this inside volume.Create
and returning an "already created" error?
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.
Well we do want it to be created if it doesn't exist, which would be the only case it would actually be created.
The thing with having it return an error when it already exists is it would break named volumes on run.
8af1a3e
to
02adcb1
Compare
I misunderstood your meaning. Updated! @cpuguy83 |
@@ -144,5 +144,9 @@ func (daemon *Daemon) VolumeCreate(name, driverName string, opts map[string]stri | |||
if err != nil { | |||
return nil, err | |||
} | |||
|
|||
if driverName != "" && v.DriverName() != driverName { |
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.
is the emtpy string check needed 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.
@runcom , yes , because if user don' t give a driver name when create a volume the driverName will be "" and the volume will be given a default driver name "local", no matter the volume is exist or not, it' s not a conflict case
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 gotcha!
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, definitely needed but we need to get the default volume driver if it is ""
instead of ignoring.
2dcdfdd
to
48583ee
Compare
have updated! @cpuguy83 |
Change LGTM, but it needs be be squashed into a single commit. |
15efff4
to
cb3ea7c
Compare
Forgot to squash , updated! |
Cool, LGTM, moving to docs review. |
@azurezk Actually if you can update the commit message to just a single message and a single sign-off that would be amazing. Thanks! |
7c16419
to
1f46bdc
Compare
@calavera have updated |
1f46bdc
to
db73f95
Compare
func (s *DockerSuite) TestVolumeCliCreateOptionConflict(c *check.C) { | ||
dockerCmd(c, "volume", "create", "--name=test") | ||
_, _, err := dockerCmdWithError("volume", "create", "--name", "test", "--driver", "nosuchdriver") | ||
c.Assert(err, check.NotNil, check.Commentf("volume create excepted to be failed on creating an existed volume with a different driver 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.
can we test that the error we get is the right error we expect? I'm not completely sure this command fails where we expect it to fail.
bd49a4a
to
1c26244
Compare
needs rebase |
1c26244
to
62762a0
Compare
rebased |
ping @cpuguy83 |
Moving to docs review, thanks! |
@@ -29,6 +29,8 @@ The mount is created inside the container's `/src` directory. Docker does not su | |||
|
|||
Multiple containers can use the same volume in the same time period. This is useful if two containers need access to shared data. For example, if one container writes and the other reads the data. | |||
|
|||
You cannot create a volume if there is a volume already registered with the same name in other driver. Docker returns the existent volume ID if the volume name conflicts and you don't specify the driver. |
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.
Slightly confused by the description here; if I understand correctly, the new behavior is;
- if I try to create a volume with the same name but a different driver, I receive an error
- if I try to create a volume with the same name, but don't specify a driver, it is assumed I want to re-use the existing volume, so I don't get an error
Correct?
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.
correct!
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.
Thanks! I'll see if I can come with a better description, unless @moxiegirl beats me to it :-)
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.
@azurezk Thank you for the contribution. Couple of changes to text and error message.
---> https://gist.github.com/moxiegirl/77c1f117d3080d1c95c6
Volume names must be unique among drivers. This means you cannot use the same volume name with two different drivers. If you attempt this docker
returns an error:
A volume named %s already exists with the %s driver. Choose a different volume name.
If you specify a volume name already in use on the current driver, Docker assumes you want to re-use the existing volume and does not return an error.
Signed-off-by: Kun Zhang <zkazure@gmail.com>
62762a0
to
0ff3123
Compare
updated @moxiegirl |
LGTM, thanks @azurezk ! |
Ping @moxiegirl: all good? ;-) |
LGTM @icecrime I'll let you coders merge the GO |
volume create error on conflict option
Volume names must be unique among drivers. This means you cannot use the same volume name with two different drivers. If you attempt this `docker` returns an error: | ||
|
||
``` | ||
A volume named %s already exists with the %s driver. Choose a different volume 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.
Oops, %s
is not what we want 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.
Oh, I open #17515 to fix it
fixes #15998
Signed-off-by: Kun Zhang zkazure@gmail.com