mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
Merge pull request #8793 from zhangguanzhang/vol-op
Fix missing options in volume's display while setting uid and gid
This commit is contained in:
@ -1593,7 +1593,7 @@ func WithVolumeOptions(options map[string]string) VolumeCreateOption {
|
|||||||
volume.config.Options = make(map[string]string)
|
volume.config.Options = make(map[string]string)
|
||||||
for key, value := range options {
|
for key, value := range options {
|
||||||
switch key {
|
switch key {
|
||||||
case "type", "device", "o":
|
case "type", "device", "o", "UID", "GID":
|
||||||
volume.config.Options[key] = value
|
volume.config.Options[key] = value
|
||||||
default:
|
default:
|
||||||
return errors.Wrapf(define.ErrInvalidArg, "unrecognized volume option %q is not supported with local driver", key)
|
return errors.Wrapf(define.ErrInvalidArg, "unrecognized volume option %q is not supported with local driver", key)
|
||||||
|
@ -58,7 +58,7 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption)
|
|||||||
// Validate options
|
// Validate options
|
||||||
for key := range volume.config.Options {
|
for key := range volume.config.Options {
|
||||||
switch key {
|
switch key {
|
||||||
case "device", "o", "type":
|
case "device", "o", "type", "UID", "GID":
|
||||||
// Do nothing, valid keys
|
// Do nothing, valid keys
|
||||||
default:
|
default:
|
||||||
return nil, errors.Wrapf(define.ErrInvalidArg, "invalid mount option %s for driver 'local'", key)
|
return nil, errors.Wrapf(define.ErrInvalidArg, "invalid mount option %s for driver 'local'", key)
|
||||||
|
@ -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)
|
logrus.Debugf("Removing uid= from options and adding WithVolumeUID for UID %d", intUID)
|
||||||
libpodOptions = append(libpodOptions, libpod.WithVolumeUID(intUID))
|
libpodOptions = append(libpodOptions, libpod.WithVolumeUID(intUID))
|
||||||
|
finalVal = append(finalVal, o)
|
||||||
|
// set option "UID": "$uid"
|
||||||
|
volumeOptions["UID"] = splitO[1]
|
||||||
case "gid":
|
case "gid":
|
||||||
if len(splitO) != 2 {
|
if len(splitO) != 2 {
|
||||||
return nil, errors.Wrapf(define.ErrInvalidArg, "gid option must provide a GID")
|
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)
|
logrus.Debugf("Removing gid= from options and adding WithVolumeGID for GID %d", intGID)
|
||||||
libpodOptions = append(libpodOptions, libpod.WithVolumeGID(intGID))
|
libpodOptions = append(libpodOptions, libpod.WithVolumeGID(intGID))
|
||||||
|
finalVal = append(finalVal, o)
|
||||||
|
// set option "GID": "$gid"
|
||||||
|
volumeOptions["GID"] = splitO[1]
|
||||||
default:
|
default:
|
||||||
finalVal = append(finalVal, o)
|
finalVal = append(finalVal, o)
|
||||||
}
|
}
|
||||||
|
@ -82,5 +82,13 @@ var _ = Describe("Podman volume create", func() {
|
|||||||
inspectGID.WaitWithDefaultTimeout()
|
inspectGID.WaitWithDefaultTimeout()
|
||||||
Expect(inspectGID.ExitCode()).To(Equal(0))
|
Expect(inspectGID.ExitCode()).To(Equal(0))
|
||||||
Expect(inspectGID.OutputToString()).To(Equal(gid))
|
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))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user