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

volume create error on conflict option #16009

Merged
merged 1 commit into from Oct 12, 2015

Conversation

azurezk
Copy link
Contributor

@azurezk azurezk commented Sep 2, 2015

fixes #15998
Signed-off-by: Kun Zhang zkazure@gmail.com

@runcom
Copy link
Member

runcom commented Sep 2, 2015

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?

@azurezk azurezk force-pushed the vol-create-conflict-option branch 2 times, most recently from c564cd9 to 1e9a6a2 Compare September 2, 2015 08:05
@azurezk
Copy link
Contributor Author

azurezk commented Sep 2, 2015

added test. :)
I m not sure about other conflict cases. @runcom @thaJeztah @cpuguy83

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

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

is this really needed?

@runcom
Copy link
Member

runcom commented Sep 2, 2015

just two small comments, ping @cpuguy83 @thaJeztah

@@ -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() {
Copy link
Member

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.

@thaJeztah
Copy link
Member

Btw the linked issue seems to have a broader scope in making sure conflicting options errors out, does that only apply to driver names?

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.

@runcom
Copy link
Member

runcom commented Sep 2, 2015

@thaJeztah gotcha thanks

@azurezk
Copy link
Contributor Author

azurezk commented Sep 6, 2015

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()
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Member

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.

@azurezk azurezk force-pushed the vol-create-conflict-option branch 2 times, most recently from 8af1a3e to 02adcb1 Compare September 8, 2015 06:59
@azurezk
Copy link
Contributor Author

azurezk commented Sep 8, 2015

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 {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

oh gotcha!

Copy link
Member

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.

@azurezk azurezk force-pushed the vol-create-conflict-option branch 2 times, most recently from 2dcdfdd to 48583ee Compare September 9, 2015 03:21
@azurezk
Copy link
Contributor Author

azurezk commented Sep 9, 2015

have updated! @cpuguy83

@calavera
Copy link
Contributor

calavera commented Sep 9, 2015

Change LGTM, but it needs be be squashed into a single commit.

@azurezk
Copy link
Contributor Author

azurezk commented Sep 10, 2015

Forgot to squash , updated!

@cpuguy83
Copy link
Member

Cool, LGTM, moving to docs review.

@cpuguy83
Copy link
Member

@azurezk Actually if you can update the commit message to just a single message and a single sign-off that would be amazing. Thanks!

@azurezk
Copy link
Contributor Author

azurezk commented Sep 25, 2015

@calavera have updated

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"))
Copy link
Contributor

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.

@azurezk azurezk force-pushed the vol-create-conflict-option branch 2 times, most recently from bd49a4a to 1c26244 Compare September 28, 2015 14:45
@jessfraz
Copy link
Contributor

jessfraz commented Oct 2, 2015

needs rebase

@azurezk
Copy link
Contributor Author

azurezk commented Oct 5, 2015

rebased

@jessfraz
Copy link
Contributor

jessfraz commented Oct 8, 2015

ping @cpuguy83

@icecrime
Copy link
Contributor

Moving to docs review, thanks!

@icecrime icecrime added this to the 1.9.0 milestone Oct 10, 2015
@@ -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.
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct!

Copy link
Member

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 :-)

Copy link
Contributor

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>
@azurezk
Copy link
Contributor Author

azurezk commented Oct 12, 2015

updated @moxiegirl

@icecrime icecrime self-assigned this Oct 12, 2015
@thaJeztah
Copy link
Member

LGTM, thanks @azurezk !

@icecrime
Copy link
Contributor

Ping @moxiegirl: all good? ;-)

@moxiegirl
Copy link
Contributor

LGTM @icecrime I'll let you coders merge the GO

jessfraz pushed a commit that referenced this pull request Oct 12, 2015
volume create error on conflict option
@jessfraz jessfraz merged commit df79536 into moby:master Oct 12, 2015
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.
Copy link
Member

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 :)

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker "volume create" doesn't error on conflicting options
9 participants