mirror of https://github.com/containers/podman.git
Allow not specifying type with --mount flag
Docker does not require `--type` to be passed, defaulting to `type=volume` in cases where it's not passed. Do the same in our volume parsing, and add a test to verify this works as expected. Fixes #26101 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
parent
775a85004f
commit
3837339e0e
|
@ -6,10 +6,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidSyntax = errors.New("incorrect mount format: should be --mount type=<bind|glob|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")
|
||||
)
|
||||
|
||||
// FindMountType parses the input and extracts the type of the mount type and
|
||||
// the remaining non-type tokens.
|
||||
func FindMountType(input string) (mountType string, tokens []string, err error) {
|
||||
|
@ -22,7 +18,7 @@ func FindMountType(input string) (mountType string, tokens []string, err error)
|
|||
return "", nil, err
|
||||
}
|
||||
if len(records) != 1 {
|
||||
return "", nil, errInvalidSyntax
|
||||
return "", nil, errors.New("incorrect mount format: should be --mount type=<bind|glob|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")
|
||||
}
|
||||
for _, s := range records[0] {
|
||||
kv := strings.Split(s, "=")
|
||||
|
@ -34,7 +30,7 @@ func FindMountType(input string) (mountType string, tokens []string, err error)
|
|||
found = true
|
||||
}
|
||||
if !found {
|
||||
err = errInvalidSyntax
|
||||
mountType = "volume"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1122,4 +1122,13 @@ RUN chmod 755 /test1 /test2 /test3`, ALPINE)
|
|||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
})
|
||||
|
||||
It("--mount flag defaults to volume if no type given", func() {
|
||||
volName := "testvol"
|
||||
podmanTest.PodmanExitCleanly("volume", "create", volName)
|
||||
|
||||
podmanTest.PodmanExitCleanly("run", "--rm", "--mount", fmt.Sprintf("src=%s,dest=/mnt", volName), ALPINE, "touch", "/mnt/testfile")
|
||||
outTest := podmanTest.PodmanExitCleanly("run", "--rm", "--mount", fmt.Sprintf("type=volume,src=%s,dest=/mnt", volName), ALPINE, "ls", "/mnt")
|
||||
Expect(outTest.OutputToString()).To(ContainSubstring("testfile"))
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue