From f94d613556bf17c7b52017920d8f503c9f56077d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Tue, 25 Mar 2025 17:01:43 +0100 Subject: [PATCH] Fix container clone with configured Healthcheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/containers/podman/issues/21630 Fixes: https://issues.redhat.com/browse/RUN-2632 Signed-off-by: Jan Rodák --- pkg/domain/infra/abi/containers.go | 5 +++++ pkg/specgen/generate/container.go | 4 ++++ test/e2e/container_clone_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 52ff8797c6..1b6694bc65 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -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{}) if err != nil { return nil, err diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go index 85547b7c7f..d5973e6984 100644 --- a/pkg/specgen/generate/container.go +++ b/pkg/specgen/generate/container.go @@ -462,6 +462,10 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, containerID specg.HealthMaxLogSize = define.DefaultHealthMaxLogSize } + specg.HealthConfig = conf.HealthCheckConfig + specg.StartupHealthConfig = conf.StartupHealthCheckConfig + specg.HealthCheckOnFailureAction = conf.HealthCheckOnFailureAction + specg.IDMappings = &conf.IDMappings specg.ContainerCreateCommand = conf.CreateCommand if len(specg.Rootfs) == 0 { diff --git a/test/e2e/container_clone_test.go b/test/e2e/container_clone_test.go index 1f5677b51a..b974a107bb 100644 --- a/test/e2e/container_clone_test.go +++ b/test/e2e/container_clone_test.go @@ -304,4 +304,33 @@ var _ = Describe("Podman container clone", func() { 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)) + + }) })