mirror of
https://github.com/containers/podman.git
synced 2025-08-15 20:00:26 +08:00
Merge pull request #6144 from mheon/fix_pod_create_noinfra
Fix `podman pod create --infra=false`
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/containers/libpod/pkg/specgen"
|
"github.com/containers/libpod/pkg/specgen"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
@ -81,6 +82,7 @@ func create(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !createOptions.Infra {
|
if !createOptions.Infra {
|
||||||
|
logrus.Debugf("Not creating an infra container")
|
||||||
if cmd.Flag("infra-command").Changed {
|
if cmd.Flag("infra-command").Changed {
|
||||||
return errors.New("cannot set infra-command without an infra container")
|
return errors.New("cannot set infra-command without an infra container")
|
||||||
}
|
}
|
||||||
@ -114,6 +116,7 @@ func create(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
createOptions.Net.Network = specgen.Namespace{}
|
||||||
if cmd.Flag("network").Changed {
|
if cmd.Flag("network").Changed {
|
||||||
netInput, err := cmd.Flags().GetString("network")
|
netInput, err := cmd.Flags().GetString("network")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -132,6 +135,7 @@ func create(cmd *cobra.Command, args []string) error {
|
|||||||
n.NSMode = specgen.Bridge
|
n.NSMode = specgen.Bridge
|
||||||
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
|
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
|
||||||
}
|
}
|
||||||
|
createOptions.Net.Network = n
|
||||||
}
|
}
|
||||||
if len(createOptions.Net.PublishPorts) > 0 {
|
if len(createOptions.Net.PublishPorts) > 0 {
|
||||||
if !createOptions.Infra {
|
if !createOptions.Infra {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/specgen"
|
"github.com/containers/libpod/pkg/specgen"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,15 +69,17 @@ func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, er
|
|||||||
if p.NoManageResolvConf {
|
if p.NoManageResolvConf {
|
||||||
options = append(options, libpod.WithPodUseImageResolvConf())
|
options = append(options, libpod.WithPodUseImageResolvConf())
|
||||||
}
|
}
|
||||||
|
if len(p.CNINetworks) > 0 {
|
||||||
|
options = append(options, libpod.WithPodNetworks(p.CNINetworks))
|
||||||
|
}
|
||||||
switch p.NetNS.NSMode {
|
switch p.NetNS.NSMode {
|
||||||
case specgen.Bridge:
|
case specgen.Bridge, specgen.Default, "":
|
||||||
logrus.Debugf("Pod using default network mode")
|
logrus.Debugf("Pod using default network mode")
|
||||||
case specgen.Host:
|
case specgen.Host:
|
||||||
logrus.Debugf("Pod will use host networking")
|
logrus.Debugf("Pod will use host networking")
|
||||||
options = append(options, libpod.WithPodHostNetwork())
|
options = append(options, libpod.WithPodHostNetwork())
|
||||||
default:
|
default:
|
||||||
logrus.Debugf("Pod joining CNI networks: %v", p.CNINetworks)
|
return nil, errors.Errorf("pods presently do not support network mode %s", p.NetNS.NSMode)
|
||||||
options = append(options, libpod.WithPodNetworks(p.CNINetworks))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.NoManageHosts {
|
if p.NoManageHosts {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package specgen
|
package specgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -37,8 +36,8 @@ func (p *PodSpecGenerator) Validate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if p.NoInfra {
|
if p.NoInfra {
|
||||||
if p.NetNS.NSMode == NoNetwork {
|
if p.NetNS.NSMode != Default && p.NetNS.NSMode != "" {
|
||||||
return errors.New("NoInfra and a none network cannot be used toegther")
|
return errors.New("NoInfra and network modes cannot be used toegther")
|
||||||
}
|
}
|
||||||
if p.StaticIP != nil {
|
if p.StaticIP != nil {
|
||||||
return exclusivePodOptions("NoInfra", "StaticIP")
|
return exclusivePodOptions("NoInfra", "StaticIP")
|
||||||
@ -86,13 +85,6 @@ func (p *PodSpecGenerator) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set Defaults
|
// Set Defaults
|
||||||
if p.NetNS.Value == "" {
|
|
||||||
if rootless.IsRootless() {
|
|
||||||
p.NetNS.NSMode = Slirp
|
|
||||||
} else {
|
|
||||||
p.NetNS.NSMode = Bridge
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(p.InfraImage) < 1 {
|
if len(p.InfraImage) < 1 {
|
||||||
p.InfraImage = containerConfig.Engine.InfraImage
|
p.InfraImage = containerConfig.Engine.InfraImage
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user