summaryrefslogtreecommitdiff
path: root/pkg/specgen/namespaces.go
diff options
context:
space:
mode:
authorSascha Grunert <sgrunert@redhat.com>2022-07-06 09:48:36 +0200
committerSascha Grunert <sgrunert@redhat.com>2022-07-08 08:54:47 +0200
commita46f798831df06c472b288db7b34de8536a7ea5a (patch)
treec370fb0fc23b461691906e308b179a50e583228b /pkg/specgen/namespaces.go
parent862cc42ddc11ff56b41be128182b748b0843dff3 (diff)
downloadpodman-a46f798831df06c472b288db7b34de8536a7ea5a.tar.gz
podman-a46f798831df06c472b288db7b34de8536a7ea5a.tar.bz2
podman-a46f798831df06c472b288db7b34de8536a7ea5a.zip
pkg: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the deprecated github.com/pkg/errors package. [NO NEW TESTS NEEDED] Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Diffstat (limited to 'pkg/specgen/namespaces.go')
-rw-r--r--pkg/specgen/namespaces.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/pkg/specgen/namespaces.go b/pkg/specgen/namespaces.go
index f1343f6e2..03a2049f6 100644
--- a/pkg/specgen/namespaces.go
+++ b/pkg/specgen/namespaces.go
@@ -1,6 +1,7 @@
package specgen
import (
+ "errors"
"fmt"
"net"
"os"
@@ -14,7 +15,6 @@ import (
"github.com/containers/storage"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
- "github.com/pkg/errors"
)
type NamespaceMode string
@@ -158,18 +158,18 @@ func validateNetNS(n *Namespace) error {
case "", Default, Host, Path, FromContainer, FromPod, Private, NoNetwork, Bridge:
break
default:
- return errors.Errorf("invalid network %q", n.NSMode)
+ return fmt.Errorf("invalid network %q", n.NSMode)
}
// Path and From Container MUST have a string value set
if n.NSMode == Path || n.NSMode == FromContainer {
if len(n.Value) < 1 {
- return errors.Errorf("namespace mode %s requires a value", n.NSMode)
+ return fmt.Errorf("namespace mode %s requires a value", n.NSMode)
}
} else if n.NSMode != Slirp {
// All others except must NOT set a string value
if len(n.Value) > 0 {
- return errors.Errorf("namespace value %s cannot be provided with namespace mode %s", n.Value, n.NSMode)
+ return fmt.Errorf("namespace value %s cannot be provided with namespace mode %s", n.Value, n.NSMode)
}
}
@@ -197,20 +197,20 @@ func (n *Namespace) validate() error {
case "", Default, Host, Path, FromContainer, FromPod, Private:
// Valid, do nothing
case NoNetwork, Bridge, Slirp:
- return errors.Errorf("cannot use network modes with non-network namespace")
+ return errors.New("cannot use network modes with non-network namespace")
default:
- return errors.Errorf("invalid namespace type %s specified", n.NSMode)
+ return fmt.Errorf("invalid namespace type %s specified", n.NSMode)
}
// Path and From Container MUST have a string value set
if n.NSMode == Path || n.NSMode == FromContainer {
if len(n.Value) < 1 {
- return errors.Errorf("namespace mode %s requires a value", n.NSMode)
+ return fmt.Errorf("namespace mode %s requires a value", n.NSMode)
}
} else {
// All others must NOT set a string value
if len(n.Value) > 0 {
- return errors.Errorf("namespace value %s cannot be provided with namespace mode %s", n.Value, n.NSMode)
+ return fmt.Errorf("namespace value %s cannot be provided with namespace mode %s", n.Value, n.NSMode)
}
}
return nil
@@ -231,19 +231,19 @@ func ParseNamespace(ns string) (Namespace, error) {
case strings.HasPrefix(ns, "ns:"):
split := strings.SplitN(ns, ":", 2)
if len(split) != 2 {
- return toReturn, errors.Errorf("must provide a path to a namespace when specifying \"ns:\"")
+ return toReturn, fmt.Errorf("must provide a path to a namespace when specifying \"ns:\"")
}
toReturn.NSMode = Path
toReturn.Value = split[1]
case strings.HasPrefix(ns, "container:"):
split := strings.SplitN(ns, ":", 2)
if len(split) != 2 {
- return toReturn, errors.Errorf("must provide name or ID or a container when specifying \"container:\"")
+ return toReturn, fmt.Errorf("must provide name or ID or a container when specifying \"container:\"")
}
toReturn.NSMode = FromContainer
toReturn.Value = split[1]
default:
- return toReturn, errors.Errorf("unrecognized namespace mode %s passed", ns)
+ return toReturn, fmt.Errorf("unrecognized namespace mode %s passed", ns)
}
return toReturn, nil
@@ -266,7 +266,7 @@ func ParseCgroupNamespace(ns string) (Namespace, error) {
case "private", "":
toReturn.NSMode = Private
default:
- return toReturn, errors.Errorf("unrecognized cgroup namespace mode %s passed", ns)
+ return toReturn, fmt.Errorf("unrecognized cgroup namespace mode %s passed", ns)
}
} else {
toReturn.NSMode = Host
@@ -300,7 +300,7 @@ func ParseUserNamespace(ns string) (Namespace, error) {
case strings.HasPrefix(ns, "auto:"):
split := strings.SplitN(ns, ":", 2)
if len(split) != 2 {
- return toReturn, errors.Errorf("invalid setting for auto: mode")
+ return toReturn, errors.New("invalid setting for auto: mode")
}
toReturn.NSMode = Auto
toReturn.Value = split[1]
@@ -365,14 +365,14 @@ func ParseNetworkFlag(networks []string) (Namespace, map[string]types.PerNetwork
case strings.HasPrefix(ns, "ns:"):
split := strings.SplitN(ns, ":", 2)
if len(split) != 2 {
- return toReturn, nil, nil, errors.Errorf("must provide a path to a namespace when specifying \"ns:\"")
+ return toReturn, nil, nil, errors.New("must provide a path to a namespace when specifying \"ns:\"")
}
toReturn.NSMode = Path
toReturn.Value = split[1]
case strings.HasPrefix(ns, string(FromContainer)+":"):
split := strings.SplitN(ns, ":", 2)
if len(split) != 2 {
- return toReturn, nil, nil, errors.Errorf("must provide name or ID or a container when specifying \"container:\"")
+ return toReturn, nil, nil, errors.New("must provide name or ID or a container when specifying \"container:\"")
}
toReturn.NSMode = FromContainer
toReturn.Value = split[1]
@@ -391,7 +391,7 @@ func ParseNetworkFlag(networks []string) (Namespace, map[string]types.PerNetwork
}
netOpts, err := parseBridgeNetworkOptions(parts[1])
if err != nil {
- return toReturn, nil, nil, errors.Wrapf(err, "invalid option for network %s", parts[0])
+ return toReturn, nil, nil, fmt.Errorf("invalid option for network %s: %w", parts[0], err)
}
podmanNetworks[parts[0]] = netOpts
}
@@ -402,24 +402,24 @@ func ParseNetworkFlag(networks []string) (Namespace, map[string]types.PerNetwork
if len(networks) > 1 {
if !toReturn.IsBridge() {
- return toReturn, nil, nil, errors.Wrapf(define.ErrInvalidArg, "cannot set multiple networks without bridge network mode, selected mode %s", toReturn.NSMode)
+ return toReturn, nil, nil, fmt.Errorf("cannot set multiple networks without bridge network mode, selected mode %s: %w", toReturn.NSMode, define.ErrInvalidArg)
}
for _, network := range networks[1:] {
parts := strings.SplitN(network, ":", 2)
if parts[0] == "" {
- return toReturn, nil, nil, errors.Wrapf(define.ErrInvalidArg, "network name cannot be empty")
+ return toReturn, nil, nil, fmt.Errorf("network name cannot be empty: %w", define.ErrInvalidArg)
}
if cutil.StringInSlice(parts[0], []string{string(Bridge), string(Slirp), string(FromPod), string(NoNetwork),
string(Default), string(Private), string(Path), string(FromContainer), string(Host)}) {
- return toReturn, nil, nil, errors.Wrapf(define.ErrInvalidArg, "can only set extra network names, selected mode %s conflicts with bridge", parts[0])
+ return toReturn, nil, nil, fmt.Errorf("can only set extra network names, selected mode %s conflicts with bridge: %w", parts[0], define.ErrInvalidArg)
}
netOpts := types.PerNetworkOptions{}
if len(parts) > 1 {
var err error
netOpts, err = parseBridgeNetworkOptions(parts[1])
if err != nil {
- return toReturn, nil, nil, errors.Wrapf(err, "invalid option for network %s", parts[0])
+ return toReturn, nil, nil, fmt.Errorf("invalid option for network %s: %w", parts[0], err)
}
}
podmanNetworks[parts[0]] = netOpts
@@ -441,7 +441,7 @@ func parseBridgeNetworkOptions(opts string) (types.PerNetworkOptions, error) {
case "ip", "ip6":
ip := net.ParseIP(split[1])
if ip == nil {
- return netOpts, errors.Errorf("invalid ip address %q", split[1])
+ return netOpts, fmt.Errorf("invalid ip address %q", split[1])
}
netOpts.StaticIPs = append(netOpts.StaticIPs, ip)
@@ -465,7 +465,7 @@ func parseBridgeNetworkOptions(opts string) (types.PerNetworkOptions, error) {
netOpts.InterfaceName = split[1]
default:
- return netOpts, errors.Errorf("unknown bridge network option: %s", split[0])
+ return netOpts, fmt.Errorf("unknown bridge network option: %s", split[0])
}
}
return netOpts, nil
@@ -477,7 +477,7 @@ func SetupUserNS(idmappings *storage.IDMappingOptions, userns Namespace, g *gene
switch userns.NSMode {
case Path:
if _, err := os.Stat(userns.Value); err != nil {
- return user, errors.Wrap(err, "cannot find specified user namespace path")
+ return user, fmt.Errorf("cannot find specified user namespace path: %w", err)
}
if err := g.AddOrReplaceLinuxNamespace(string(spec.UserNamespace), userns.Value); err != nil {
return user, err
@@ -526,7 +526,7 @@ func privateUserNamespace(idmappings *storage.IDMappingOptions, g *generate.Gene
return err
}
if idmappings == nil || (len(idmappings.UIDMap) == 0 && len(idmappings.GIDMap) == 0) {
- return errors.Errorf("must provide at least one UID or GID mapping to configure a user namespace")
+ return errors.New("must provide at least one UID or GID mapping to configure a user namespace")
}
for _, uidmap := range idmappings.UIDMap {
g.AddLinuxUIDMapping(uint32(uidmap.HostID), uint32(uidmap.ContainerID), uint32(uidmap.Size))