From 9ffde85523aafa8f687bb90e36828e89f992b95b Mon Sep 17 00:00:00 2001 From: Austin Raney Date: Thu, 22 Jun 2023 07:59:49 -0400 Subject: [PATCH] add support for cluster volumes --- convert/volume.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/convert/volume.go b/convert/volume.go index 34f65ba..1d4153c 100644 --- a/convert/volume.go +++ b/convert/volume.go @@ -34,8 +34,11 @@ func convertVolumeToMount( return handleTmpfsToMount(volume) case "npipe": return handleNpipeToMount(volume) + case "cluster": + return handleClusterToMount(volume) } - return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs, or npipe") + + return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs, npipe, or cluster") } func handleVolumeToMount( @@ -148,6 +151,25 @@ func handleNpipeToMount(volume composego.ServiceVolumeConfig) (mount.Mount, erro return result, nil } +func handleClusterToMount(volume composego.ServiceVolumeConfig) (mount.Mount, error) { + result := createMountFromVolume(volume) + if volume.Source == "" { + return mount.Mount{}, errors.New("invalid cluster source, source cannot be empty") + } + if volume.Volume != nil { + return mount.Mount{}, errors.New("volume options are incompatible with type cluster") + } + if volume.Tmpfs != nil { + return mount.Mount{}, errors.New("tmpfs options are incompatible with type cluster") + } + if volume.Bind != nil { + result.BindOptions = &mount.BindOptions{ + Propagation: mount.Propagation(volume.Bind.Propagation), + } + } + return result, nil +} + func createMountFromVolume(volume composego.ServiceVolumeConfig) mount.Mount { return mount.Mount{ Type: mount.Type(volume.Type),