Skip to content

Commit

Permalink
Allow docker volume create API to pass without name
Browse files Browse the repository at this point in the history
The Docker API does not require Volume name to be specified when
creating a volume.

Fixes: #9803

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Apr 27, 2021
1 parent 3148e01 commit 825c84e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/api/handlers/compat/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ func CreateVolume(w http.ResponseWriter, r *http.Request) {
return
}

// See if the volume exists already
existingVolume, err := runtime.GetVolume(input.Name)
if err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
utils.InternalServerError(w, err)
return
var (
existingVolume *libpod.Volume
err error
)
if len(input.Name) != 0 {
// See if the volume exists already
existingVolume, err = runtime.GetVolume(input.Name)
if err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
utils.InternalServerError(w, err)
return
}
}

// if using the compat layer and the volume already exists, we
Expand Down
7 changes: 7 additions & 0 deletions test/apiv2/30-volumes.at
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ t POST libpod/volumes/create name=foo1 201 \
.CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
.Labels={} \
.Options={}
t POST volumes/create 201 \
.Name~[0-9a-f]\\{64\\}
.Driver=local \
.Mountpoint=$volumepath/~[0-9a-f]\\{64\\}/_data \
.CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
.Labels={} \
.Options={}
t POST libpod/volumes/create 201
t POST libpod/volumes/create \
Name=foo2 \
Expand Down

0 comments on commit 825c84e

Please sign in to comment.