Merge pull request #26643 from Luap99/rm-dead-conmon

podman rm: handle case where conmon was killed
This commit is contained in:
openshift-merge-bot[bot]
2025-07-16 12:39:11 +00:00
committed by GitHub
6 changed files with 23 additions and 15 deletions

View File

@ -1544,7 +1544,7 @@ func (c *Container) waitForConmonToExitAndSave() error {
logrus.Errorf("Error cleaning up container %s after Conmon exited prematurely: %v", c.ID(), err)
}
return fmt.Errorf("container %s conmon exited prematurely, exit code could not be retrieved: %w", c.ID(), define.ErrInternal)
return fmt.Errorf("container %s conmon exited prematurely, exit code could not be retrieved: %w", c.ID(), define.ErrConmonDead)
}
return c.save()

View File

@ -539,7 +539,7 @@ func (ic *ContainerEngine) ContainerInspect(ctx context.Context, namesOrIds []st
// ErrNoSuchCtr is non-fatal, other errors will be
// treated as fatal.
if errors.Is(err, define.ErrNoSuchCtr) {
errs = append(errs, fmt.Errorf("no such container %s", name))
errs = append(errs, fmt.Errorf("no such container %q", name))
continue
}
return nil, nil, err
@ -550,7 +550,7 @@ func (ic *ContainerEngine) ContainerInspect(ctx context.Context, namesOrIds []st
// ErrNoSuchCtr is non-fatal, other errors will be
// treated as fatal.
if errors.Is(err, define.ErrNoSuchCtr) {
errs = append(errs, fmt.Errorf("no such container %s", name))
errs = append(errs, fmt.Errorf("no such container %q", name))
continue
}
return nil, nil, err

View File

@ -188,11 +188,7 @@ var _ = Describe("Podman inspect", func() {
ctrInspect := podmanTest.Podman([]string{"container", "inspect", ALPINE})
ctrInspect.WaitWithDefaultTimeout()
if IsRemote() {
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", ALPINE)))
} else {
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", ALPINE)))
}
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", ALPINE)))
imageInspect := podmanTest.Podman([]string{"image", "inspect", ALPINE})
imageInspect.WaitWithDefaultTimeout()
@ -399,11 +395,7 @@ var _ = Describe("Podman inspect", func() {
inspect := podmanTest.Podman([]string{"inspect", "--type", "container", podName})
inspect.WaitWithDefaultTimeout()
if IsRemote() {
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", podName)))
} else {
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", podName)))
}
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", podName)))
})
It("podman inspect --type network on a container should fail", func() {

View File

@ -1778,7 +1778,7 @@ search | $IMAGE |
# Unclear why `-t0` is required here, works locally without.
# But it shouldn't hurt and does make the test pass...
PODMAN_TIMEOUT=5 run_podman 125 stop -t0 $cname
is "$output" "Error: container .* conmon exited prematurely, exit code could not be retrieved: internal libpod error" "correct error on missing conmon"
is "$output" "Error: container .* conmon exited prematurely, exit code could not be retrieved: conmon process killed" "correct error on missing conmon"
# This should be safe because stop is guaranteed to call cleanup?
run_podman inspect --format "{{ .State.Status }}" $cname

View File

@ -202,4 +202,20 @@ function __run_healthcheck_container() {
die "Container never entered 'stopping' state"
}
# bats test_tags=ci:parallel
@test "podman rm after killed conmon" {
cname=c_$(safename)
run_podman run -d --name $cname $IMAGE sleep 1000
run_podman inspect --format '{{ .State.ConmonPid }}' $cname
conmon_pid=$output
kill -9 ${conmon_pid}
run_podman rm -f -t0 $cname
run_podman 125 container inspect $cname
assert "$output" =~ "no such container \"$cname\"" "Container should be removed"
}
# vim: filetype=sh

View File

@ -1081,7 +1081,7 @@ EOF
is "$output" "$exit_code_prop" \
"$basename: service container has the expected policy set in its annotations"
else
assert "$output" =~ "no such container $service_container" \
assert "$output" =~ "no such container \"$service_container\"" \
"$basename: unexpected error from podman container inspect"
fi