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

Fixes Incorrect documentation docker volume create - Issue #47606 #47798

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions volume/drivers/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func (a *volumeDriverAdapter) Name() string {
}

func (a *volumeDriverAdapter) Create(name string, opts map[string]string) (volume.Volume, error) {
v, err := a.proxy.Get(name)
if err == nil && v.DriverName() != a.Name() {
return nil, errors.New("A volume named " + name + " already exists with the " + v.DriverName() + " driver. Choose a different volume name.")
}

Comment on lines +27 to +31
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is already handled; looking at

// checkConflict checks the local cache for name collisions with the passed in name,
// for existing volumes with the same name but in a different driver.
// This is used by `Create` as a best effort to prevent name collisions for volumes.
// If a matching volume is found that is not a conflict that is returned so the caller
// does not need to perform an additional lookup.
// When no matching volume is found, both returns will be nil
//
// Note: This does not probe all the drivers for name collisions because v1 plugins
// are very slow, particularly if the plugin is down, and cause other issues,
// particularly around locking the store.
// TODO(cpuguy83): With v2 plugins this shouldn't be a problem. Could also potentially
// use a connect timeout for this kind of check to ensure we aren't blocking for a
// long time.
func (s *VolumeStore) checkConflict(ctx context.Context, name, driverName string) (volume.Volume, error) {

And, more specifically, these lines

if exists {
if conflict {
return nil, errors.Wrapf(errNameConflict, "driver '%s' already has volume '%s'", vDriverName, name)
}
return v, nil
}

if err := a.proxy.Create(name, opts); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions volume/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (s *VolumesService) Create(ctx context.Context, name, driverName string, op
name = stringid.GenerateRandomID()
options = append(options, opts.WithCreateLabel(AnonymousLabel, ""))
}

v, err := s.vs.Create(ctx, name, driverName, options...)
if err != nil {
return nil, err
Expand Down