diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index 7b1e221c8c..db641c70de 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -144,6 +144,10 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste } config := ctr.Config() + if len(config.InitContainerType) > 0 { + return nil, fmt.Errorf("unsupported container %s: cannot generate systemd units for init containers", ctr.ID()) + } + conmonPidFile := config.ConmonPidFile if conmonPidFile == "" { return nil, errors.New("conmon PID file path is empty, try to recreate the container with --conmon-pidfile flag") diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go index bdc7c34d8f..94cebccbbf 100644 --- a/pkg/systemd/generate/pods.go +++ b/pkg/systemd/generate/pods.go @@ -170,6 +170,7 @@ func PodUnits(pod *libpod.Pod, options entities.GenerateSystemdOptions) (map[str if ctr.ID() == infraID { continue } + ctrInfo, err := generateContainerInfo(ctr, options) if err != nil { return nil, err diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go index b3cc35d1cb..b984a6ed5b 100644 --- a/test/e2e/generate_systemd_test.go +++ b/test/e2e/generate_systemd_test.go @@ -215,6 +215,22 @@ var _ = Describe("Podman generate systemd", func() { Expect(strings.Count(output, "RequiresMountsFor="+podmanTest.RunRoot)).To(Equal(3)) // The podman commands in the unit should not contain the root flags Expect(output).ToNot(ContainSubstring(" --runroot")) + + // Generating pod/container units for an init container is not + // supported (see #18585). + n = podmanTest.Podman([]string{"create", "--pod", "foo", "--init-ctr", "always", "--name", "foo-init", "alpine", "top"}) + n.WaitWithDefaultTimeout() + Expect(n).Should(Exit(0)) + // Fail for the pod + session = podmanTest.Podman([]string{"generate", "systemd", "foo"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(125)) + Expect(session.ErrorToString()).To(ContainSubstring("cannot generate systemd units for init containers")) + // Fail for the init container + session = podmanTest.Podman([]string{"generate", "systemd", "foo-init"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(125)) + Expect(session.ErrorToString()).To(ContainSubstring("cannot generate systemd units for init containers")) }) It("podman generate systemd pod --name --files", func() {