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>
| ... | ... |
@@ -42,7 +42,15 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam |
| 42 | 42 |
case 1: |
| 43 | 43 |
target = parts[0] |
| 44 | 44 |
default: |
| 45 |
- return mount.Mount{}, fmt.Errorf("invald volume: %s", volumeSpec)
|
|
| 45 |
+ return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec)
|
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ if source == "" {
|
|
| 49 |
+ // Anonymous volume |
|
| 50 |
+ return mount.Mount{
|
|
| 51 |
+ Type: mount.TypeVolume, |
|
| 52 |
+ Target: target, |
|
| 53 |
+ }, nil |
|
| 46 | 54 |
} |
| 47 | 55 |
|
| 48 | 56 |
// TODO: catch Windows paths here |
| ... | ... |
@@ -34,6 +34,18 @@ func TestGetBindOptionsNone(t *testing.T) {
|
| 34 | 34 |
assert.Equal(t, opts, (*mount.BindOptions)(nil)) |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
+func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
|
| 38 |
+ stackVolumes := volumes{}
|
|
| 39 |
+ namespace := NewNamespace("foo")
|
|
| 40 |
+ expected := mount.Mount{
|
|
| 41 |
+ Type: mount.TypeVolume, |
|
| 42 |
+ Target: "/foo/bar", |
|
| 43 |
+ } |
|
| 44 |
+ mount, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
|
|
| 45 |
+ assert.NilError(t, err) |
|
| 46 |
+ assert.DeepEqual(t, mount, expected) |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 37 | 49 |
func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
| 38 | 50 |
stackVolumes := volumes{
|
| 39 | 51 |
"normal": composetypes.VolumeConfig{
|