From a917a6cfe05431c29025364767a3a77163132b7e Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Fri, 18 Aug 2023 06:06:39 -0400 Subject: [PATCH] use container restart policy if user specifies one Fixes: https://github.com/containers/podman/issues/19671 Signed-off-by: Daniel J Walsh --- pkg/specgen/generate/container_create.go | 2 +- test/system/200-pod.bats | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index 648dd17c35..738aae2892 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -587,7 +587,7 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l retries uint ) // If the container is running in a pod, use the pod's restart policy for all the containers - if pod != nil && !s.IsInitContainer() { + if pod != nil && !s.IsInitContainer() && s.RestartPolicy == "" { podConfig := pod.ConfigNoCopy() if podConfig.RestartRetries != nil { retries = *podConfig.RestartRetries diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats index f159ed6ee0..1b25477a85 100644 --- a/test/system/200-pod.bats +++ b/test/system/200-pod.bats @@ -577,6 +577,21 @@ io.max | $lomajmin rbps=1048576 wbps=1048576 riops=max wiops=max run_podman 1 pod exists $podname } +@test "podman pod create restart tests" { + podname=pod$(random_string) + + run_podman pod create --restart=on-failure --name $podname + run_podman create --name test-ctr --pod $podname $IMAGE + run_podman container inspect --format '{{ .HostConfig.RestartPolicy.Name }}' test-ctr + is "$output" "on-failure" "container inherits from pod" + + run_podman create --replace --restart=always --name test-ctr --pod $podname $IMAGE + run_podman container inspect --format '{{ .HostConfig.RestartPolicy.Name }}' test-ctr + is "$output" "always" "container overrides restart policy from pod" + + run_podman pod rm -f -a +} + # Helper used by pod ps --filter test. Creates one pod or container # with a UNIQUE two-character CID prefix. function thingy_with_unique_id() {