Skip to content
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

Merged
merged 1 commit into from
Jul 28, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Jul 25, 2022

Fixes #15049

Signed-off-by: Daniel J Walsh [email protected]

Does this PR introduce a user-facing change?

podman run --rm ... commands that fail will no longer leave the container behind, it will be removed.

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Jul 25, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 25, 2022

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note-none and removed do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels Jul 25, 2022
@mheon
Copy link
Member

mheon commented Jul 25, 2022

LGTM

Copy link
Member

@edsantiago edsantiago left a 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 "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
Copy link
Member

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

@@ -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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

run_podman stop test
run_podman wait test

# container should be in output of 'ps -a'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment seems wrong

@@ -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)
Copy link
Member

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

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member Author

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.

@edsantiago
Copy link
Member

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 main

@edsantiago
Copy link
Member

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 --rm

@rhatdan rhatdan force-pushed the rm1 branch 3 times, most recently from fe3201e to 87fd73e Compare July 26, 2022 10:37
@edsantiago
Copy link
Member

LGTM but I'd say this merits a release note...?

@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2022
@openshift-merge-robot openshift-merge-robot merged commit a43cfc1 into containers:main Jul 28, 2022
@rhatdan rhatdan deleted the rm1 branch December 1, 2022 22:01
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
5 participants