-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With --rm option remove container if podman run fails #15060
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test looks weird
test/system/030-run.bats
Outdated
@test "podman run failed --rm " { | ||
rand=$(random_string 30) | ||
run_podman run -p 1200:80 --rm -d --name $rand docker.io/library/nginx | ||
run_podman 225 run -p 1200:80 --rm -d docker.io/library/nginx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
225??? That seems like a nonsensical exit code
test/system/030-run.bats
Outdated
@@ -870,4 +870,19 @@ EOF | |||
run_podman container rm -fa | |||
} | |||
|
|||
@test "podman run failed --rm " { | |||
rand=$(random_string 30) | |||
run_podman run -p 1200:80 --rm -d --name $rand docker.io/library/nginx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why nginx? Can't we use $IMAGE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we actually needed a process to bind, but it looks like we can do it without. Besides this is the image (sortof) that the user reported. Since $IMAGE will cause the same error, I will change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bind is done by podman on the host, it will fail with all images.
test/system/030-run.bats
Outdated
run_podman stop test | ||
run_podman wait test | ||
|
||
# container should be in output of 'ps -a' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems wrong
pkg/domain/infra/abi/containers.go
Outdated
@@ -1097,6 +1107,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta | |||
if err := ctr.Start(ctx, true); err != nil { | |||
// This means the command did not exist | |||
report.ExitCode = define.ExitCode(err) | |||
_ = removeContainer(ctr, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this removes the container even when opts.Rm is not set
also we should not ignore the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if deleteError := ic.Libpod.RemoveContainer(ctx, ctr, true, false, timeout); deleteError != nil { | ||
logrus.Debugf("unable to remove container %s after failing to start and attach to it", ctr.ID()) | ||
} | ||
_ = removeContainer(ctr, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts.RM is checked. removeContainer is logging the debug message itself.
Test is still broken, no point in CI right now. Suggestion: @test "podman run failed --rm " {
port=$(random_free_port)
# Run two containers with the same port bindings. The second must fail
run_podman run -p $port:80 --rm -d --name c_ok $IMAGE top
run_podman 126 run -p $port:80 --rm -d --name c_notok $IMAGE top
# Prior to #15060, the second container would still show up in ps -a
run_podman ps -a --format '{{.Image}}--{{.Names}}'
is "$output" "$IMAGE--c_ok" "podman ps -a shows only the OK container"
run_podman container rm -f -t 0 c_ok
} Another suggestion: you can run system tests on your own system with, e.g., $ hack/bats 030:"run failed" <--- 030 = 030-run.bats, "run failed" is filter substring on test name I've confirmed that this test passes with your PR, and fails on |
Better suggestion: @test "podman run failed --rm " {
port=$(random_free_port)
# Run two containers with the same port bindings. The second must fail
run_podman run -p $port:80 --rm -d --name c_ok $IMAGE top
run_podman 126 run -p $port:80 -d --name c_fail_no_rm $IMAGE top
run_podman 126 run -p $port:80 --rm -d --name c_fail_with_rm $IMAGE top
# Prior to #15060, the third container would still show up in ps -a
run_podman ps -a --sort names --format '{{.Image}}--{{.Names}}'
is "$output" "$IMAGE--c_fail_no_rm
$IMAGE--c_ok" \
"podman ps -a shows running & failed containers, but not failed-with-rm"
run_podman container rm -f -t 0 c_ok c_fail_no_rm
} This one confirms that the error container is only removed with |
fe3201e
to
87fd73e
Compare
Fixes containers#15049 Signed-off-by: Daniel J Walsh <[email protected]>
LGTM but I'd say this merits a release note...? |
Fixes #15049
Signed-off-by: Daniel J Walsh [email protected]
Does this PR introduce a user-facing change?