mirror of
https://github.com/docker/cli.git
synced 2026-09-24 15:30:10 -05:00
Use newer default values for mounts CLI
In the API: `Writable` changed to `ReadOnly` `Populate` changed to `NoCopy` Corresponding CLI options updated to: `volume-writable` changed to `volume-readonly` `volume-populate` changed to `volume-nocopy` Signed-off-by: Brian Goff <cpuguy83@gmail.com> Upstream-commit: 56f3422468a0b43da7bae7a01762ce4f0a92d9ff Component: engine
This commit is contained in:
@@ -176,10 +176,16 @@ func (m *MountOpt) Set(value string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Set writable as the default
|
||||
for _, field := range fields {
|
||||
parts := strings.SplitN(field, "=", 2)
|
||||
if len(parts) == 1 && strings.ToLower(parts[0]) == "writable" {
|
||||
mount.Writable = true
|
||||
if len(parts) == 1 && strings.ToLower(parts[0]) == "readonly" {
|
||||
mount.ReadOnly = true
|
||||
continue
|
||||
}
|
||||
|
||||
if len(parts) == 1 && strings.ToLower(parts[0]) == "volume-nocopy" {
|
||||
volumeOptions().NoCopy = true
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -195,15 +201,16 @@ func (m *MountOpt) Set(value string) error {
|
||||
mount.Source = value
|
||||
case "target":
|
||||
mount.Target = value
|
||||
case "writable":
|
||||
mount.Writable, err = strconv.ParseBool(value)
|
||||
case "readonly":
|
||||
ro, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid value for writable: %s", value)
|
||||
return fmt.Errorf("invalid value for readonly: %s", value)
|
||||
}
|
||||
mount.ReadOnly = ro
|
||||
case "bind-propagation":
|
||||
bindOptions().Propagation = swarm.MountPropagation(strings.ToUpper(value))
|
||||
case "volume-populate":
|
||||
volumeOptions().Populate, err = strconv.ParseBool(value)
|
||||
case "volume-nocopy":
|
||||
volumeOptions().NoCopy, err = strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid value for populate: %s", value)
|
||||
}
|
||||
@@ -229,6 +236,17 @@ func (m *MountOpt) Set(value string) error {
|
||||
return fmt.Errorf("target is required")
|
||||
}
|
||||
|
||||
if mount.VolumeOptions != nil && mount.Source == "" {
|
||||
return fmt.Errorf("source is required when specifying volume-* options")
|
||||
}
|
||||
|
||||
if mount.Type == swarm.MountType("BIND") && mount.VolumeOptions != nil {
|
||||
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", swarm.MountTypeBind)
|
||||
}
|
||||
if mount.Type == swarm.MountType("VOLUME") && mount.BindOptions != nil {
|
||||
return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", swarm.MountTypeVolume)
|
||||
}
|
||||
|
||||
m.values = append(m.values, mount)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -111,5 +111,53 @@ func TestMountOptSetErrorInvalidField(t *testing.T) {
|
||||
|
||||
func TestMountOptSetErrorInvalidWritable(t *testing.T) {
|
||||
var mount MountOpt
|
||||
assert.Error(t, mount.Set("type=VOLUME,writable=yes"), "invalid value for writable: yes")
|
||||
assert.Error(t, mount.Set("type=VOLUME,readonly=no"), "invalid value for readonly: no")
|
||||
}
|
||||
|
||||
func TestMountOptDefaultEnableWritable(t *testing.T) {
|
||||
var m MountOpt
|
||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo"))
|
||||
assert.Equal(t, m.values[0].ReadOnly, false)
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly"))
|
||||
assert.Equal(t, m.values[0].ReadOnly, true)
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
|
||||
assert.Equal(t, m.values[0].ReadOnly, true)
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
|
||||
assert.Equal(t, m.values[0].ReadOnly, false)
|
||||
}
|
||||
|
||||
func TestMountOptVolumeNoCopy(t *testing.T) {
|
||||
var m MountOpt
|
||||
assert.Error(t, m.Set("type=volume,target=/foo,volume-nocopy"), "source is required")
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))
|
||||
assert.Equal(t, m.values[0].VolumeOptions == nil, true)
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true"))
|
||||
assert.Equal(t, m.values[0].VolumeOptions != nil, true)
|
||||
assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true)
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy"))
|
||||
assert.Equal(t, m.values[0].VolumeOptions != nil, true)
|
||||
assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true)
|
||||
|
||||
m = MountOpt{}
|
||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1"))
|
||||
assert.Equal(t, m.values[0].VolumeOptions != nil, true)
|
||||
assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true)
|
||||
}
|
||||
|
||||
func TestMountOptTypeConflict(t *testing.T) {
|
||||
var m MountOpt
|
||||
assert.Error(t, m.Set("type=bind,target=/foo,source=/foo,volume-nocopy=true"), "cannot mix")
|
||||
assert.Error(t, m.Set("type=volume,target=/foo,source=/foo,bind-propagation=rprivate"), "cannot mix")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user