Merge pull request #18602 from vrothberg/fix-18585

generate systemd: error on init containers
This commit is contained in:
OpenShift Merge Robot
2023-05-17 11:18:21 -04:00
committed by GitHub
3 changed files with 21 additions and 0 deletions

View File

@ -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")

View File

@ -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

View File

@ -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() {