summaryrefslogtreecommitdiff
path: root/cmd/podman/pods/create.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pods/create.go')
-rw-r--r--cmd/podman/pods/create.go45
1 files changed, 22 insertions, 23 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 63dab4707..85b96d37b 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -9,7 +9,7 @@ import (
"github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry"
- "github.com/containers/libpod/libpod/define"
+ "github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/errorhandling"
"github.com/containers/libpod/pkg/specgen"
@@ -25,7 +25,7 @@ var (
createCommand = &cobra.Command{
Use: "create",
- Args: cobra.NoArgs,
+ Args: validate.NoArgs,
Short: "Create a new empty pod",
Long: podCreateDescription,
RunE: create,
@@ -50,8 +50,8 @@ func init() {
flags.AddFlagSet(common.GetNetFlags())
flags.StringVar(&createOptions.CGroupParent, "cgroup-parent", "", "Set parent cgroup for the pod")
flags.BoolVar(&createOptions.Infra, "infra", true, "Create an infra container associated with the pod to share namespaces with")
- flags.StringVar(&createOptions.InfraImage, "infra-image", define.DefaultInfraImage, "The image of the infra container to associate with the pod")
- flags.StringVar(&createOptions.InfraCommand, "infra-command", define.DefaultInfraCommand, "The command to run on the infra container when the pod is started")
+ flags.StringVar(&createOptions.InfraImage, "infra-image", containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
+ flags.StringVar(&createOptions.InfraCommand, "infra-command", containerConfig.Engine.InfraCommand, "The command to run on the infra container when the pod is started")
flags.StringSliceVar(&labelFile, "label-file", []string{}, "Read in a line delimited file of labels")
flags.StringSliceVarP(&labels, "label", "l", []string{}, "Set metadata on pod (default [])")
flags.StringVarP(&createOptions.Name, "name", "n", "", "Assign a name to the pod")
@@ -70,10 +70,24 @@ func create(cmd *cobra.Command, args []string) error {
return errors.Wrapf(err, "unable to process labels")
}
- if !createOptions.Infra && cmd.Flag("share").Changed && share != "none" && share != "" {
- return errors.Errorf("You cannot share kernel namespaces on the pod level without an infra container")
+ if !createOptions.Infra {
+ if cmd.Flag("infra-command").Changed {
+ return errors.New("cannot set infra-command without an infra container")
+ }
+ createOptions.InfraCommand = ""
+ if cmd.Flag("infra-image").Changed {
+ return errors.New("cannot set infra-image without an infra container")
+ }
+ createOptions.InfraImage = ""
+
+ if cmd.Flag("share").Changed && share != "none" && share != "" {
+ return fmt.Errorf("cannot set share(%s) namespaces without an infra container", cmd.Flag("share").Value)
+ }
+ createOptions.Share = nil
+ } else {
+ createOptions.Share = strings.Split(share, ",")
}
- createOptions.Share = strings.Split(share, ",")
+
if cmd.Flag("pod-id-file").Changed {
podIdFile, err = util.OpenExclusiveFile(podIDFile)
if err != nil && os.IsExist(err) {
@@ -103,7 +117,7 @@ func create(cmd *cobra.Command, args []string) error {
case "slip4netns":
n.NSMode = specgen.Slirp
default:
- if strings.HasPrefix(netInput, "container:") { //nolint
+ if strings.HasPrefix(netInput, "container:") { // nolint
split := strings.Split(netInput, ":")
if len(split) != 2 {
return errors.Errorf("invalid network paramater: %q", netInput)
@@ -123,21 +137,6 @@ func create(cmd *cobra.Command, args []string) error {
}
}
- if !createOptions.Infra {
- if cmd.Flag("infra-command").Changed {
- return errors.New("cannot set infra-command without an infra container")
- }
- createOptions.InfraCommand = ""
- if cmd.Flag("infra-image").Changed {
- return errors.New("cannot set infra-image without an infra container")
- }
- createOptions.InfraImage = ""
- if cmd.Flag("share").Changed {
- return errors.New("cannot set share namespaces without an infra container")
- }
- createOptions.Share = nil
- }
-
response, err := registry.ContainerEngine().PodCreate(context.Background(), createOptions)
if err != nil {
return err