Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/mountutil/mountutil_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func parseVolumeOptionsWithMountInfo(vType, src, optsRaw, ociRuntime string, get
if err != nil {
return nil, nil, err
}
if err := ensureMountOptionalValue(mi, "shared:"); err != nil {
if err := ensureMountOptionalValue(mi, got, "shared:"); err != nil {
return nil, nil, err
}

Expand Down Expand Up @@ -276,7 +276,7 @@ func parseVolumeOptionsWithMountInfo(vType, src, optsRaw, ociRuntime string, get
if err != nil {
return nil, nil, err
}
if err := ensureMountOptionalValue(mi, "shared:", "master:"); err != nil {
if err := ensureMountOptionalValue(mi, got, "shared:", "master:"); err != nil {
return nil, nil, err
}

Expand Down Expand Up @@ -320,7 +320,7 @@ func parseVolumeOptionsWithMountInfo(vType, src, optsRaw, ociRuntime string, get
//
// For more details about "optional" field:
// - https://github.com/moby/sys/blob/mountinfo/v0.4.1/mountinfo/mountinfo.go#L52-L56
func ensureMountOptionalValue(mi mount.Info, vals ...string) error {
func ensureMountOptionalValue(mi mount.Info, propagation string, vals ...string) error {
var hasValue bool
for _, opt := range strings.Split(mi.Optional, " ") {
for _, mark := range vals {
Expand All @@ -330,7 +330,7 @@ func ensureMountOptionalValue(mi mount.Info, vals ...string) error {
}
}
if !hasValue {
return fmt.Errorf("mountpoint %q doesn't have optional field neither of %+v", mi.Mountpoint, vals)
return fmt.Errorf("mountpoint %q is not a shared or slave mount, so it cannot be bind-mounted with propagation %q; try running `mount --make-rshared %q` on the host", mi.Mountpoint, propagation, mi.Mountpoint)
}
return nil
}
Expand Down
30 changes: 18 additions & 12 deletions pkg/mountutil/mountutil_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestParseVolumeOptions(t *testing.T) {
wants []string
wantRootfsPropagation string
wantFail bool
wantErrContains string
}{
{
name: "unknown option is ignored (with warning)",
Expand Down Expand Up @@ -176,12 +177,13 @@ func TestParseVolumeOptions(t *testing.T) {
wants: []string{"ro", "rshared"},
},
{
name: "shared propagation is not allowed if the src is not shared",
vType: "bind",
src: "dummy",
optsRaw: "ro,shared",
srcOptional: nil,
wantFail: true,
name: "shared propagation is not allowed if the src is not shared",
vType: "bind",
src: "dummy",
optsRaw: "ro,shared",
srcOptional: nil,
wantFail: true,
wantErrContains: `mount --make-rshared "dummy"`,
},
{
name: "make bind slave",
Expand All @@ -203,12 +205,13 @@ func TestParseVolumeOptions(t *testing.T) {
wants: []string{"ro", "slave"},
},
{
name: "slave propagation is not allowed if the src is not slave",
vType: "bind",
src: "dummy",
optsRaw: "ro,slave",
srcOptional: nil,
wantFail: true,
name: "slave propagation is not allowed if the src is not slave",
vType: "bind",
src: "dummy",
optsRaw: "ro,slave",
srcOptional: nil,
wantFail: true,
wantErrContains: `mount --make-rshared "dummy"`,
},
}
for _, tt := range tests {
Expand All @@ -222,6 +225,9 @@ func TestParseVolumeOptions(t *testing.T) {
})
if err != nil {
if tt.wantFail {
if tt.wantErrContains != "" {
assert.ErrorContains(t, err, tt.wantErrContains)
}
return
}
t.Errorf("failed to parse option %q: %v", tt.optsRaw, err)
Expand Down
Loading