Merge pull request #25681 from Honny1/fix-container-clone-with-hc

Fix container clone with configured Healthcheck
This commit is contained in:
openshift-merge-bot[bot]
2025-03-26 11:38:14 +00:00
committed by GitHub
3 changed files with 38 additions and 0 deletions

View File

@ -1733,6 +1733,11 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
} }
} }
ctrCloneOpts.CreateOpts.HealthOnFailure = spec.HealthCheckOnFailureAction.String()
ctrCloneOpts.CreateOpts.HealthLogDestination = spec.HealthLogDestination
ctrCloneOpts.CreateOpts.HealthMaxLogCount = spec.HealthMaxLogCount
ctrCloneOpts.CreateOpts.HealthMaxLogSize = spec.HealthMaxLogSize
err = specgenutil.FillOutSpecGen(spec, &ctrCloneOpts.CreateOpts, []string{}) err = specgenutil.FillOutSpecGen(spec, &ctrCloneOpts.CreateOpts, []string{})
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -462,6 +462,10 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, containerID
specg.HealthMaxLogSize = define.DefaultHealthMaxLogSize specg.HealthMaxLogSize = define.DefaultHealthMaxLogSize
} }
specg.HealthConfig = conf.HealthCheckConfig
specg.StartupHealthConfig = conf.StartupHealthCheckConfig
specg.HealthCheckOnFailureAction = conf.HealthCheckOnFailureAction
specg.IDMappings = &conf.IDMappings specg.IDMappings = &conf.IDMappings
specg.ContainerCreateCommand = conf.CreateCommand specg.ContainerCreateCommand = conf.CreateCommand
if len(specg.Rootfs) == 0 { if len(specg.Rootfs) == 0 {

View File

@ -304,4 +304,33 @@ var _ = Describe("Podman container clone", func() {
Expect(session.OutputToString()).Should(ContainSubstring("12=3")) Expect(session.OutputToString()).Should(ContainSubstring("12=3"))
}) })
It("podman container clone container with healthcheck", func() {
podmanTest.PodmanExitCleanly(
"run", "-d", "--rm",
"--health-cmd", "true", "--health-start-period", "10s", "--health-interval", "10s", "--health-timeout", "10s", "--health-retries", "2",
"--health-startup-cmd", "true", "--health-startup-interval", "10s", "--health-startup-timeout", "10s", "--health-startup-retries", "2", "--health-startup-success", "1",
"--health-on-failure", "stop", "--health-max-log-count", "1", "--health-max-log-size", "1", "--health-log-destination", podmanTest.TempDir,
"--name", "parent", ALPINE, "sleep", "200",
)
podmanTest.PodmanExitCleanly("healthcheck", "run", "parent")
podmanTest.PodmanExitCleanly("container", "clone", "--run", "parent", "clone", ALPINE)
podmanTest.PodmanExitCleanly("healthcheck", "run", "clone")
parentInspect := podmanTest.PodmanExitCleanly("inspect", "parent")
parentData := parentInspect.InspectContainerToJSON()[0]
cloneInspect := podmanTest.PodmanExitCleanly("inspect", "clone")
cloneData := cloneInspect.InspectContainerToJSON()[0]
Expect(parentData.Config.HealthcheckOnFailureAction).To(Equal(cloneData.Config.HealthcheckOnFailureAction))
Expect(*parentData.Config.Healthcheck).To(Equal(*cloneData.Config.Healthcheck))
Expect(*parentData.Config.StartupHealthCheck).To(Equal(*cloneData.Config.StartupHealthCheck))
Expect(parentData.Config.HealthcheckOnFailureAction).To(Equal(cloneData.Config.HealthcheckOnFailureAction))
Expect(parentData.Config.HealthLogDestination).To(Equal(cloneData.Config.HealthLogDestination))
Expect(parentData.Config.HealthMaxLogCount).To(Equal(cloneData.Config.HealthMaxLogCount))
Expect(parentData.Config.HealthMaxLogSize).To(Equal(cloneData.Config.HealthMaxLogSize))
})
}) })