From 81a95fade593d4fda6c6f340865ae24824ac2ac8 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Wed, 6 Apr 2022 15:59:59 +0530 Subject: run, mount: allow setting driver specific option using volume-opt `--mount` should allow setting driver specific options using `volume-opt` when `type=volume` is set. This ensures parity with docker's `volume-opt`. Signed-off-by: Aditya R --- libpod/runtime_ctr.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libpod') diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 8c3d283a5..f92898b1c 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -475,6 +475,26 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai if isAnonymous { volOptions = append(volOptions, withSetAnon()) } + + // If volume-opts are set parse and add driver opts. + if len(vol.Options) > 0 { + isDriverOpts := false + driverOpts := make(map[string]string) + for _, opts := range vol.Options { + if strings.HasPrefix(opts, "volume-opt") { + isDriverOpts = true + driverOptKey, driverOptValue, err := util.ParseDriverOpts(opts) + if err != nil { + return nil, err + } + driverOpts[driverOptKey] = driverOptValue + } + } + if isDriverOpts { + parsedOptions := []VolumeCreateOption{WithVolumeOptions(driverOpts)} + volOptions = append(volOptions, parsedOptions...) + } + } newVol, err := r.newVolume(ctx, volOptions...) if err != nil { return nil, errors.Wrapf(err, "error creating named volume %q", vol.Name) -- cgit v1.2.3-54-g00ecf