diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2021-08-05 13:52:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 13:52:15 +0000 |
commit | 1f0a24437d71f8fe2b2233a428202afcfe513666 (patch) | |
tree | e17f57dce6bf61d38a74fc6b8f011bffbb4082fa /cmd/podman | |
parent | 117583c293713f2baa920c4035e820ad59fe6622 (diff) | |
parent | 3c3fa6fac4d0f8e89181ea2d4e1fe0318d24b6f4 (diff) | |
download | podman-1f0a24437d71f8fe2b2233a428202afcfe513666.tar.gz podman-1f0a24437d71f8fe2b2233a428202afcfe513666.tar.bz2 podman-1f0a24437d71f8fe2b2233a428202afcfe513666.zip |
Merge pull request #11011 from baude/initcontainers
implement init containers in podman
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 } |