Skip to content

Commit

Permalink
Allow creating anonymous volumes with --mount
Browse files Browse the repository at this point in the history
This fixes containers#13756.

All the mechanics to create anonymous volumes is already present, but
there's still a validation preventing that path from being taken.  We
remove the validation, which allows the volume to be created
successfully.

Signed-off-by: Andrew Aylett <[email protected]>
  • Loading branch information
andrewaylett committed Apr 2, 2022
1 parent d4394ea commit bf4318e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/specgenutil/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func getDevptsMount(args []string) (spec.Mount, error) {
func getNamedVolume(args []string) (*specgen.NamedVolume, error) {
newVolume := new(specgen.NamedVolume)

var setSource, setDest, setRORW, setSuid, setDev, setExec, setOwnership bool
var setDest, setRORW, setSuid, setDev, setExec, setOwnership bool

for _, val := range args {
kv := strings.SplitN(val, "=", 2)
Expand Down Expand Up @@ -554,7 +554,6 @@ func getNamedVolume(args []string) (*specgen.NamedVolume, error) {
return nil, errors.Wrapf(optionArgError, kv[0])
}
newVolume.Name = kv[1]
setSource = true
case "target", "dst", "destination":
if len(kv) == 1 {
return nil, errors.Wrapf(optionArgError, kv[0])
Expand Down Expand Up @@ -585,9 +584,6 @@ func getNamedVolume(args []string) (*specgen.NamedVolume, error) {
}
}

if !setSource {
return nil, errors.Errorf("must set source volume")
}
if !setDest {
return nil, noDestError
}
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ VOLUME /test/`, ALPINE)
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).Should(Equal("888:888"))

// anonymous volume mount
vol = "type=volume," + "dst=" + dest
session = podmanTest.Podman([]string{"run", "--rm", "--user", "888:888", "--mount", vol, ALPINE, "stat", "-c", "%u:%g", dest})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).Should(Equal("888:888"))

// named volume mount
namedVolume := podmanTest.Podman([]string{"volume", "create", "foo"})
namedVolume.WaitWithDefaultTimeout()
Expand Down

0 comments on commit bf4318e

Please sign in to comment.