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
27 changes: 27 additions & 0 deletions pkg/flags/mountopt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package flags

import "testing"

// A mount option without a value used to index past the end of the split.
func TestParseMountOptionsWithoutValue(t *testing.T) {
tests := []struct {
in string
wantErr bool
}{
{"readonly=true", false},
{"readonly=false", false},
{"readonly", true},
{"readonly=", false},
{"bogus=1", true},
}

for _, tc := range tests {
_, err := parseMountOptions(tc.in)
if tc.wantErr && err == nil {
t.Errorf("%q: expected an error, got none", tc.in)
}
if !tc.wantErr && err != nil {
t.Errorf("%q: unexpected error: %v", tc.in, err)
}
}
}
8 changes: 3 additions & 5 deletions pkg/flags/podspec_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,9 @@ func parseMountOptions(options string) (*util.OrderedMap, error) {
pair := strings.SplitN(slice, "=", 2)
switch strings.ToLower(pair[0]) {
case "readonly":
if len(pair) != 2 {
return nil, fmt.Errorf("mount option %q requires a value, for example readOnly=true", pair[0])
}
mountOptions.Set("readonly", pair[1])
default:
return nil, fmt.Errorf("unknown mount option %q", pair[0])
Expand Down Expand Up @@ -994,11 +997,6 @@ func getMountInfo(volume string) *MountInfo {
configSlices := strings.SplitN(volume, ":", 2)
var mountInfo MountInfo
if len(configSlices) == 2 {
readOnlySlices := strings.SplitN(configSlices[1], "=", 2)
switch strings.ToLower(readOnlySlices[0]) {
case "readonly":

}
mountInfo.MountOptions = configSlices[1]
}
slices := strings.SplitN(configSlices[0], "/", 2)
Expand Down
Loading