Add --force in docker volume rm to fix out-of-band volume driver deletion
This fix tries to address the issue in raised #23367 where an out-of-band volume driver deletion leaves some data in docker. This prevent the reuse of deleted volume names (by out-of-band volume driver like flocker). This fix adds a `--force` field in `docker volume rm` to forcefully purge the data of the volume that has already been deleted. Related documentations have been updated. This fix is tested manually with flocker, as is specified in #23367. An integration test has also been added for the scenario described. This fix fixes #23367. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Upstream-commit: 6c5c34d50d377d1c5318a255240fb2dc9c23cf92 Component: engine
This commit is contained in:
@ -374,3 +374,38 @@ func (s *DockerSuite) TestVolumeCliLsFilterLabels(c *check.C) {
|
||||
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCliRmForceUsage(c *check.C) {
|
||||
out, _ := dockerCmd(c, "volume", "create")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
dockerCmd(c, "volume", "rm", "-f", id)
|
||||
dockerCmd(c, "volume", "rm", "--force", "nonexist")
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCliRmForce(c *check.C) {
|
||||
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
||||
|
||||
name := "test"
|
||||
out, _ := dockerCmd(c, "volume", "create", "--name", name)
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(id, checker.Equals, name)
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "inspect", "--format", "{{.Mountpoint}}", name)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
// Mountpoint is in the form of "/var/lib/docker/volumes/.../_data", removing `/_data`
|
||||
path := strings.TrimSuffix(strings.TrimSpace(out), "/_data")
|
||||
out, _, err := runCommandWithOutput(exec.Command("rm", "-rf", path))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
dockerCmd(c, "volume", "rm", "-f", "test")
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(out, checker.Not(checker.Contains), name)
|
||||
dockerCmd(c, "volume", "create", "--name", "test")
|
||||
out, _ = dockerCmd(c, "volume", "ls")
|
||||
c.Assert(out, checker.Contains, name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user