diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/common/create_opts.go | 1 | ||||
-rw-r--r-- | cmd/podman/common/specgen.go | 2 | ||||
-rw-r--r-- | cmd/podman/containers/create.go | 24 |
3 files changed, 26 insertions, 1 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index 42e0efe5d..61f08b73b 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -61,6 +61,7 @@ type ContainerCLIOpts struct { HTTPProxy bool ImageVolume string Init bool + InitContainerType string InitPath string Interactive bool IPC string diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index 42f515ace..118091855 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -659,6 +659,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string s.PidFile = c.PidFile s.Volatile = c.Rm + // Initcontainers + s.InitContainerType = c.InitContainerType return nil } diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index c63c074f7..895736144 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + "github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/config" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/podman/v3/cmd/podman/common" @@ -49,12 +50,20 @@ var ( ) var ( - cliVals common.ContainerCLIOpts + cliVals common.ContainerCLIOpts + InitContainerType string ) func createFlags(cmd *cobra.Command) { flags := cmd.Flags() + initContainerFlagName := "init-ctr" + flags.StringVar( + &InitContainerType, + initContainerFlagName, "", + "Make this a pod init container.", + ) + flags.SetInterspersed(false) common.DefineCreateFlags(cmd, &cliVals) common.DefineNetFlags(cmd) @@ -65,6 +74,8 @@ func createFlags(cmd *cobra.Command) { _ = flags.MarkHidden("conmon-pidfile") _ = flags.MarkHidden("pidfile") } + + _ = cmd.RegisterFlagCompletionFunc(initContainerFlagName, completion.AutocompleteDefault) } func init() { @@ -89,6 +100,17 @@ func create(cmd *cobra.Command, args []string) error { return err } + // Check if initctr is used with --pod and the value is correct + if initctr := InitContainerType; cmd.Flags().Changed("init-ctr") { + if !cmd.Flags().Changed("pod") { + return errors.New("must specify pod value with init-ctr") + } + if !util.StringInSlice(initctr, []string{"always", "oneshot"}) { + return errors.New("init-ctr value must be 'always' or 'oneshot'") + } + cliVals.InitContainerType = initctr + } + if err := createInit(cmd); err != nil { return err } |