Skip to content

Commit

Permalink
Fix missing options in volumes display while setting uid and gid
Browse files Browse the repository at this point in the history
```
$ 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 <[email protected]>
  • Loading branch information
zhangguanzhang committed Dec 23, 2020
1 parent 5c6b5ef commit 28138da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime_volume_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/domain/infra/abi/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/volume_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

0 comments on commit 28138da

Please sign in to comment.