Skip to content

Commit 27487fd

Browse files
Merge pull request #26643 from Luap99/rm-dead-conmon
podman rm: handle case where conmon was killed
2 parents 3986832 + c1cf4b0 commit 27487fd

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

libpod/container_internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ func (c *Container) waitForConmonToExitAndSave() error {
15441544
logrus.Errorf("Error cleaning up container %s after Conmon exited prematurely: %v", c.ID(), err)
15451545
}
15461546

1547-
return fmt.Errorf("container %s conmon exited prematurely, exit code could not be retrieved: %w", c.ID(), define.ErrInternal)
1547+
return fmt.Errorf("container %s conmon exited prematurely, exit code could not be retrieved: %w", c.ID(), define.ErrConmonDead)
15481548
}
15491549

15501550
return c.save()

pkg/domain/infra/abi/containers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func (ic *ContainerEngine) ContainerInspect(ctx context.Context, namesOrIds []st
539539
// ErrNoSuchCtr is non-fatal, other errors will be
540540
// treated as fatal.
541541
if errors.Is(err, define.ErrNoSuchCtr) {
542-
errs = append(errs, fmt.Errorf("no such container %s", name))
542+
errs = append(errs, fmt.Errorf("no such container %q", name))
543543
continue
544544
}
545545
return nil, nil, err
@@ -550,7 +550,7 @@ func (ic *ContainerEngine) ContainerInspect(ctx context.Context, namesOrIds []st
550550
// ErrNoSuchCtr is non-fatal, other errors will be
551551
// treated as fatal.
552552
if errors.Is(err, define.ErrNoSuchCtr) {
553-
errs = append(errs, fmt.Errorf("no such container %s", name))
553+
errs = append(errs, fmt.Errorf("no such container %q", name))
554554
continue
555555
}
556556
return nil, nil, err

test/e2e/inspect_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,7 @@ var _ = Describe("Podman inspect", func() {
188188

189189
ctrInspect := podmanTest.Podman([]string{"container", "inspect", ALPINE})
190190
ctrInspect.WaitWithDefaultTimeout()
191-
if IsRemote() {
192-
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", ALPINE)))
193-
} else {
194-
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", ALPINE)))
195-
}
191+
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", ALPINE)))
196192

197193
imageInspect := podmanTest.Podman([]string{"image", "inspect", ALPINE})
198194
imageInspect.WaitWithDefaultTimeout()
@@ -399,11 +395,7 @@ var _ = Describe("Podman inspect", func() {
399395

400396
inspect := podmanTest.Podman([]string{"inspect", "--type", "container", podName})
401397
inspect.WaitWithDefaultTimeout()
402-
if IsRemote() {
403-
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", podName)))
404-
} else {
405-
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", podName)))
406-
}
398+
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", podName)))
407399
})
408400

409401
It("podman inspect --type network on a container should fail", func() {

test/system/030-run.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ search | $IMAGE |
17781778
# Unclear why `-t0` is required here, works locally without.
17791779
# But it shouldn't hurt and does make the test pass...
17801780
PODMAN_TIMEOUT=5 run_podman 125 stop -t0 $cname
1781-
is "$output" "Error: container .* conmon exited prematurely, exit code could not be retrieved: internal libpod error" "correct error on missing conmon"
1781+
is "$output" "Error: container .* conmon exited prematurely, exit code could not be retrieved: conmon process killed" "correct error on missing conmon"
17821782

17831783
# This should be safe because stop is guaranteed to call cleanup?
17841784
run_podman inspect --format "{{ .State.Status }}" $cname

test/system/055-rm.bats

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,20 @@ function __run_healthcheck_container() {
202202
die "Container never entered 'stopping' state"
203203
}
204204

205+
# bats test_tags=ci:parallel
206+
@test "podman rm after killed conmon" {
207+
cname=c_$(safename)
208+
run_podman run -d --name $cname $IMAGE sleep 1000
209+
210+
run_podman inspect --format '{{ .State.ConmonPid }}' $cname
211+
conmon_pid=$output
212+
213+
kill -9 ${conmon_pid}
214+
215+
run_podman rm -f -t0 $cname
216+
217+
run_podman 125 container inspect $cname
218+
assert "$output" =~ "no such container \"$cname\"" "Container should be removed"
219+
}
220+
205221
# vim: filetype=sh

test/system/252-quadlet.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ EOF
10811081
is "$output" "$exit_code_prop" \
10821082
"$basename: service container has the expected policy set in its annotations"
10831083
else
1084-
assert "$output" =~ "no such container $service_container" \
1084+
assert "$output" =~ "no such container \"$service_container\"" \
10851085
"$basename: unexpected error from podman container inspect"
10861086
fi
10871087

0 commit comments

Comments
 (0)