diff options
author | Brent Baude <bbaude@redhat.com> | 2021-07-14 16:03:55 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2021-08-04 14:14:36 -0500 |
commit | 3c3fa6fac4d0f8e89181ea2d4e1fe0318d24b6f4 (patch) | |
tree | f087d0a772797a9028df514d8d0369835724b3a2 /cmd/podman | |
parent | e93661f5e765d84893e2ad5a488682c0a67412d0 (diff) | |
download | podman-3c3fa6fac4d0f8e89181ea2d4e1fe0318d24b6f4.tar.gz podman-3c3fa6fac4d0f8e89181ea2d4e1fe0318d24b6f4.tar.bz2 podman-3c3fa6fac4d0f8e89181ea2d4e1fe0318d24b6f4.zip |
implement init containers in podman
this is the first pass at implementing init containers for podman pods.
init containersare made popular by k8s as a way to run setup for pods
before the pods standard containers run.
unlike k8s, we support two styles of init containers: always and
oneshot. always means the container stays in the pod and starts
whenever a pod is started. this does not apply to pods restarting.
oneshot means the container runs onetime when the pod starts and then is
removed.
Signed-off-by: Brent Baude <bbaude@redhat.com>
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 } |