Merge pull request #26235 from mheon/fix_26101

Allow not specifying type with --mount flag
This commit is contained in:
openshift-merge-bot[bot]
2025-05-30 20:50:20 +00:00
committed by GitHub
4 changed files with 16 additions and 11 deletions

View File

@ -13,7 +13,7 @@ Options common to all mount types:
- *src*, *source*: mount source spec for **bind**, **glob**, and **volume**.
Mandatory for **artifact**, **bind**, **glob**, **image** and **volume**.
- *dst*, *destination*, *target*: mount destination spec.
- *dst*, *dest*, *destination*, *target*: mount destination spec.
When source globs are specified without the destination directory,
the files and directories are mounted with their complete path

View File

@ -446,7 +446,7 @@ func parseMountOptions(mountType string, args []string) (*universalMount, error)
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
}
mnt.subPath = value
case "target", "dst", "destination":
case "target", "dst", "dest", "destination":
if mnt.mount.Destination != "" {
return nil, fmt.Errorf("cannot pass %q option more than once: %w", name, errOptionArg)
}
@ -617,7 +617,7 @@ func getDevptsMount(args []string) (spec.Mount, error) {
switch name {
case "uid", "gid", "mode", "ptmxmode", "newinstance", "max":
newMount.Options = append(newMount.Options, arg)
case "target", "dst", "destination":
case "target", "dst", "dest", "destination":
if !hasValue {
return newMount, fmt.Errorf("%v: %w", name, errOptionArg)
}
@ -674,7 +674,7 @@ func getImageVolume(args []string) (*specgen.ImageVolume, error) {
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
}
newVolume.Source = value
case "target", "dst", "destination":
case "target", "dst", "dest", "destination":
if !hasValue {
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
}
@ -728,7 +728,7 @@ func getArtifactVolume(args []string) (*specgen.ArtifactVolume, error) {
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
}
newVolume.Source = value
case "target", "dst", "destination":
case "target", "dst", "dest", "destination":
if !hasValue {
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
}

View File

@ -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
}

View File

@ -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"))
})
})