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

Ensure pod infra containers have an exit command #7283

Merged
merged 2 commits into from
Aug 17, 2020

Conversation

mheon
Copy link
Member

@mheon mheon commented Aug 10, 2020

Most Libpod containers are made via pkg/specgen/generate which includes code to generate an appropriate exit command which will handle unmounting the container's storage, cleaning up the container's network, etc. There is one notable exception: pod infra containers, which are made entirely within Libpod and do not touch pkg/specgen. As such, no cleanup process, network never cleaned up, bad things can happen.

There is good news, though - it's not that difficult to add this, and it's done in this PR. Generally speaking, we don't allow passing options directly to the infra container at create time, but we do (optionally) proxy a pre-approved set of options into it when we create it. Add ExitCommand to these options, and set it at time of pod creation using the same code we use to generate exit commands for normal containers.

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon

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-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 10, 2020
@mheon mheon force-pushed the pod_infra_has_exit_cmd branch from 00244f5 to 3a77203 Compare August 10, 2020 19:08
@TomSweeneyRedHat
Copy link
Member

Anyway to add a test?

Copy link
Member

@ashley-cui ashley-cui left a comment

Choose a reason for hiding this comment

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

LGTM, tested and it fixes #7103

[acui@localhost podman]$ ./bin/podman pod create --name test -p 5000:5000
564f217152dcceccc8f8200d8d4060f1b7602e64db104d07b8d3ee2dbc9ccb22

[acui@localhost podman]$ ./bin/podman create -d --pod test -p 5000:5000 registry:2
9c4d770b0cefd11b112ca13e415a2cd231fe1cb1866754fbc4d6eaa204902a42

[acui@localhost podman]$ ./bin/podman pod start test
564f217152dcceccc8f8200d8d4060f1b7602e64db104d07b8d3ee2dbc9ccb22

[acui@localhost podman]$ curl localhost:5000

[acui@localhost podman]$ ./bin/podman pod stop test
564f217152dcceccc8f8200d8d4060f1b7602e64db104d07b8d3ee2dbc9ccb22

[acui@localhost podman]$ ./bin/podman pod start test
564f217152dcceccc8f8200d8d4060f1b7602e64db104d07b8d3ee2dbc9ccb22

[acui@localhost podman]$ curl localhost:5000

@mheon mheon force-pushed the pod_infra_has_exit_cmd branch from 3a77203 to 4bb4356 Compare August 10, 2020 20:01
@mheon
Copy link
Member Author

mheon commented Aug 10, 2020

Pushed an update to fix pods where no infra container was created.

@rhatdan
Copy link
Member

rhatdan commented Aug 10, 2020

/lgtm
/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 10, 2020
@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 10, 2020
@mheon mheon force-pushed the pod_infra_has_exit_cmd branch from 4bb4356 to fb1465e Compare August 11, 2020 13:55
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2020
@mheon
Copy link
Member Author

mheon commented Aug 11, 2020

Rebased, hopefully CI will be happy now

@rhatdan
Copy link
Member

rhatdan commented Aug 11, 2020

Sad trombone.

@mheon
Copy link
Member Author

mheon commented Aug 11, 2020

I think the bindings test is wrong, will fix tomorrow morning. Not sure what's going on with rootless remote and F31 - they seem to be consistently failing, but initial glance doesn't say why.

@mheon mheon force-pushed the pod_infra_has_exit_cmd branch from fb1465e to e3d8728 Compare August 12, 2020 17:59
@mheon
Copy link
Member Author

mheon commented Aug 12, 2020

Bindings tests should be fixed

Most Libpod containers are made via `pkg/specgen/generate` which
includes code to generate an appropriate exit command which will
handle unmounting the container's storage, cleaning up the
container's network, etc. There is one notable exception: pod
infra containers, which are made entirely within Libpod and do
not touch pkg/specgen. As such, no cleanup process, network never
cleaned up, bad things can happen.

There is good news, though - it's not that difficult to add this,
and it's done in this PR. Generally speaking, we don't allow
passing options directly to the infra container at create time,
but we do (optionally) proxy a pre-approved set of options into
it when we create it. Add ExitCommand to these options, and set
it at time of pod creation using the same code we use to generate
exit commands for normal containers.

Fixes containers#7103

Signed-off-by: Matthew Heon <[email protected]>
@mheon mheon force-pushed the pod_infra_has_exit_cmd branch from e3d8728 to a071939 Compare August 13, 2020 18:04
@mheon
Copy link
Member Author

mheon commented Aug 13, 2020

Current thinking: we have a race similar to #5747 but with stopping pods, not containers - and it's causing the bindings tests to fail as we hit the pod for status info before the cleanup process can run.

@rhatdan
Copy link
Member

rhatdan commented Aug 13, 2020

Can you add a podman wait?

@mheon
Copy link
Member Author

mheon commented Aug 13, 2020

I'm looking into a similar solution to what we used in #5747 - force a cleanup before the API call returns.

This should help alleviate races where the pod is not fully
cleaned up before subsequent API calls happen.

Signed-off-by: Matthew Heon <[email protected]>
@mheon
Copy link
Member Author

mheon commented Aug 17, 2020

Added code to ensure cleanup happens before the Pod Stop API call finishes.

}

// Ignore containers that are running/paused
if !ctr.ensureState(define.ContainerStateConfigured, define.ContainerStateCreated, define.ContainerStateStopped, define.ContainerStateExited) {
Copy link
Member

Choose a reason for hiding this comment

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

Not for this review, but it might be nice to create a isContainerPausedOrRunning() utility function. I think we've this big blob of test in a few places. But not for this PR.

@TomSweeneyRedHat
Copy link
Member

LGTM
one comment for future consideration and happy green test buttons

@mheon
Copy link
Member Author

mheon commented Aug 17, 2020

Tests are green!

@rhatdan @baude @giuseppe @TomSweeneyRedHat PTAL and merge, would like to get this backported to 2.0 for 2.0.5

@baude
Copy link
Member

baude commented Aug 17, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 17, 2020
@rhatdan
Copy link
Member

rhatdan commented Aug 17, 2020

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 17, 2020
@openshift-merge-robot openshift-merge-robot merged commit 8caed30 into containers:master Aug 17, 2020
@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 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants