mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #44360 from neersighted/backport_44224
[22.06 backport] Fix force-remove for cluster volumes
This commit is contained in:
commit
cbaf1808cb
2 changed files with 20 additions and 7 deletions
|
@ -162,12 +162,17 @@ func (v *volumeRouter) deleteVolumes(ctx context.Context, w http.ResponseWriter,
|
||||||
version := httputils.VersionFromContext(ctx)
|
version := httputils.VersionFromContext(ctx)
|
||||||
|
|
||||||
err := v.backend.Remove(ctx, vars["name"], opts.WithPurgeOnError(force))
|
err := v.backend.Remove(ctx, vars["name"], opts.WithPurgeOnError(force))
|
||||||
if err != nil {
|
// when a removal is forced, if the volume does not exist, no error will be
|
||||||
if errdefs.IsNotFound(err) && versions.GreaterThanOrEqualTo(version, clusterVolumesVersion) && v.cluster.IsManager() {
|
// returned. this means that to ensure forcing works on swarm volumes as
|
||||||
|
// well, we should always also force remove against the cluster.
|
||||||
|
if err != nil || force {
|
||||||
|
if versions.GreaterThanOrEqualTo(version, clusterVolumesVersion) && v.cluster.IsManager() {
|
||||||
|
if errdefs.IsNotFound(err) || force {
|
||||||
err := v.cluster.RemoveVolume(vars["name"], force)
|
err := v.cluster.RemoveVolume(vars["name"], force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -574,6 +574,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) {
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, len(b.volumes), 0)
|
assert.Equal(t, len(b.volumes), 0)
|
||||||
|
assert.Equal(t, len(c.volumes), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
type fakeVolumeBackend struct {
|
type fakeVolumeBackend struct {
|
||||||
|
@ -616,9 +617,16 @@ func (b *fakeVolumeBackend) Create(_ context.Context, name, driverName string, _
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *fakeVolumeBackend) Remove(_ context.Context, name string, _ ...opts.RemoveOption) error {
|
func (b *fakeVolumeBackend) Remove(_ context.Context, name string, o ...opts.RemoveOption) error {
|
||||||
|
removeOpts := &opts.RemoveConfig{}
|
||||||
|
for _, opt := range o {
|
||||||
|
opt(removeOpts)
|
||||||
|
}
|
||||||
|
|
||||||
if v, ok := b.volumes[name]; !ok {
|
if v, ok := b.volumes[name]; !ok {
|
||||||
|
if !removeOpts.PurgeOnError {
|
||||||
return errdefs.NotFound(fmt.Errorf("volume %s not found", name))
|
return errdefs.NotFound(fmt.Errorf("volume %s not found", name))
|
||||||
|
}
|
||||||
} else if v.Name == "inuse" {
|
} else if v.Name == "inuse" {
|
||||||
return errdefs.Conflict(fmt.Errorf("volume in use"))
|
return errdefs.Conflict(fmt.Errorf("volume in use"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue