Skip to content

Commit 3b91669

Browse files
Merge pull request #26235 from mheon/fix_26101
Allow not specifying type with --mount flag
2 parents 2f91c5c + 3837339 commit 3b91669

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

docs/source/markdown/options/mount.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Options common to all mount types:
1313
- *src*, *source*: mount source spec for **bind**, **glob**, and **volume**.
1414
Mandatory for **artifact**, **bind**, **glob**, **image** and **volume**.
1515

16-
- *dst*, *destination*, *target*: mount destination spec.
16+
- *dst*, *dest*, *destination*, *target*: mount destination spec.
1717

1818
When source globs are specified without the destination directory,
1919
the files and directories are mounted with their complete path

pkg/specgenutil/volumes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func parseMountOptions(mountType string, args []string) (*universalMount, error)
446446
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
447447
}
448448
mnt.subPath = value
449-
case "target", "dst", "destination":
449+
case "target", "dst", "dest", "destination":
450450
if mnt.mount.Destination != "" {
451451
return nil, fmt.Errorf("cannot pass %q option more than once: %w", name, errOptionArg)
452452
}
@@ -617,7 +617,7 @@ func getDevptsMount(args []string) (spec.Mount, error) {
617617
switch name {
618618
case "uid", "gid", "mode", "ptmxmode", "newinstance", "max":
619619
newMount.Options = append(newMount.Options, arg)
620-
case "target", "dst", "destination":
620+
case "target", "dst", "dest", "destination":
621621
if !hasValue {
622622
return newMount, fmt.Errorf("%v: %w", name, errOptionArg)
623623
}
@@ -674,7 +674,7 @@ func getImageVolume(args []string) (*specgen.ImageVolume, error) {
674674
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
675675
}
676676
newVolume.Source = value
677-
case "target", "dst", "destination":
677+
case "target", "dst", "dest", "destination":
678678
if !hasValue {
679679
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
680680
}
@@ -728,7 +728,7 @@ func getArtifactVolume(args []string) (*specgen.ArtifactVolume, error) {
728728
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
729729
}
730730
newVolume.Source = value
731-
case "target", "dst", "destination":
731+
case "target", "dst", "dest", "destination":
732732
if !hasValue {
733733
return nil, fmt.Errorf("%v: %w", name, errOptionArg)
734734
}

pkg/specgenutilexternal/mount.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"strings"
77
)
88

9-
var (
10-
errInvalidSyntax = errors.New("incorrect mount format: should be --mount type=<bind|glob|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")
11-
)
12-
139
// FindMountType parses the input and extracts the type of the mount type and
1410
// the remaining non-type tokens.
1511
func FindMountType(input string) (mountType string, tokens []string, err error) {
@@ -22,7 +18,7 @@ func FindMountType(input string) (mountType string, tokens []string, err error)
2218
return "", nil, err
2319
}
2420
if len(records) != 1 {
25-
return "", nil, errInvalidSyntax
21+
return "", nil, errors.New("incorrect mount format: should be --mount type=<bind|glob|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")
2622
}
2723
for _, s := range records[0] {
2824
kv := strings.Split(s, "=")
@@ -34,7 +30,7 @@ func FindMountType(input string) (mountType string, tokens []string, err error)
3430
found = true
3531
}
3632
if !found {
37-
err = errInvalidSyntax
33+
mountType = "volume"
3834
}
3935
return
4036
}

test/e2e/run_volume_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,4 +1122,13 @@ RUN chmod 755 /test1 /test2 /test3`, ALPINE)
11221122
session.WaitWithDefaultTimeout()
11231123
Expect(session).Should(ExitCleanly())
11241124
})
1125+
1126+
It("--mount flag defaults to volume if no type given", func() {
1127+
volName := "testvol"
1128+
podmanTest.PodmanExitCleanly("volume", "create", volName)
1129+
1130+
podmanTest.PodmanExitCleanly("run", "--rm", "--mount", fmt.Sprintf("src=%s,dest=/mnt", volName), ALPINE, "touch", "/mnt/testfile")
1131+
outTest := podmanTest.PodmanExitCleanly("run", "--rm", "--mount", fmt.Sprintf("type=volume,src=%s,dest=/mnt", volName), ALPINE, "ls", "/mnt")
1132+
Expect(outTest.OutputToString()).To(ContainSubstring("testfile"))
1133+
})
11251134
})

0 commit comments

Comments
 (0)