mirror of https://github.com/containers/podman.git
Merge pull request #6124 from mheon/fix_rootless_podcreate
Fix parsing of --network for `podman pod create`
This commit is contained in:
commit
d3826d6eb3
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -59,6 +60,14 @@ func init() {
|
||||||
flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod")
|
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(&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.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 {
|
func create(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -105,29 +114,21 @@ func create(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
netInput, err := cmd.Flags().GetString("network")
|
if cmd.Flag("network").Changed {
|
||||||
if err != nil {
|
netInput, err := cmd.Flags().GetString("network")
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
n := specgen.Namespace{}
|
}
|
||||||
switch netInput {
|
n := specgen.Namespace{}
|
||||||
case "bridge":
|
switch netInput {
|
||||||
n.NSMode = specgen.Bridge
|
case "bridge":
|
||||||
case "host":
|
n.NSMode = specgen.Bridge
|
||||||
n.NSMode = specgen.Host
|
case "host":
|
||||||
case "slip4netns":
|
n.NSMode = specgen.Host
|
||||||
n.NSMode = specgen.Slirp
|
case "slirp4netns":
|
||||||
default:
|
n.NSMode = specgen.Slirp
|
||||||
if strings.HasPrefix(netInput, "container:") { // nolint
|
default:
|
||||||
split := strings.Split(netInput, ":")
|
// Container and NS mode are presently unsupported
|
||||||
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 {
|
|
||||||
n.NSMode = specgen.Bridge
|
n.NSMode = specgen.Bridge
|
||||||
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
|
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (p *PodSpecGenerator) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodNetworkConfig
|
// PodNetworkConfig
|
||||||
if err := p.NetNS.validate(); err != nil {
|
if err := validateNetNS(&p.NetNS); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if p.NoInfra {
|
if p.NoInfra {
|
||||||
|
@ -85,10 +85,6 @@ func (p *PodSpecGenerator) Validate() error {
|
||||||
return exclusivePodOptions("NoManageHosts", "HostAdd")
|
return exclusivePodOptions("NoManageHosts", "HostAdd")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.NetNS.validate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set Defaults
|
// Set Defaults
|
||||||
if p.NetNS.Value == "" {
|
if p.NetNS.Value == "" {
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ type PodNetworkConfig struct {
|
||||||
// namespace. This network will, by default, be shared with all
|
// namespace. This network will, by default, be shared with all
|
||||||
// containers in the pod.
|
// containers in the pod.
|
||||||
// Cannot be set to FromContainer and FromPod.
|
// Cannot be set to FromContainer and FromPod.
|
||||||
// Setting this to anything except "" conflicts with NoInfra=true.
|
// Setting this to anything except default conflicts with NoInfra=true.
|
||||||
// Defaults to Bridge as root and Slirp as rootless.
|
// Defaults to Bridge as root and Slirp as rootless.
|
||||||
// Mandatory.
|
// Mandatory.
|
||||||
NetNS Namespace `json:"netns,omitempty"`
|
NetNS Namespace `json:"netns,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue