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

Running a pod on OSX leaves infra container running forever #13464

Closed
dav009 opened this issue Mar 8, 2022 · 19 comments · Fixed by #13859
Closed

Running a pod on OSX leaves infra container running forever #13464

dav009 opened this issue Mar 8, 2022 · 19 comments · Fixed by #13859
Assignees
Labels
locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@dav009
Copy link

dav009 commented Mar 8, 2022

I am running a pod via play kube. My container exits, but the companion infra container keeps running forever, meaning that the whole pod keeps running forever

Is there a way to make infra container exit once pod's containers exit?

I am running on OSX

@baude
Copy link
Member

baude commented Mar 8, 2022

OSX has nothing to do with it. And fwiw, this is normal pod behavior. I don't recall offhand that it is possible to do what you are asking; though it is getting late in the day and maybe someone will remember something.

@rhatdan
Copy link
Member

rhatdan commented Mar 8, 2022

We have talked a while about instrumenting what should happen in a Pod when containers exit.

1 Pod exits
2 Pod restarts container
3 Pod does nothing

I think we should add a feature to Pod/Containers for them to specify this.
Default should be for the Pod to exit when it has no containers running.

@baude
Copy link
Member

baude commented Mar 8, 2022

captured in RUN-1458

@vrothberg
Copy link
Member

We need such kind of behavior to make play-kube play nicely with systemd as well. Getting this done will probably be a by-product the Edge work unless tackled before.

It's probably also a better experience using a single pod in a systemd unit (from podman-generate-systemd).

@cdoern
Copy link
Contributor

cdoern commented Mar 11, 2022

yeah I can easily add a flag that changes this behavior

@baude
Copy link
Member

baude commented Mar 11, 2022

@cdoern the stuff @rhatdan describes above should be the default ... as such I dont think a flag is needed?

@rhatdan
Copy link
Member

rhatdan commented Mar 13, 2022

I would like a default for pod creation, how to handle containers. I don't know what the option shouldbe called.

--cfinish=[exit | ignore| restart]
I guess for cosistancy we would need to default to ignore. Should be in containers.conf.

@cdoern
Copy link
Contributor

cdoern commented Mar 13, 2022

@baude @rhatdan currently the default is as described where the pod keeps running when a container exits. I was thinking of adding a flag for containers (?) where one can specify that when a specific container exits maybe the pod stops as well?

@vrothberg
Copy link
Member

I don't understand why we would keep a Pod running when all containers exited. If users make heavy use of pods, they will have a lot of processes running that don't do much more than creating (a small amount of) heat.

I see an argument for keeping it running if no containers have been added yet though. But if we added a flag, I'd prefer calling it --keep-running.

@rhatdan
Copy link
Member

rhatdan commented Mar 16, 2022

Let's discuss at Cabal.

@cdoern
Copy link
Contributor

cdoern commented Mar 21, 2022

@rhatdan what was our decision on this one? I can implement this.

@cdoern cdoern self-assigned this Mar 21, 2022
@dav009
Copy link
Author

dav009 commented Mar 23, 2022

@rhatdan @cdoern happy to contribute and learn if some hints are given. TA!

@rhatdan
Copy link
Member

rhatdan commented Mar 23, 2022

The decision was to do the following. When a container exits, podman container cleanup is executed.

This program needs to be changed to check if the container is running within a Pod, if so, and the pod has no other containers running, it should stop the pod. If there are other containers running, then it should just exit.

A Pod with no containers should continue to run, which it will.

We need to make sure that a container start with a restart policy works correctly when run within a Pod.

@cdoern and @dav009 you are both welcome to work on this. (I was planning on looking at it next, but I don't have the time now.)

@vrothberg
Copy link
Member

I need this behavior for enabling play-kube in systemd units. I haven't seen work starting on it yet, so I will tackle it.

@vrothberg vrothberg assigned vrothberg and unassigned cdoern Apr 13, 2022
@cdoern
Copy link
Contributor

cdoern commented Apr 13, 2022

@vrothberg I am working on it but hit a snag so feel free to open a PR. I will follow up with a comment containing the code I have so far

@vrothberg
Copy link
Member

Apologies, Charlie! I didn't know you were already on it.

@cdoern
Copy link
Contributor

cdoern commented Apr 13, 2022

No worries, do you want to continue with it? I haven't gotten too far.

@vrothberg
Copy link
Member

If you're cool, I can continue. I think I am close to completion but it is tricky ... dead locks lie behind each and every corner.

@cdoern
Copy link
Contributor

cdoern commented Apr 13, 2022

Sounds good @vrothberg I was running into a bunch of deadlocks too!

vrothberg added a commit to vrothberg/libpod that referenced this issue May 2, 2022
Add the notion of an "exit policy" to a pod.  This policy controls the
behaviour when the last container of pod exits.  Initially, there are
two policies:

 - "continue" : the pod continues running. This is the default policy
                when creating a pod.

 - "stop" : stop the pod when the last container exits. This is the
            default behaviour for `play kube`.

In order to implement the deferred stop of a pod, add a worker queue to
the libpod runtime.  The queue will pick up work items and in this case
helps resolve dead locks that would otherwise occur if we attempted to
stop a pod during container cleanup.

Note that the default restart policy of `play kube` is "Always".  Hence,
in order to really solve containers#13464, the YAML files must set a custom
restart policy; the tests use "OnFailure".

Fixes: containers#13464
Signed-off-by: Valentin Rothberg <[email protected]>
@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
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 a pull request may close this issue.

5 participants