Skip to content

Commit 1f7311c

Browse files
committed
cli/compose/types: ServiceVolumeConfig: use strong type for Consistency field
Using a strong type for this field, to make it clearer what's supported, and to allow assigning values without having to cast them. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent d17d7bd commit 1f7311c

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

‎cli/compose/convert/volume.go‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func createMountFromVolume(volume composetypes.ServiceVolumeConfig) mount.Mount
3030
Target: volume.Target,
3131
ReadOnly: volume.ReadOnly,
3232
Source: volume.Source,
33-
Consistency: mount.Consistency(volume.Consistency),
33+
Consistency: volume.Consistency,
3434
}
3535
}
3636

@@ -196,21 +196,17 @@ func handleClusterToMount(
196196
return result, nil
197197
}
198198

199-
func convertVolumeToMount(
200-
volume composetypes.ServiceVolumeConfig,
201-
stackVolumes volumes,
202-
namespace Namespace,
203-
) (mount.Mount, error) {
199+
func convertVolumeToMount(volume composetypes.ServiceVolumeConfig, stackVolumes volumes, namespace Namespace) (mount.Mount, error) {
204200
switch volume.Type {
205-
case "volume", "":
201+
case mount.TypeVolume, "":
206202
return handleVolumeToMount(volume, stackVolumes, namespace)
207-
case "bind":
203+
case mount.TypeBind:
208204
return handleBindToMount(volume)
209-
case "tmpfs":
205+
case mount.TypeTmpfs:
210206
return handleTmpfsToMount(volume)
211-
case "npipe":
207+
case mount.TypeNamedPipe:
212208
return handleNpipeToMount(volume)
213-
case "cluster":
209+
case mount.TypeCluster:
214210
return handleClusterToMount(volume, stackVolumes, namespace)
215211
}
216212
return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs, npipe, or cluster")

‎cli/compose/types/types.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ type ServiceVolumeConfig struct {
390390
Source string `yaml:",omitempty" json:"source,omitempty"`
391391
Target string `yaml:",omitempty" json:"target,omitempty"`
392392
ReadOnly bool `mapstructure:"read_only" yaml:"read_only,omitempty" json:"read_only,omitempty"`
393-
Consistency string `yaml:",omitempty" json:"consistency,omitempty"`
393+
Consistency mount.Consistency `yaml:",omitempty" json:"consistency,omitempty"`
394394
Bind *ServiceVolumeBind `yaml:",omitempty" json:"bind,omitempty"`
395395
Volume *ServiceVolumeVolume `yaml:",omitempty" json:"volume,omitempty"`
396396
Tmpfs *ServiceVolumeTmpfs `yaml:",omitempty" json:"tmpfs,omitempty"`

0 commit comments

Comments
 (0)