fix conversion of anonymous volumes in compose-file
the `convertVolumeToMount()` function did not take
anonymous volumes into account when converting
volume specifications to bind-mounts.
this resulted in the conversion to try to
look up an empty "source" volume, which
lead to an error;
undefined volume:
this patch distinguishes "anonymous"
volumes from bind-mounts and named-volumes,
and skips further processing if no source
is defined (i.e. the volume is "anonymous").
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: bc4590fd7d
Component: cli
This commit is contained in:
@ -42,7 +42,15 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam
|
||||
case 1:
|
||||
target = parts[0]
|
||||
default:
|
||||
return mount.Mount{}, fmt.Errorf("invald volume: %s", volumeSpec)
|
||||
return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec)
|
||||
}
|
||||
|
||||
if source == "" {
|
||||
// Anonymous volume
|
||||
return mount.Mount{
|
||||
Type: mount.TypeVolume,
|
||||
Target: target,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TODO: catch Windows paths here
|
||||
|
||||
@ -34,6 +34,18 @@ func TestGetBindOptionsNone(t *testing.T) {
|
||||
assert.Equal(t, opts, (*mount.BindOptions)(nil))
|
||||
}
|
||||
|
||||
func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
||||
stackVolumes := volumes{}
|
||||
namespace := NewNamespace("foo")
|
||||
expected := mount.Mount{
|
||||
Type: mount.TypeVolume,
|
||||
Target: "/foo/bar",
|
||||
}
|
||||
mount, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, mount, expected)
|
||||
}
|
||||
|
||||
func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
||||
stackVolumes := volumes{
|
||||
"normal": composetypes.VolumeConfig{
|
||||
|
||||
Reference in New Issue
Block a user