Pārlūkot izejas kodu

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>
Sebastiaan van Stijn 8 gadi atpakaļ
vecāks
revīzija
34889e579f
2 mainītis faili ar 21 papildinājumiem un 1 dzēšanām
  1. 9 1
      cli/compose/convert/volume.go
  2. 12 0
      cli/compose/convert/volume_test.go

+ 9 - 1
cli/compose/convert/volume.go

@@ -42,7 +42,15 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam
 	case 1:
 	case 1:
 		target = parts[0]
 		target = parts[0]
 	default:
 	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
 	// TODO: catch Windows paths here

+ 12 - 0
cli/compose/convert/volume_test.go

@@ -34,6 +34,18 @@ func TestGetBindOptionsNone(t *testing.T) {
 	assert.Equal(t, opts, (*mount.BindOptions)(nil))
 	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) {
 func TestConvertVolumeToMountNamedVolume(t *testing.T) {
 	stackVolumes := volumes{
 	stackVolumes := volumes{
 		"normal": composetypes.VolumeConfig{
 		"normal": composetypes.VolumeConfig{