浏览代码

volume: remove the short RRO forms in favor of the long forms

"ro-non-recursive", "ro-force-recursive", and "rro" are
now removed from the legacy mount API.

CLI may still support them via the new mount API (if we want).

Follow-up to PR 45278

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Akihiro Suda 2 年之前
父节点
当前提交
483a1933a2

+ 0 - 4
integration/container/mounts_linux_test.go

@@ -480,7 +480,6 @@ func TestContainerBindMountRecursivelyReadOnly(t *testing.T) {
 		ReadOnlyNonRecursive: true,
 		ReadOnlyNonRecursive: true,
 		Propagation:          mounttypes.PropagationRPrivate,
 		Propagation:          mounttypes.PropagationRPrivate,
 	}
 	}
-	nonRecursiveAsStr := nonRecursive.Source + ":" + nonRecursive.Target + ":ro-non-recursive,rprivate"
 
 
 	// Force recursive
 	// Force recursive
 	forceRecursive := ro
 	forceRecursive := ro
@@ -488,7 +487,6 @@ func TestContainerBindMountRecursivelyReadOnly(t *testing.T) {
 		ReadOnlyForceRecursive: true,
 		ReadOnlyForceRecursive: true,
 		Propagation:            mounttypes.PropagationRPrivate,
 		Propagation:            mounttypes.PropagationRPrivate,
 	}
 	}
-	forceRecursiveAsStr := forceRecursive.Source + ":" + forceRecursive.Target + ":ro-force-recursive,rprivate"
 
 
 	ctx := context.Background()
 	ctx := context.Background()
 	client := testEnv.APIClient()
 	client := testEnv.APIClient()
@@ -498,13 +496,11 @@ func TestContainerBindMountRecursivelyReadOnly(t *testing.T) {
 		container.Run(ctx, t, client, container.WithBindRaw(roAsStr), container.WithCmd(roVerifier...)),
 		container.Run(ctx, t, client, container.WithBindRaw(roAsStr), container.WithCmd(roVerifier...)),
 
 
 		container.Run(ctx, t, client, container.WithMount(nonRecursive), container.WithCmd(nonRecursiveVerifier...)),
 		container.Run(ctx, t, client, container.WithMount(nonRecursive), container.WithCmd(nonRecursiveVerifier...)),
-		container.Run(ctx, t, client, container.WithBindRaw(nonRecursiveAsStr), container.WithCmd(nonRecursiveVerifier...)),
 	}
 	}
 
 
 	if rroSupported {
 	if rroSupported {
 		containers = append(containers,
 		containers = append(containers,
 			container.Run(ctx, t, client, container.WithMount(forceRecursive), container.WithCmd(forceRecursiveVerifier...)),
 			container.Run(ctx, t, client, container.WithMount(forceRecursive), container.WithCmd(forceRecursiveVerifier...)),
-			container.Run(ctx, t, client, container.WithBindRaw(forceRecursiveAsStr), container.WithCmd(forceRecursiveVerifier...)),
 		)
 		)
 	}
 	}
 
 

+ 1 - 22
volume/mounts/linux_parser.go

@@ -198,7 +198,7 @@ func (p *linuxParser) ReadWrite(mode string) bool {
 	}
 	}
 
 
 	for _, o := range strings.Split(mode, ",") {
 	for _, o := range strings.Split(mode, ",") {
-		if o == "ro" || strings.HasPrefix(o, "ro-") || o == "rro" {
+		if o == "ro" {
 			return false
 			return false
 		}
 		}
 	}
 	}
@@ -266,24 +266,6 @@ func (p *linuxParser) ParseMountRaw(raw, volumeDriver string) (*MountPoint, erro
 		}
 		}
 	}
 	}
 
 
-	for _, m := range strings.Split(mode, ",") {
-		m = strings.TrimSpace(m)
-		if strings.HasPrefix(m, "ro-") || m == "rro" {
-			if spec.Type != mount.TypeBind {
-				return nil, fmt.Errorf("mount mode %q requires a bind mount: %w", mode, errInvalidSpec(raw))
-			}
-			if spec.BindOptions == nil {
-				spec.BindOptions = &mount.BindOptions{}
-			}
-			switch m {
-			case "ro-non-recursive":
-				spec.BindOptions.ReadOnlyNonRecursive = true
-			case "ro-force-recursive", "rro":
-				spec.BindOptions.ReadOnlyForceRecursive = true
-			}
-		}
-	}
-
 	mp, err := p.parseMountSpec(spec, false)
 	mp, err := p.parseMountSpec(spec, false)
 	if mp != nil {
 	if mp != nil {
 		mp.Mode = mode
 		mp.Mode = mode
@@ -353,9 +335,6 @@ func (p *linuxParser) ParseVolumesFrom(spec string) (string, string, error) {
 	if !linuxValidMountMode(mode) {
 	if !linuxValidMountMode(mode) {
 		return "", "", errInvalidMode(mode)
 		return "", "", errInvalidMode(mode)
 	}
 	}
-	if strings.HasPrefix(mode, "ro-") || mode == "rro" {
-		return "", "", fmt.Errorf("mount mode %q is not supported for volumes-from mounts: %w", mode, errInvalidMode(mode))
-	}
 	// For now don't allow propagation properties while importing
 	// For now don't allow propagation properties while importing
 	// volumes from data container. These volumes will inherit
 	// volumes from data container. These volumes will inherit
 	// the same propagation property as of the original volume
 	// the same propagation property as of the original volume

+ 18 - 30
volume/mounts/linux_parser_test.go

@@ -99,30 +99,25 @@ func TestLinuxParseMountRaw(t *testing.T) {
 
 
 func TestLinuxParseMountRawSplit(t *testing.T) {
 func TestLinuxParseMountRawSplit(t *testing.T) {
 	cases := []struct {
 	cases := []struct {
-		bind        string
-		driver      string
-		expType     mount.Type
-		expDest     string
-		expSource   string
-		expName     string
-		expDriver   string
-		expRW       bool
-		expNonRRO   bool
-		expForceRRO bool
-		fail        bool
+		bind      string
+		driver    string
+		expType   mount.Type
+		expDest   string
+		expSource string
+		expName   string
+		expDriver string
+		expRW     bool
+		fail      bool
 	}{
 	}{
-		{"/tmp:/tmp1", "", mount.TypeBind, "/tmp1", "/tmp", "", "", true, false, false, false},
-		{"/tmp:/tmp2:ro", "", mount.TypeBind, "/tmp2", "/tmp", "", "", false, false, false, false},
-		{"/tmp:/tmp3:rw", "", mount.TypeBind, "/tmp3", "/tmp", "", "", true, false, false, false},
-		{"/tmp:/tmp4:foo", "", mount.TypeBind, "", "", "", "", false, false, false, true},
-		{"/tmp:/tmp5:ro-non-recursive", "", mount.TypeBind, "/tmp5", "/tmp", "", "", false, true, false, false},
-		{"/tmp:/tmp6:ro-force-recursive,rprivate", "", mount.TypeBind, "/tmp6", "/tmp", "", "", false, false, true, false},
-		{"/tmp:/tmp7:rro", "", mount.TypeBind, "/tmp7", "/tmp", "", "", false, false, true, false},
-		{"name:/named1", "", mount.TypeVolume, "/named1", "", "name", "", true, false, false, false},
-		{"name:/named2", "external", mount.TypeVolume, "/named2", "", "name", "external", true, false, false, false},
-		{"name:/named3:ro", "local", mount.TypeVolume, "/named3", "", "name", "local", false, false, false, false},
-		{"local/name:/tmp:rw", "", mount.TypeVolume, "/tmp", "", "local/name", "", true, false, false, false},
-		{"/tmp:tmp", "", mount.TypeBind, "", "", "", "", true, false, false, true},
+		{"/tmp:/tmp1", "", mount.TypeBind, "/tmp1", "/tmp", "", "", true, false},
+		{"/tmp:/tmp2:ro", "", mount.TypeBind, "/tmp2", "/tmp", "", "", false, false},
+		{"/tmp:/tmp3:rw", "", mount.TypeBind, "/tmp3", "/tmp", "", "", true, false},
+		{"/tmp:/tmp4:foo", "", mount.TypeBind, "", "", "", "", false, true},
+		{"name:/named1", "", mount.TypeVolume, "/named1", "", "name", "", true, false},
+		{"name:/named2", "external", mount.TypeVolume, "/named2", "", "name", "external", true, false},
+		{"name:/named3:ro", "local", mount.TypeVolume, "/named3", "", "name", "local", false, false},
+		{"local/name:/tmp:rw", "", mount.TypeVolume, "/tmp", "", "local/name", "", true, false},
+		{"/tmp:tmp", "", mount.TypeBind, "", "", "", "", true, true},
 	}
 	}
 
 
 	parser := NewLinuxParser()
 	parser := NewLinuxParser()
@@ -146,13 +141,6 @@ func TestLinuxParseMountRawSplit(t *testing.T) {
 			assert.Equal(t, m.Driver, c.expDriver)
 			assert.Equal(t, m.Driver, c.expDriver)
 			assert.Equal(t, m.RW, c.expRW)
 			assert.Equal(t, m.RW, c.expRW)
 			assert.Equal(t, m.Type, c.expType)
 			assert.Equal(t, m.Type, c.expType)
-			var nonRRO, forceRRO bool
-			if m.Spec.BindOptions != nil {
-				nonRRO = m.Spec.BindOptions.ReadOnlyNonRecursive
-				forceRRO = m.Spec.BindOptions.ReadOnlyForceRecursive
-			}
-			assert.Equal(t, nonRRO, c.expNonRRO)
-			assert.Equal(t, forceRRO, c.expForceRRO)
 		})
 		})
 	}
 	}
 }
 }

+ 2 - 5
volume/mounts/parser.go

@@ -13,11 +13,8 @@ var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't
 
 
 // read-write modes
 // read-write modes
 var rwModes = map[string]bool{
 var rwModes = map[string]bool{
-	"rw":                 true,
-	"ro":                 true, // attempts recursive read-only if possible
-	"ro-non-recursive":   true, // makes the mount non-recursively read-only, but still leaves the mount recursive
-	"ro-force-recursive": true, // raises an error if the mount cannot be made recursively read-only
-	"rro":                true, // alias for ro-force-recursive
+	"rw": true,
+	"ro": true, // attempts recursive read-only if possible
 }
 }
 
 
 // Parser represents a platform specific parser for mount expressions
 // Parser represents a platform specific parser for mount expressions