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

fix for compatibility volume creation #7804

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/api/handlers/compat/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ 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
}

// if using the compat layer and the volume already exists, we
// must return a 201 with the same information as create
if existingVolume != nil && !utils.IsLibpodRequest(r) {
response := docker_api_types.Volume{
CreatedAt: existingVolume.CreatedTime().Format(time.RFC3339),
Driver: existingVolume.Driver(),
Labels: existingVolume.Labels(),
Mountpoint: existingVolume.MountPoint(),
Name: existingVolume.Name(),
Options: existingVolume.Options(),
Scope: existingVolume.Scope(),
}
utils.WriteResponse(w, http.StatusCreated, response)
return
}

if len(input.Name) > 0 {
volumeOptions = append(volumeOptions, libpod.WithVolumeName(input.Name))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/server/register_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func (s *APIServer) registerVolumeHandlers(r *mux.Router) error {
// parameters:
// - in: body
// name: create
// description: attributes for creating a container
// description: |
// attributes for creating a container.
// Note: If a volume by the same name exists, a 201 response with that volume's information will be generated.
// schema:
// $ref: "#/definitions/DockerVolumeCreate"
// produces:
Expand Down