Use stop timeout of zero for system reset

when performing a system reset with containers that run somewhere where
a soft kill wont work (like sleep), containers will wait 10 seconds
before terminating with a sigkill.  But for a forceful action like
system reset, we should outright set no timeout so containers stop
quickly and are not waiting on a timeout

Fixes #21874

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude 2024-03-01 10:43:43 -06:00
parent 032cd5b402
commit 0898b338b0
2 changed files with 10 additions and 6 deletions

View File

@ -108,13 +108,13 @@ func (r *Runtime) Reset(ctx context.Context) error {
return define.ErrRuntimeStopped
}
var timeout *uint
var timeout uint = 0
pods, err := r.GetAllPods()
if err != nil {
return err
}
for _, p := range pods {
if ctrs, err := r.RemovePod(ctx, p, true, true, timeout); err != nil {
if ctrs, err := r.RemovePod(ctx, p, true, true, &timeout); err != nil {
if errors.Is(err, define.ErrNoSuchPod) {
continue
}
@ -133,7 +133,7 @@ func (r *Runtime) Reset(ctx context.Context) error {
}
for _, c := range ctrs {
if ctrs, _, err := r.RemoveContainerAndDependencies(ctx, c, true, true, timeout); err != nil {
if ctrs, _, err := r.RemoveContainerAndDependencies(ctx, c, true, true, &timeout); err != nil {
for ctr, err := range ctrs {
logrus.Errorf("Error removing container %s: %v", ctr, err)
}
@ -163,7 +163,7 @@ func (r *Runtime) Reset(ctx context.Context) error {
return err
}
for _, v := range volumes {
if err := r.RemoveVolume(ctx, v, true, timeout); err != nil {
if err := r.RemoveVolume(ctx, v, true, &timeout); err != nil {
if errors.Is(err, define.ErrNoSuchVolume) {
continue
}

View File

@ -92,12 +92,16 @@ var _ = Describe("podman system reset", Serial, func() {
ctrName := "testctr"
port1 := GetPort()
port2 := GetPort()
session := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "sleep", "inf"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
// run system reset on a container that is running
// set a timeout of 9 seconds, which tests that reset is using the timeout
// of zero and forceable killing containers with no wait.
// #21874
reset := podmanTest.Podman([]string{"system", "reset", "--force"})
reset.WaitWithDefaultTimeout()
reset.WaitWithTimeout(9)
Expect(reset).Should(ExitCleanly())
session2 := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "top"})