mirror of
https://github.com/containers/podman.git
synced 2026-03-27 19:13:49 -04:00
The new golangci-lint version 1.60.1 has problems with typecheck when linting remote files. We have certain pakcages that should never be inlcuded in remote but the typecheck tries to compile all of them but this never works and it seems to ignore the exclude files we gave it. To fix this the proper way is to mark all packages we only use locally with !remote tags. This is a bit ugly but more correct. I also moved the DecodeChanges() code around as it is called from the client so the handles package which should only be remote doesn't really fit anyway. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
114 lines
3.9 KiB
Go
114 lines
3.9 KiB
Go
//go:build !remote
|
|
|
|
package parse
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/containers/podman/v5/libpod"
|
|
"github.com/containers/podman/v5/libpod/define"
|
|
"github.com/docker/go-units"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Handle volume options from CLI.
|
|
// Parse "o" option to find UID, GID, Size.
|
|
func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) {
|
|
libpodOptions := []libpod.VolumeCreateOption{}
|
|
volumeOptions := make(map[string]string)
|
|
|
|
for key, value := range opts {
|
|
switch key {
|
|
case "o":
|
|
// o has special handling to parse out UID, GID.
|
|
// These are separate Libpod options.
|
|
splitVal := strings.Split(value, ",")
|
|
finalVal := []string{}
|
|
for _, o := range splitVal {
|
|
// Options will be formatted as either "opt" or
|
|
// "opt=value"
|
|
opt, val, hasVal := strings.Cut(o, "=")
|
|
switch strings.ToLower(opt) {
|
|
case "size":
|
|
size, err := units.FromHumanSize(val)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot convert size %s to integer: %w", val, err)
|
|
}
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeSize(uint64(size)))
|
|
finalVal = append(finalVal, o)
|
|
// set option "SIZE": "$size"
|
|
volumeOptions["SIZE"] = val
|
|
case "inodes":
|
|
inodes, err := strconv.ParseUint(val, 10, 64)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot convert inodes %s to integer: %w", val, err)
|
|
}
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeInodes(inodes))
|
|
finalVal = append(finalVal, o)
|
|
// set option "INODES": "$size"
|
|
volumeOptions["INODES"] = val
|
|
case "uid":
|
|
if !hasVal {
|
|
return nil, fmt.Errorf("uid option must provide a UID: %w", define.ErrInvalidArg)
|
|
}
|
|
intUID, err := strconv.Atoi(val)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot convert UID %s to integer: %w", val, err)
|
|
}
|
|
logrus.Debugf("Removing uid= from options and adding WithVolumeUID for UID %d", intUID)
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeUID(intUID), libpod.WithVolumeNoChown())
|
|
finalVal = append(finalVal, o)
|
|
// set option "UID": "$uid"
|
|
volumeOptions["UID"] = val
|
|
case "gid":
|
|
if !hasVal {
|
|
return nil, fmt.Errorf("gid option must provide a GID: %w", define.ErrInvalidArg)
|
|
}
|
|
intGID, err := strconv.Atoi(val)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot convert GID %s to integer: %w", val, err)
|
|
}
|
|
logrus.Debugf("Removing gid= from options and adding WithVolumeGID for GID %d", intGID)
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeGID(intGID), libpod.WithVolumeNoChown())
|
|
finalVal = append(finalVal, o)
|
|
// set option "GID": "$gid"
|
|
volumeOptions["GID"] = val
|
|
case "noquota":
|
|
logrus.Debugf("Removing noquota from options and adding WithVolumeDisableQuota")
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeDisableQuota())
|
|
// set option "NOQUOTA": "true"
|
|
volumeOptions["NOQUOTA"] = "true"
|
|
case "timeout":
|
|
if !hasVal {
|
|
return nil, fmt.Errorf("timeout option must provide a valid timeout in seconds: %w", define.ErrInvalidArg)
|
|
}
|
|
intTimeout, err := strconv.Atoi(val)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot convert Timeout %s to an integer: %w", val, err)
|
|
}
|
|
if intTimeout < 0 {
|
|
return nil, fmt.Errorf("volume timeout cannot be negative (got %d)", intTimeout)
|
|
}
|
|
logrus.Debugf("Removing timeout from options and adding WithTimeout for Timeout %d", intTimeout)
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeDriverTimeout(uint(intTimeout)))
|
|
default:
|
|
finalVal = append(finalVal, o)
|
|
}
|
|
}
|
|
if len(finalVal) > 0 {
|
|
volumeOptions[key] = strings.Join(finalVal, ",")
|
|
}
|
|
default:
|
|
volumeOptions[key] = value
|
|
}
|
|
}
|
|
|
|
if len(volumeOptions) > 0 {
|
|
libpodOptions = append(libpodOptions, libpod.WithVolumeOptions(volumeOptions))
|
|
}
|
|
|
|
return libpodOptions, nil
|
|
}
|