mirror of
https://github.com/containers/podman.git
synced 2025-06-23 10:38:20 +08:00
Merge pull request #18602 from vrothberg/fix-18585
generate systemd: error on init containers
This commit is contained in:
@ -144,6 +144,10 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste
|
|||||||
}
|
}
|
||||||
|
|
||||||
config := ctr.Config()
|
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
|
conmonPidFile := config.ConmonPidFile
|
||||||
if conmonPidFile == "" {
|
if conmonPidFile == "" {
|
||||||
return nil, errors.New("conmon PID file path is empty, try to recreate the container with --conmon-pidfile flag")
|
return nil, errors.New("conmon PID file path is empty, try to recreate the container with --conmon-pidfile flag")
|
||||||
|
@ -170,6 +170,7 @@ func PodUnits(pod *libpod.Pod, options entities.GenerateSystemdOptions) (map[str
|
|||||||
if ctr.ID() == infraID {
|
if ctr.ID() == infraID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrInfo, err := generateContainerInfo(ctr, options)
|
ctrInfo, err := generateContainerInfo(ctr, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -215,6 +215,22 @@ var _ = Describe("Podman generate systemd", func() {
|
|||||||
Expect(strings.Count(output, "RequiresMountsFor="+podmanTest.RunRoot)).To(Equal(3))
|
Expect(strings.Count(output, "RequiresMountsFor="+podmanTest.RunRoot)).To(Equal(3))
|
||||||
// The podman commands in the unit should not contain the root flags
|
// The podman commands in the unit should not contain the root flags
|
||||||
Expect(output).ToNot(ContainSubstring(" --runroot"))
|
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() {
|
It("podman generate systemd pod --name --files", func() {
|
||||||
|
Reference in New Issue
Block a user