moby/daemon/cluster
Sebastiaan van Stijn 6c65a9a07f
volumes: fix error-handling when removing volumes with swarm enabled
Commit 3246db3755 added handling for removing
cluster volumes, but in some conditions, this resulted in errors not being
returned if the volume was in use;

    docker swarm init
    docker volume create foo
    docker create -v foo:/foo busybox top
    docker volume rm foo

This patch changes the logic for ignoring "local" volume errors if swarm
is enabled (and cluster volumes supported).

While working on this fix, I also discovered that Cluster.RemoveVolume()
did not handle the "force" option correctly; while swarm correctly handled
these, the cluster backend performs a lookup of the volume first (to obtain
its ID), which would fail if the volume didn't exist.

Before this patch:

    make TEST_FILTER=TestVolumesRemoveSwarmEnabled DOCKER_GRAPHDRIVER=vfs test-integration
    ...
    Running /go/src/github.com/docker/docker/integration/volume (arm64.integration.volume) flags=-test.v -test.timeout=10m  -test.run TestVolumesRemoveSwarmEnabled
    ...
    === RUN   TestVolumesRemoveSwarmEnabled
    === PAUSE TestVolumesRemoveSwarmEnabled
    === CONT  TestVolumesRemoveSwarmEnabled
    === RUN   TestVolumesRemoveSwarmEnabled/volume_in_use
        volume_test.go:122: assertion failed: error is nil, not errdefs.IsConflict
        volume_test.go:123: assertion failed: expected an error, got nil
    === RUN   TestVolumesRemoveSwarmEnabled/volume_not_in_use
    === RUN   TestVolumesRemoveSwarmEnabled/non-existing_volume
    === RUN   TestVolumesRemoveSwarmEnabled/non-existing_volume_force
        volume_test.go:143: assertion failed: error is not nil: Error response from daemon: volume no_such_volume not found
    --- FAIL: TestVolumesRemoveSwarmEnabled (1.57s)
        --- FAIL: TestVolumesRemoveSwarmEnabled/volume_in_use (0.00s)
        --- PASS: TestVolumesRemoveSwarmEnabled/volume_not_in_use (0.01s)
        --- PASS: TestVolumesRemoveSwarmEnabled/non-existing_volume (0.00s)
        --- FAIL: TestVolumesRemoveSwarmEnabled/non-existing_volume_force (0.00s)
    FAIL

With this patch:

    make TEST_FILTER=TestVolumesRemoveSwarmEnabled DOCKER_GRAPHDRIVER=vfs test-integration
    ...
    Running /go/src/github.com/docker/docker/integration/volume (arm64.integration.volume) flags=-test.v -test.timeout=10m  -test.run TestVolumesRemoveSwarmEnabled
    ...
    make TEST_FILTER=TestVolumesRemoveSwarmEnabled DOCKER_GRAPHDRIVER=vfs test-integration
    ...
    Running /go/src/github.com/docker/docker/integration/volume (arm64.integration.volume) flags=-test.v -test.timeout=10m  -test.run TestVolumesRemoveSwarmEnabled
    ...
    === RUN   TestVolumesRemoveSwarmEnabled
    === PAUSE TestVolumesRemoveSwarmEnabled
    === CONT  TestVolumesRemoveSwarmEnabled
    === RUN   TestVolumesRemoveSwarmEnabled/volume_in_use
    === RUN   TestVolumesRemoveSwarmEnabled/volume_not_in_use
    === RUN   TestVolumesRemoveSwarmEnabled/non-existing_volume
    === RUN   TestVolumesRemoveSwarmEnabled/non-existing_volume_force
    --- PASS: TestVolumesRemoveSwarmEnabled (1.53s)
        --- PASS: TestVolumesRemoveSwarmEnabled/volume_in_use (0.00s)
        --- PASS: TestVolumesRemoveSwarmEnabled/volume_not_in_use (0.01s)
        --- PASS: TestVolumesRemoveSwarmEnabled/non-existing_volume (0.00s)
        --- PASS: TestVolumesRemoveSwarmEnabled/non-existing_volume_force (0.00s)
    PASS

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 058a31e479)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-14 11:38:04 +01:00
..
controllers/plugin migrate pkg/pubsub to github.com/moby/pubsub 2022-09-30 22:32:43 +02:00
convert daemon/cluster: fix empty-lines (revive) 2022-09-30 23:59:30 +02:00
executor daemon/cluster: fix empty-lines (revive) 2022-09-30 23:59:30 +02:00
provider Add canonical import comment 2018-02-05 16:51:57 -05:00
cluster.go opts: ParseTCPAddr(): extract parsing logic, consistent errors 2022-05-01 19:53:40 +02:00
configs.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
errors.go Add canonical import comment 2018-02-05 16:51:57 -05:00
filters.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
filters_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
helpers.go Add Swarm cluster volume supports 2022-05-13 00:55:44 +02:00
listen_addr.go gofmt GoDoc comments with go1.19 2022-07-13 22:42:29 +02:00
listen_addr_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
listen_addr_others.go Update to Go 1.17.0, and gofmt with Go 1.17 2021-08-24 23:33:27 +02:00
networks.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
noderunner.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
nodes.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
secrets.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
services.go daemon/cluster: fix empty-lines (revive) 2022-09-30 23:59:30 +02:00
swarm.go opts: ParseTCPAddr(): extract parsing logic, consistent errors 2022-05-01 19:53:40 +02:00
tasks.go Bump swarmkit to v2 2022-04-21 17:33:07 -04:00
utils.go refactor: move from io/ioutil to io and os package 2021-08-27 14:56:57 +08:00
volumes.go volumes: fix error-handling when removing volumes with swarm enabled 2023-03-14 11:38:04 +01:00