From d2ec127c1310beb04c79028986eadede2e390505 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 22 Aug 2023 17:15:27 -0400 Subject: [PATCH 1/2] Set StopTimeout for compat API if not set by client Currently containers created via DOCKER API without specifying StopTimeout are defaulting to 0 seconds. This change should default them to setting in containers.conf normally 10 seconds. Fixes: https://github.com/containers/podman/issues/19139 Signed-off-by: Daniel J Walsh --- pkg/api/handlers/compat/containers_create.go | 1 + test/apiv2/20-containers.at | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 19a541b4ec..80d7d7f316 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -435,6 +435,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C Rm: cc.HostConfig.AutoRemove, SecurityOpt: cc.HostConfig.SecurityOpt, StopSignal: cc.Config.StopSignal, + StopTimeout: rtc.Engine.StopTimeout, // podman default StorageOpts: stringMaptoArray(cc.HostConfig.StorageOpt), Sysctl: stringMaptoArray(cc.HostConfig.Sysctls), Systemd: "true", // podman default diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 92074b0b28..b057ef8936 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -308,6 +308,7 @@ cid_top=$(jq -r '.Id' <<<"$output") t GET containers/${cid_top}/json 200 \ .Config.Entrypoint[0]="top" \ .Config.Cmd='[]' \ + .Config.StopTimeput="10" \ .Path="top" \ .NetworkSettings.Networks.podman.NetworkID=podman t POST containers/${cid_top}/start 204 From f32e954b8a472b58b8a1918d5de16866f4917807 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 22 Aug 2023 17:16:04 -0400 Subject: [PATCH 2/2] Set StopTimeout for service-container started under podman kube play Fixes: https://github.com/containers/podman/issues/19139 Service containers are defaulting to 0 seconds for Timeout rather then the settings in containers.conf. Signed-off-by: Daniel J Walsh --- pkg/domain/infra/abi/play.go | 7 ++++++- test/apiv2/20-containers.at | 2 +- test/system/700-play.bats | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index f11a92085f..63d0f657b9 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -65,6 +65,10 @@ func (ic *ContainerEngine) createServiceContainer(ctx context.Context, name stri return nil, fmt.Errorf("image for service container: %w", err) } + rtc, err := ic.Libpod.GetConfigNoCopy() + if err != nil { + return nil, err + } ctrOpts := entities.ContainerCreateOptions{ // Inherited from infra containers ImageVolume: define.TypeBind, @@ -73,7 +77,8 @@ func (ic *ContainerEngine) createServiceContainer(ctx context.Context, name stri ReadOnly: true, ReadWriteTmpFS: false, // No need to spin up slirp etc. - Net: &entities.NetOptions{Network: specgen.Namespace{NSMode: specgen.NoNetwork}}, + Net: &entities.NetOptions{Network: specgen.Namespace{NSMode: specgen.NoNetwork}}, + StopTimeout: rtc.Engine.StopTimeout, } // Create and fill out the runtime spec. diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index b057ef8936..a0a652ac60 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -308,7 +308,7 @@ cid_top=$(jq -r '.Id' <<<"$output") t GET containers/${cid_top}/json 200 \ .Config.Entrypoint[0]="top" \ .Config.Cmd='[]' \ - .Config.StopTimeput="10" \ + .Config.StopTimeout="10" \ .Path="top" \ .NetworkSettings.Networks.podman.NetworkID=podman t POST containers/${cid_top}/start 204 diff --git a/test/system/700-play.bats b/test/system/700-play.bats index 122e4ccc45..efa8eced50 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -206,6 +206,9 @@ EOF run_podman container inspect $service_container --format "{{.State.Running}}" is "$output" "true" + run_podman container inspect $service_container --format '{{.Config.StopTimeout}}' + is "$output" "10" "StopTimeout should be initialized to 10" + # Stop the *main* container and make sure that # 1) The pod transitions to Exited # 2) The service container is stopped