1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix external volume error to pass validation.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-03-24 12:24:58 -04:00
parent 3c22c7d5e9
commit 7236686987

View file

@ -19,6 +19,7 @@ import (
units "github.com/docker/go-units" units "github.com/docker/go-units"
shellwords "github.com/mattn/go-shellwords" shellwords "github.com/mattn/go-shellwords"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
@ -435,6 +436,12 @@ func LoadNetworks(source map[string]interface{}) (map[string]types.NetworkConfig
return networks, nil return networks, nil
} }
func externalVolumeError(volume, key string) error {
return errors.Errorf(
"conflicting parameters \"external\" and %q specified for volume %q",
key, volume)
}
// LoadVolumes produces a VolumeConfig map from a compose file Dict // LoadVolumes produces a VolumeConfig map from a compose file Dict
// the source Dict is not validated if directly used. Use Load() to enable validation // the source Dict is not validated if directly used. Use Load() to enable validation
func LoadVolumes(source map[string]interface{}) (map[string]types.VolumeConfig, error) { func LoadVolumes(source map[string]interface{}) (map[string]types.VolumeConfig, error) {
@ -445,15 +452,14 @@ func LoadVolumes(source map[string]interface{}) (map[string]types.VolumeConfig,
} }
for name, volume := range volumes { for name, volume := range volumes {
if volume.External.External { if volume.External.External {
template := "conflicting parameters \"external\" and %q specified for volume %q"
if volume.Driver != "" { if volume.Driver != "" {
return nil, fmt.Errorf(template, "driver", name) return nil, externalVolumeError(name, "driver")
} }
if len(volume.DriverOpts) > 0 { if len(volume.DriverOpts) > 0 {
return nil, fmt.Errorf(template, "driver_opts", name) return nil, externalVolumeError(name, "driver_opts")
} }
if len(volume.Labels) > 0 { if len(volume.Labels) > 0 {
return nil, fmt.Errorf(template, "labels", name) return nil, externalVolumeError(name, "labels")
} }
if volume.External.Name == "" { if volume.External.Name == "" {
volume.External.Name = name volume.External.Name = name