summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-05-07 15:43:51 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-05-07 17:58:50 -0400
commit2d68dc776d80cc5b71c609b8ddaf2069c97193e7 (patch)
tree2de91bd3d68b3d80d0433a24629b88c83061e50c /cmd/podman
parentab518cdba02b85a32d3c2bce4c0b65dcdea4dfcc (diff)
downloadpodman-2d68dc776d80cc5b71c609b8ddaf2069c97193e7.tar.gz
podman-2d68dc776d80cc5b71c609b8ddaf2069c97193e7.tar.bz2
podman-2d68dc776d80cc5b71c609b8ddaf2069c97193e7.zip
Fix parsing of --network for `podman pod create`
Interpreting CNI networks was a bit broken, and it was causing rootless `podman pod create` to fail. Also, we were missing the `--net` alias for `--network`, so add that. Fixes #6119 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/pods/create.go47
1 files changed, 24 insertions, 23 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 0a2016496..f97fa836a 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -17,6 +17,7 @@ import (
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
var (
@@ -59,6 +60,14 @@ func init() {
flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod")
flags.StringVar(&podIDFile, "pod-id-file", "", "Write the pod ID to the file")
flags.StringVar(&share, "share", createconfig.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
+ flags.SetNormalizeFunc(aliasNetworkFlag)
+}
+
+func aliasNetworkFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
+ if name == "net" {
+ name = "network"
+ }
+ return pflag.NormalizedName(name)
}
func create(cmd *cobra.Command, args []string) error {
@@ -105,29 +114,21 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- netInput, err := cmd.Flags().GetString("network")
- if err != nil {
- return err
- }
- n := specgen.Namespace{}
- switch netInput {
- case "bridge":
- n.NSMode = specgen.Bridge
- case "host":
- n.NSMode = specgen.Host
- case "slip4netns":
- n.NSMode = specgen.Slirp
- default:
- if strings.HasPrefix(netInput, "container:") { // nolint
- split := strings.Split(netInput, ":")
- if len(split) != 2 {
- return errors.Errorf("invalid network paramater: %q", netInput)
- }
- n.NSMode = specgen.FromContainer
- n.Value = split[1]
- } else if strings.HasPrefix(netInput, "ns:") {
- return errors.New("the ns: network option is not supported for pods")
- } else {
+ if cmd.Flag("network").Changed {
+ netInput, err := cmd.Flags().GetString("network")
+ if err != nil {
+ return err
+ }
+ n := specgen.Namespace{}
+ switch netInput {
+ case "bridge":
+ n.NSMode = specgen.Bridge
+ case "host":
+ n.NSMode = specgen.Host
+ case "slirp4netns":
+ n.NSMode = specgen.Slirp
+ default:
+ // Container and NS mode are presently unsupported
n.NSMode = specgen.Bridge
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
}