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>
| ... | ... |
@@ -359,7 +359,15 @@ func convertVolumeToMount( |
| 359 | 359 |
case 1: |
| 360 | 360 |
target = parts[0] |
| 361 | 361 |
default: |
| 362 |
- return mount.Mount{}, fmt.Errorf("invald volume: %s", volumeSpec)
|
|
| 362 |
+ return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec)
|
|
| 363 |
+ } |
|
| 364 |
+ |
|
| 365 |
+ if source == "" {
|
|
| 366 |
+ // Anonymous volume |
|
| 367 |
+ return mount.Mount{
|
|
| 368 |
+ Type: mount.TypeVolume, |
|
| 369 |
+ Target: target, |
|
| 370 |
+ }, nil |
|
| 363 | 371 |
} |
| 364 | 372 |
|
| 365 | 373 |
// TODO: catch Windows paths here |
| 366 | 374 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,21 @@ |
| 0 |
+package stack |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "testing" |
|
| 4 |
+ |
|
| 5 |
+ composetypes "github.com/aanand/compose-file/types" |
|
| 6 |
+ "github.com/docker/docker/api/types/mount" |
|
| 7 |
+ "github.com/docker/docker/pkg/testutil/assert" |
|
| 8 |
+) |
|
| 9 |
+ |
|
| 10 |
+func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
|
| 11 |
+ stackVolumes := map[string]composetypes.VolumeConfig{}
|
|
| 12 |
+ namespace := namespace{name:"foo"}
|
|
| 13 |
+ expected := mount.Mount{
|
|
| 14 |
+ Type: mount.TypeVolume, |
|
| 15 |
+ Target: "/foo/bar", |
|
| 16 |
+ } |
|
| 17 |
+ mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
|
|
| 18 |
+ assert.NilError(t, err) |
|
| 19 |
+ assert.DeepEqual(t, mnt, expected) |
|
| 20 |
+} |