summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-12-21 11:37:12 +0800
committerzhangguanzhang <zhangguanzhang@qq.com>2020-12-23 09:13:20 +0800
commit28138dafcc391b0d03633ee9c8e23ebc229842ba (patch)
treed373363d0d597c9e937afb3b4b6865f9950b645e
parent5c6b5ef34905f40562b518799c35be8d06694e65 (diff)
downloadpodman-28138dafcc391b0d03633ee9c8e23ebc229842ba.tar.gz
podman-28138dafcc391b0d03633ee9c8e23ebc229842ba.tar.bz2
podman-28138dafcc391b0d03633ee9c8e23ebc229842ba.zip
Fix missing options in volumes display while setting uid and gid
``` $ podman volume create testvol --opt o=uid=1001,gid=1001 $ ./bin/podman volume create testvol2 --opt o=uid=1001,gid=1001 $ podman volume inspect testvol "Options": {}, $ podman volume inspect testvol2 "Options": { "GID": "1001", "UID": "1001", "o": "uid=1001,gid=1001" }, ``` Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
-rw-r--r--libpod/options.go2
-rw-r--r--libpod/runtime_volume_linux.go2
-rw-r--r--pkg/domain/infra/abi/parse/parse.go6
-rw-r--r--test/e2e/volume_create_test.go8
4 files changed, 16 insertions, 2 deletions
diff --git a/libpod/options.go b/libpod/options.go
index c2db13560..1ef058cc8 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1593,7 +1593,7 @@ func WithVolumeOptions(options map[string]string) VolumeCreateOption {
volume.config.Options = make(map[string]string)
for key, value := range options {
switch key {
- case "type", "device", "o":
+ case "type", "device", "o", "UID", "GID":
volume.config.Options[key] = value
default:
return errors.Wrapf(define.ErrInvalidArg, "unrecognized volume option %q is not supported with local driver", key)
diff --git a/libpod/runtime_volume_linux.go b/libpod/runtime_volume_linux.go
index e1877b17d..9bf0fd108 100644
--- a/libpod/runtime_volume_linux.go
+++ b/libpod/runtime_volume_linux.go
@@ -58,7 +58,7 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption)
// Validate options
for key := range volume.config.Options {
switch key {
- case "device", "o", "type":
+ case "device", "o", "type", "UID", "GID":
// Do nothing, valid keys
default:
return nil, errors.Wrapf(define.ErrInvalidArg, "invalid mount option %s for driver 'local'", key)
diff --git a/pkg/domain/infra/abi/parse/parse.go b/pkg/domain/infra/abi/parse/parse.go
index 37568ea11..6a6380e33 100644
--- a/pkg/domain/infra/abi/parse/parse.go
+++ b/pkg/domain/infra/abi/parse/parse.go
@@ -38,6 +38,9 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
}
logrus.Debugf("Removing uid= from options and adding WithVolumeUID for UID %d", intUID)
libpodOptions = append(libpodOptions, libpod.WithVolumeUID(intUID))
+ finalVal = append(finalVal, o)
+ // set option "UID": "$uid"
+ volumeOptions["UID"] = splitO[1]
case "gid":
if len(splitO) != 2 {
return nil, errors.Wrapf(define.ErrInvalidArg, "gid option must provide a GID")
@@ -48,6 +51,9 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
}
logrus.Debugf("Removing gid= from options and adding WithVolumeGID for GID %d", intGID)
libpodOptions = append(libpodOptions, libpod.WithVolumeGID(intGID))
+ finalVal = append(finalVal, o)
+ // set option "GID": "$gid"
+ volumeOptions["GID"] = splitO[1]
default:
finalVal = append(finalVal, o)
}
diff --git a/test/e2e/volume_create_test.go b/test/e2e/volume_create_test.go
index 8c44e57e4..544532ee0 100644
--- a/test/e2e/volume_create_test.go
+++ b/test/e2e/volume_create_test.go
@@ -82,5 +82,13 @@ var _ = Describe("Podman volume create", func() {
inspectGID.WaitWithDefaultTimeout()
Expect(inspectGID.ExitCode()).To(Equal(0))
Expect(inspectGID.OutputToString()).To(Equal(gid))
+
+ // options should containt `uid=3000,gid=4000:3000:4000`
+ optionFormat := `{{ .Options.o }}:{{ .Options.UID }}:{{ .Options.GID }}`
+ optionStrFormatExpect := fmt.Sprintf(`uid=%s,gid=%s:%s:%s`, uid, gid, uid, gid)
+ inspectOpts := podmanTest.Podman([]string{"volume", "inspect", "--format", optionFormat, volName})
+ inspectOpts.WaitWithDefaultTimeout()
+ Expect(inspectOpts.ExitCode()).To(Equal(0))
+ Expect(inspectOpts.OutputToString()).To(Equal(optionStrFormatExpect))
})
})