summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-05-29 13:20:22 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-06-11 11:01:13 +0200
commit402c68b41d3fd8f354a4fd0ba4d4101920f8cfe6 (patch)
treeae60cd4ffc1e50a88740b888d4d8d6d0bb5e530e
parent144c6bb76d7652f53167d4bc7130cf897f5903a1 (diff)
downloadpodman-402c68b41d3fd8f354a4fd0ba4d4101920f8cfe6.tar.gz
podman-402c68b41d3fd8f354a4fd0ba4d4101920f8cfe6.tar.bz2
podman-402c68b41d3fd8f354a4fd0ba4d4101920f8cfe6.zip
pod create: add `--infra-conmon-pidfile`
Add an `--infra-conmon-pidfile` flag to `podman-pod-create` to write the infra container's conmon process ID to a specified path. Several container sub-commands already support `--conmon-pidfile` which is especially helpful to allow for systemd to access and track the conmon processes. This allows for easily tracking the conmon process of a pod's infra container. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r--cmd/podman/pods/create.go4
-rw-r--r--completions/bash/podman1
-rw-r--r--docs/source/markdown/podman-pod-create.1.md4
-rw-r--r--libpod/options.go12
-rw-r--r--libpod/pod.go1
-rw-r--r--libpod/runtime_pod_infra_linux.go3
-rw-r--r--pkg/domain/entities/pods.go22
-rw-r--r--pkg/specgen/generate/pod_create.go3
-rw-r--r--pkg/specgen/podspecgen.go3
-rw-r--r--test/e2e/pod_start_test.go19
10 files changed, 63 insertions, 9 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 5ed5fa57c..51b7a7d52 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -53,6 +53,7 @@ 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.InfraConmonPidFile, "infra-conmon-pidfile", "", "Path to the file that will receive the POD of the infra container's conmon")
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")
@@ -83,6 +84,9 @@ func create(cmd *cobra.Command, args []string) error {
if !createOptions.Infra {
logrus.Debugf("Not creating an infra container")
+ if cmd.Flag("infra-conmon-pidfile").Changed {
+ return errors.New("cannot set infra-conmon-pid without an infra container")
+ }
if cmd.Flag("infra-command").Changed {
return errors.New("cannot set infra-command without an infra container")
}
diff --git a/completions/bash/podman b/completions/bash/podman
index 0e4b60b14..6dbe645fe 100644
--- a/completions/bash/podman
+++ b/completions/bash/podman
@@ -3098,6 +3098,7 @@ _podman_pod_create() {
--dns-opt
--dns-search
--infra-command
+ --infra-conmon-pidfile
--infra-image
--ip
--label-file
diff --git a/docs/source/markdown/podman-pod-create.1.md b/docs/source/markdown/podman-pod-create.1.md
index 489c9b32e..de6b600f0 100644
--- a/docs/source/markdown/podman-pod-create.1.md
+++ b/docs/source/markdown/podman-pod-create.1.md
@@ -47,6 +47,10 @@ Set a hostname to the pod
Create an infra container and associate it with the pod. An infra container is a lightweight container used to coordinate the shared kernel namespace of a pod. Default: true.
+**--infra-conmon-pidfile**=*file*
+
+Write the pid of the infra container's **conmon** process to a file. As **conmon** runs in a separate process than Podman, this is necessary when using systemd to manage Podman containers and pods.
+
**--infra-command**=*command*
The command that will be run to start the infra container. Default: "/pause".
diff --git a/libpod/options.go b/libpod/options.go
index 75d098815..5a0f60093 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1550,6 +1550,18 @@ func WithPodCreateCommand() PodCreateOption {
}
}
+// WithInfraConmonPidFile sets the path to a custom conmon PID file for the
+// infra container.
+func WithInfraConmonPidFile(path string) PodCreateOption {
+ return func(pod *Pod) error {
+ if pod.valid {
+ return define.ErrPodFinalized
+ }
+ pod.config.InfraContainer.ConmonPidFile = path
+ return nil
+ }
+}
+
// WithPodLabels sets the labels of a pod.
func WithPodLabels(labels map[string]string) PodCreateOption {
return func(pod *Pod) error {
diff --git a/libpod/pod.go b/libpod/pod.go
index 38fe1fd2c..7af78fa07 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -83,6 +83,7 @@ type podState struct {
// InfraContainerConfig is the configuration for the pod's infra container
type InfraContainerConfig struct {
+ ConmonPidFile string `json:"conmonPidFile"`
HasInfraContainer bool `json:"makeInfraContainer"`
HostNetwork bool `json:"infraHostNetwork,omitempty"`
PortBindings []ocicni.PortMapping `json:"infraPortBindings"`
diff --git a/libpod/runtime_pod_infra_linux.go b/libpod/runtime_pod_infra_linux.go
index 06a7b3936..a0dee3aa1 100644
--- a/libpod/runtime_pod_infra_linux.go
+++ b/libpod/runtime_pod_infra_linux.go
@@ -130,6 +130,9 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
options = append(options, WithRootFSFromImage(imgID, imgName, rawImageName))
options = append(options, WithName(containerName))
options = append(options, withIsInfra())
+ if len(p.config.InfraContainer.ConmonPidFile) > 0 {
+ options = append(options, WithConmonPidFile(p.config.InfraContainer.ConmonPidFile))
+ }
return r.newContainer(ctx, g.Config, options...)
}
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go
index a85333c75..fc76ddd41 100644
--- a/pkg/domain/entities/pods.go
+++ b/pkg/domain/entities/pods.go
@@ -103,15 +103,16 @@ type PodRmReport struct {
}
type PodCreateOptions struct {
- CGroupParent string
- Hostname string
- Infra bool
- InfraImage string
- InfraCommand string
- Labels map[string]string
- Name string
- Net *NetOptions
- Share []string
+ CGroupParent string
+ Hostname string
+ Infra bool
+ InfraImage string
+ InfraCommand string
+ InfraConmonPidFile string
+ Labels map[string]string
+ Name string
+ Net *NetOptions
+ Share []string
}
type PodCreateReport struct {
@@ -127,6 +128,9 @@ func (p PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) {
if len(p.InfraCommand) > 0 {
s.InfraCommand = strings.Split(p.InfraCommand, " ")
}
+ if len(p.InfraConmonPidFile) > 0 {
+ s.InfraConmonPidFile = p.InfraConmonPidFile
+ }
s.InfraImage = p.InfraImage
s.SharedNamespaces = p.Share
diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go
index 51b7835b2..5ccb1ba80 100644
--- a/pkg/specgen/generate/pod_create.go
+++ b/pkg/specgen/generate/pod_create.go
@@ -94,5 +94,8 @@ func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, er
}
options = append(options, libpod.WithPodCgroups())
options = append(options, libpod.WithPodCreateCommand())
+ if len(p.InfraConmonPidFile) > 0 {
+ options = append(options, libpod.WithInfraConmonPidFile(p.InfraConmonPidFile))
+ }
return options, nil
}
diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go
index 11976233a..600d27004 100644
--- a/pkg/specgen/podspecgen.go
+++ b/pkg/specgen/podspecgen.go
@@ -25,6 +25,9 @@ type PodBasicConfig struct {
// InfraCommand and InfraImages in this struct.
// Optional.
NoInfra bool `json:"no_infra,omitempty"`
+ // InfraConmonPidFile is a custom path to store the infra container's
+ // conmon PID.
+ InfraConmonPidFile string `json:"infra_conmon_pid_file,omitempty"`
// InfraCommand sets the command that will be used to start the infra
// container.
// If not set, the default set in the Libpod configuration file will be
diff --git a/test/e2e/pod_start_test.go b/test/e2e/pod_start_test.go
index 4502a76ed..99285d1e1 100644
--- a/test/e2e/pod_start_test.go
+++ b/test/e2e/pod_start_test.go
@@ -193,4 +193,23 @@ var _ = Describe("Podman pod start", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(20)) // 10*(infra+top)
})
+
+ It("podman pod create --infra-conmon-pod create + start", func() {
+ tmpDir, err := ioutil.TempDir("", "")
+ Expect(err).To(BeNil())
+ tmpFile := tmpDir + "podID"
+ defer os.RemoveAll(tmpDir)
+
+ podName := "rudolph"
+ // Create a pod with --infra-conmon-pid.
+ session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--infra-conmon-pidfile", tmpFile})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "start", podName})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) // infra
+ })
+
})