mirror of https://github.com/docker/cli.git
Merge pull request #31176 from adshmh/29662-stack-deploy-error-if-external-combined-with-other-volume-options
stack deploy exits with error if both 'external' and other options are specified for a volume
This commit is contained in:
commit
4c4af071c7
|
@ -435,11 +435,23 @@ func LoadVolumes(source types.Dict) (map[string]types.VolumeConfig, error) {
|
||||||
return volumes, err
|
return volumes, err
|
||||||
}
|
}
|
||||||
for name, volume := range volumes {
|
for name, volume := range volumes {
|
||||||
if volume.External.External && volume.External.Name == "" {
|
if volume.External.External {
|
||||||
|
template := "conflicting parameters \"external\" and %q specified for volume %q"
|
||||||
|
if volume.Driver != "" {
|
||||||
|
return nil, fmt.Errorf(template, "driver", name)
|
||||||
|
}
|
||||||
|
if len(volume.DriverOpts) > 0 {
|
||||||
|
return nil, fmt.Errorf(template, "driver_opts", name)
|
||||||
|
}
|
||||||
|
if len(volume.Labels) > 0 {
|
||||||
|
return nil, fmt.Errorf(template, "labels", name)
|
||||||
|
}
|
||||||
|
if volume.External.Name == "" {
|
||||||
volume.External.Name = name
|
volume.External.Name = name
|
||||||
volumes[name] = volume
|
volumes[name] = volume
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return volumes, nil
|
return volumes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -541,6 +541,50 @@ services:
|
||||||
assert.Contains(t, forbidden, "extends")
|
assert.Contains(t, forbidden, "extends")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInvalidExternalAndDriverCombination(t *testing.T) {
|
||||||
|
_, err := loadYAML(`
|
||||||
|
version: "3"
|
||||||
|
volumes:
|
||||||
|
external_volume:
|
||||||
|
external: true
|
||||||
|
driver: foobar
|
||||||
|
`)
|
||||||
|
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "conflicting parameters \"external\" and \"driver\" specified for volume")
|
||||||
|
assert.Contains(t, err.Error(), "external_volume")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvalidExternalAndDirverOptsCombination(t *testing.T) {
|
||||||
|
_, err := loadYAML(`
|
||||||
|
version: "3"
|
||||||
|
volumes:
|
||||||
|
external_volume:
|
||||||
|
external: true
|
||||||
|
driver_opts:
|
||||||
|
beep: boop
|
||||||
|
`)
|
||||||
|
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "conflicting parameters \"external\" and \"driver_opts\" specified for volume")
|
||||||
|
assert.Contains(t, err.Error(), "external_volume")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvalidExternalAndLabelsCombination(t *testing.T) {
|
||||||
|
_, err := loadYAML(`
|
||||||
|
version: "3"
|
||||||
|
volumes:
|
||||||
|
external_volume:
|
||||||
|
external: true
|
||||||
|
labels:
|
||||||
|
- beep=boop
|
||||||
|
`)
|
||||||
|
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "conflicting parameters \"external\" and \"labels\" specified for volume")
|
||||||
|
assert.Contains(t, err.Error(), "external_volume")
|
||||||
|
}
|
||||||
|
|
||||||
func durationPtr(value time.Duration) *time.Duration {
|
func durationPtr(value time.Duration) *time.Duration {
|
||||||
return &value
|
return &value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue