ignore mount options which don't match type

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-04-13 11:53:06 +02:00
parent 74773b9062
commit 6ec682cade
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 35 additions and 3 deletions

View File

@ -774,18 +774,50 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
}
}
bind, vol, tmpfs := buildMountOptions(volume)
return mount.Mount{
Type: mount.Type(volume.Type),
Source: source,
Target: volume.Target,
ReadOnly: volume.ReadOnly,
Consistency: mount.Consistency(volume.Consistency),
BindOptions: buildBindOption(volume.Bind),
VolumeOptions: buildVolumeOptions(volume.Volume),
TmpfsOptions: buildTmpfsOptions(volume.Tmpfs),
BindOptions: bind,
VolumeOptions: vol,
TmpfsOptions: tmpfs,
}, nil
}
func buildMountOptions(volume types.ServiceVolumeConfig) (*mount.BindOptions, *mount.VolumeOptions, *mount.TmpfsOptions) {
switch volume.Type {
case "bind":
if volume.Volume != nil {
logrus.Warnf("mount of type `bind` should not define `volume` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `tmpfs` should not define `tmpfs` option")
}
return buildBindOption(volume.Bind), nil, nil
case "volume":
if volume.Bind != nil {
logrus.Warnf("mount of type `volume` should not define `bind` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `volume` should not define `tmpfs` option")
}
return nil, buildVolumeOptions(volume.Volume), nil
case "tmpfs":
if volume.Bind != nil {
logrus.Warnf("mount of type `tmpfs` should not define `bind` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `tmpfs` should not define `volumeZ` option")
}
return nil, nil, buildTmpfsOptions(volume.Tmpfs)
}
return nil, nil, nil
}
func buildBindOption(bind *types.ServiceVolumeBind) *mount.BindOptions {
if bind == nil {
return nil