mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: remove version-gate for "--force" on "volume remove"
The `force` option on volume remove was added in [moby@6c5c34d] (docker 1.13.0-rc1, API v1.25), but did not gate the feature to API version, so effectively introduced it to all existing API versions. After this, [moby@e98e4a7] enabled experimental features by default, and added API version gates, but only did so on the client side, so the daemon / API server would continue to accept the `force` option on any API version. Let's remove this code, given that: - API v1.24 is the oldest API version we still handle, and only as fallback. - This code silently discards the user's option (no warning / error) - Every current version of the daemon handles the option, regardless of API version (only a 9+ year old daemon wouldn't handle it). [moby@6c5c34d]:6c5c34d50d[moby@e98e4a7]:e98e4a7111Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -3,8 +3,6 @@ package client
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/moby/moby/api/types/versions"
|
||||
)
|
||||
|
||||
// VolumeRemove removes a volume from the docker host.
|
||||
@@ -16,17 +14,7 @@ func (cli *Client) VolumeRemove(ctx context.Context, volumeID string, force bool
|
||||
|
||||
query := url.Values{}
|
||||
if force {
|
||||
// Make sure we negotiated (if the client is configured to do so),
|
||||
// as code below contains API-version specific handling of options.
|
||||
//
|
||||
// Normally, version-negotiation (if enabled) would not happen until
|
||||
// the API request is made.
|
||||
if err := cli.checkVersion(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if versions.GreaterThanOrEqualTo(cli.version, "1.25") {
|
||||
query.Set("force", "1")
|
||||
}
|
||||
query.Set("force", "1")
|
||||
}
|
||||
resp, err := cli.delete(ctx, "/volumes/"+volumeID, query, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
|
||||
@@ -3,6 +3,7 @@ package client
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -47,6 +48,10 @@ func TestVolumeRemove(t *testing.T) {
|
||||
if err := assertRequest(req, http.MethodDelete, expectedURL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v := req.URL.Query().Get("force"); v != "1" {
|
||||
return nil, fmt.Errorf("expected force=1, got %s", v)
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewReader([]byte("body"))),
|
||||
@@ -54,6 +59,6 @@ func TestVolumeRemove(t *testing.T) {
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = client.VolumeRemove(context.Background(), "volume_id", false)
|
||||
err = client.VolumeRemove(context.Background(), "volume_id", true)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
14
vendor/github.com/moby/moby/client/volume_remove.go
generated
vendored
14
vendor/github.com/moby/moby/client/volume_remove.go
generated
vendored
@@ -3,8 +3,6 @@ package client
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/moby/moby/api/types/versions"
|
||||
)
|
||||
|
||||
// VolumeRemove removes a volume from the docker host.
|
||||
@@ -16,17 +14,7 @@ func (cli *Client) VolumeRemove(ctx context.Context, volumeID string, force bool
|
||||
|
||||
query := url.Values{}
|
||||
if force {
|
||||
// Make sure we negotiated (if the client is configured to do so),
|
||||
// as code below contains API-version specific handling of options.
|
||||
//
|
||||
// Normally, version-negotiation (if enabled) would not happen until
|
||||
// the API request is made.
|
||||
if err := cli.checkVersion(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if versions.GreaterThanOrEqualTo(cli.version, "1.25") {
|
||||
query.Set("force", "1")
|
||||
}
|
||||
query.Set("force", "1")
|
||||
}
|
||||
resp, err := cli.delete(ctx, "/volumes/"+volumeID, query, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
|
||||
Reference in New Issue
Block a user