mirror of
https://github.com/containers/podman.git
synced 2025-06-23 18:59:30 +08:00
Merge pull request #11219 from baude/oneshottoonce
rename oneshot initcontainers to once
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"github.com/containers/podman/v3/cmd/podman/common"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/utils"
|
"github.com/containers/podman/v3/cmd/podman/utils"
|
||||||
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v3/pkg/specgen"
|
"github.com/containers/podman/v3/pkg/specgen"
|
||||||
"github.com/containers/podman/v3/pkg/util"
|
"github.com/containers/podman/v3/pkg/util"
|
||||||
@ -105,8 +106,8 @@ func create(cmd *cobra.Command, args []string) error {
|
|||||||
if !cmd.Flags().Changed("pod") {
|
if !cmd.Flags().Changed("pod") {
|
||||||
return errors.New("must specify pod value with init-ctr")
|
return errors.New("must specify pod value with init-ctr")
|
||||||
}
|
}
|
||||||
if !util.StringInSlice(initctr, []string{"always", "oneshot"}) {
|
if !util.StringInSlice(initctr, []string{define.AlwaysInitContainer, define.OneShotInitContainer}) {
|
||||||
return errors.New("init-ctr value must be 'always' or 'oneshot'")
|
return errors.Errorf("init-ctr value must be '%s' or '%s'", define.AlwaysInitContainer, define.OneShotInitContainer)
|
||||||
}
|
}
|
||||||
cliVals.InitContainerType = initctr
|
cliVals.InitContainerType = initctr
|
||||||
}
|
}
|
||||||
|
@ -453,8 +453,8 @@ When using pods, create an init style container, which is run after the infra co
|
|||||||
but before regular pod containers are started. Init containers are useful for running
|
but before regular pod containers are started. Init containers are useful for running
|
||||||
setup operations for the pod's applications.
|
setup operations for the pod's applications.
|
||||||
|
|
||||||
Valid values for `init-ctr` type are *always* or *oneshot*. The *always* value
|
Valid values for `init-ctr` type are *always* or *once*. The *always* value
|
||||||
means the container will run with each and every `pod start`, whereas the *oneshot*
|
means the container will run with each and every `pod start`, whereas the *once*
|
||||||
value means the container will only run once when the pod is started and then the container is removed.
|
value means the container will only run once when the pod is started and then the container is removed.
|
||||||
|
|
||||||
Init containers are only run on pod `start`. Restarting a pod will not execute any init
|
Init containers are only run on pod `start`. Restarting a pod will not execute any init
|
||||||
|
@ -376,6 +376,6 @@ type ContainerMiscConfig struct {
|
|||||||
// EnvSecrets are secrets that are set as environment variables
|
// EnvSecrets are secrets that are set as environment variables
|
||||||
EnvSecrets map[string]*secrets.Secret `json:"secret_env,omitempty"`
|
EnvSecrets map[string]*secrets.Secret `json:"secret_env,omitempty"`
|
||||||
// InitContainerType specifies if the container is an initcontainer
|
// InitContainerType specifies if the container is an initcontainer
|
||||||
// and if so, what type: always or oneshot are possible non-nil entries
|
// and if so, what type: always or once are possible non-nil entries
|
||||||
InitContainerType string `json:"init_container_type,omitempty"`
|
InitContainerType string `json:"init_container_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -34,5 +34,5 @@ const (
|
|||||||
AlwaysInitContainer = "always"
|
AlwaysInitContainer = "always"
|
||||||
// OneShotInitContainer is a container that only runs as init once
|
// OneShotInitContainer is a container that only runs as init once
|
||||||
// and is then deleted.
|
// and is then deleted.
|
||||||
OneShotInitContainer = "oneshot"
|
OneShotInitContainer = "once"
|
||||||
)
|
)
|
||||||
|
@ -32,14 +32,14 @@ func (p *Pod) startInitContainers(ctx context.Context) error {
|
|||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
return errors.Errorf("init container %s exited with code %d", initCon.ID(), rc)
|
return errors.Errorf("init container %s exited with code %d", initCon.ID(), rc)
|
||||||
}
|
}
|
||||||
// If the container is an oneshot init container, we need to remove it
|
// If the container is a once init container, we need to remove it
|
||||||
// after it runs
|
// after it runs
|
||||||
if initCon.Config().InitContainerType == define.OneShotInitContainer {
|
if initCon.Config().InitContainerType == define.OneShotInitContainer {
|
||||||
icLock := initCon.lock
|
icLock := initCon.lock
|
||||||
icLock.Lock()
|
icLock.Lock()
|
||||||
if err := p.runtime.removeContainer(ctx, initCon, false, false, true); err != nil {
|
if err := p.runtime.removeContainer(ctx, initCon, false, false, true); err != nil {
|
||||||
icLock.Unlock()
|
icLock.Unlock()
|
||||||
return errors.Wrapf(err, "failed to remove oneshot init container %s", initCon.ID())
|
return errors.Wrapf(err, "failed to remove once init container %s", initCon.ID())
|
||||||
}
|
}
|
||||||
// Removing a container this way requires an explicit call to clean up the db
|
// Removing a container this way requires an explicit call to clean up the db
|
||||||
if err := p.runtime.state.RemoveContainerFromPod(p, initCon); err != nil {
|
if err := p.runtime.state.RemoveContainerFromPod(p, initCon); err != nil {
|
||||||
|
@ -184,7 +184,7 @@ type ContainerBasicConfig struct {
|
|||||||
// Optional.
|
// Optional.
|
||||||
EnvSecrets map[string]string `json:"secret_env,omitempty"`
|
EnvSecrets map[string]string `json:"secret_env,omitempty"`
|
||||||
// InitContainerType describes if this container is an init container
|
// InitContainerType describes if this container is an init container
|
||||||
// and if so, what type: always or oneshot
|
// and if so, what type: always or once
|
||||||
InitContainerType string `json:"init_container_type"`
|
InitContainerType string `json:"init_container_type"`
|
||||||
// Personality allows users to configure different execution domains.
|
// Personality allows users to configure different execution domains.
|
||||||
// Execution domains tell Linux how to map signal numbers into signal actions.
|
// Execution domains tell Linux how to map signal numbers into signal actions.
|
||||||
|
@ -98,10 +98,10 @@ var _ = Describe("Podman init containers", func() {
|
|||||||
Expect(checkLog.OutputToString()).To(Equal(content))
|
Expect(checkLog.OutputToString()).To(Equal(content))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman make sure oneshot container is removed", func() {
|
It("podman make sure once container is removed", func() {
|
||||||
filename := filepath.Join("/dev/shm", RandomString(12))
|
filename := filepath.Join("/dev/shm", RandomString(12))
|
||||||
content := RandomString(16)
|
content := RandomString(16)
|
||||||
session := podmanTest.Podman([]string{"create", "--init-ctr", "oneshot", "--pod", "new:foobar", ALPINE, "bin/sh", "-c", fmt.Sprintf("echo %s > %s", content, filename)})
|
session := podmanTest.Podman([]string{"create", "--init-ctr", "once", "--pod", "new:foobar", ALPINE, "bin/sh", "-c", fmt.Sprintf("echo %s > %s", content, filename)})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
initContainerID := session.OutputToString()
|
initContainerID := session.OutputToString()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
Reference in New Issue
Block a user