From 58f845701ac743d027dfb78f7b667e04ad358ef5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 18 Dec 2016 16:50:32 +0100 Subject: [PATCH] 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 Upstream-commit: bc4590fd7d5cc7745e66def87895b2776ef4876e Component: cli --- components/cli/compose/convert/volume.go | 10 +++++++++- components/cli/compose/convert/volume_test.go | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/cli/compose/convert/volume.go b/components/cli/compose/convert/volume.go index 4eb5788204..027774bcec 100644 --- a/components/cli/compose/convert/volume.go +++ b/components/cli/compose/convert/volume.go @@ -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 diff --git a/components/cli/compose/convert/volume_test.go b/components/cli/compose/convert/volume_test.go index 5e9c042b5f..3ca6ab4a52 100644 --- a/components/cli/compose/convert/volume_test.go +++ b/components/cli/compose/convert/volume_test.go @@ -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{