-
Notifications
You must be signed in to change notification settings - Fork 557
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
Allow to do some actions before container process stop #926
Comments
The spec doesn't have pre-stop hooks, because it doesn't have a
That's pretty easy to do if you can tell the controller to fire 1 (and 3, if any monitoring is necessary there), and thrre's no need to involve the runtime. But since the
That gets a bit wiggly, because the spec says nothing about supported |
In my opinion this is not a good argument for this use case. To be honest, as you go along this reasoning, no hook is guaranteed to be run because the runtime controller process can crash in any moment also (as any other component of your infrastructure can fail). I understand that it is impossible to guarantee a 100% effectiveness of a graceful shutdown mechanism in all situations, but 99% effectiveness in every day use cases (new version deployments, host maintenance etc.) is a great business value, because it allows you to work almost freely (and safely) with the containers. |
On Mon, Oct 02, 2017 at 09:16:14AM +0000, Adam Medziński wrote:
To be honest, as you go along this reasoning, no hook is guaranteed
to be run because the runtime controller process can crash in any
moment also (as any other component of your infrastructure can
fail).
Fair. And the fact that the signals supported by ‘kill’ are
undocumented is clearly something that could be addressed by the spec
if the maintainers agree that it's useful (I think it is, regardless
of whether kill-related hooks are supported).
This is really a judgement call for maintainers about the scope of
hooks in the spec. I don't know if we have maintainers speaking for
themselves somewhere on that topic, but based on my paraphrasing in
[1], it's possible that the current hooks were just grandfathered into
the spec because they had existing users, and that the maintainers
would rather not add additional hooks because folks can always address
these issues in higher levels (e.g. in containerd or whatever
controller you use). Or it's possible that they want pre- and
post-hooks for all operations [2]. Or it's possible that they want to
debate the utility of pre- and post-hooks for each case, and only
require runtime support for those which they deem sufficiently useful.
If we do add pre- and post-kill hooks, an alternative to my previous
suggestion [3] might be to drop the signal keys and add a token
(‘${SIGNAL}’?) to pass the chosen signal through to the hook:
$ cat config.json
{
…,
"hooks": {
"prekill": [
{
"path": "/usr/bin/my-pre-kill-hook"
"args": ["ab", "${SIGNAL}", "cd"],
}
]
}
}
$ cat /usr/bin/my-pre-kill-hook
#!/bin/sh
AB="${1}"
SIGNAL="${2}"
CD="${3}"
STATE="$(cat)" # read the state JSON from stdin
case "${SIGNAL}" in
TERM)
…whatever…
;;
KILL)
…other stuff…
;;
USR1|USR2)
…more stuff…
;;
esac
…
That would also allow the spec to continue to dodge the issue of
signal names, although I don't see a need to do so.
[1]: #483 (comment)
[2]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0/runtime.md#operations
[3]: #926 (comment)
|
@wking Should I make a pull request with proposed changes or more opinions is needed? |
Working up a pull request is more work for you, and the maintainers may end up rejecting it if you don't happen to guess what they want. But it might increase the chances of a maintainer chiming in on this point, and that would help. The December meeting is just around the corner; I'll try to get some opinions then. If you can make the meeting, you may wan't to argue for your preferred approach. I don't really care if the spec gets If we don't get maintainer opinions at the meeting and you're comfortable investing time in a PR that might be rejected, then you can work up a PR. Or if you don't mind investing time and want something more concrete to discuss at the meeting, you can work up a PR now. |
There was some discussion of this in today's meeting, although it looks like collabot decided to check out and miss the fun :p. Here's my local log: 14:07 @wking I'd like to talk about the plans for hooks in runtime spec (#926), but we may not have enough runtime-spec maintainers present to make useful progress on that So we're waiting for @mrunalp and @crosbymichael to weigh in with their plans for hooks. |
FWIW I also think adding hooks (where they make sense) might be a good decision, specifically because it allows us to avoid having to have even more wrappers-of-wrappers when people decide they want to slightly alter how |
On Wed, Jan 10, 2018 at 11:23:04PM +0000, Aleksa Sarai wrote:
The GPU usecases in particular show how useful hooks are (they even
modified the hook design in LXC so that the GPU usecase worked
better).
Is this a reference to lxc/lxc#1826? That sounds like it could be
handled in our existing pre-start hook [1] or by the orchestrator
between the runtime ‘create’ and ‘start’ calls. Are there other links
into the GPU-hook discussion?
[1]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#prestart
|
Yes, that's the issue I was referring to. Most of the discussion about hooks for GPU happened in-person at the time (this was at Linux Plumbers) so I can't really link to any of it. |
Anything new to report here? Would like to use it as podman hook to retrieve ip information of the used interfaces in the container. After the container stops, all that information is lost. |
Background:
The OCI hooks mechanism looks like a good place to register container in discovery service or add it to load balancer pool - as we have
Prestart
andPoststart
hooks, but there is a problem when we want to remove old containers after new version deployment. We only havePoststop
hook which is fired during container deletion (so process inside container is already dead), which in practice makes impossible to gracefully remove old containers (e.g. by using load balancer connection draining feature). When a single container handles high traffic (thousands of requests per seconds) it ends with a lot of 502 HTTP errors for the site users. Currently each popular container management software provides some way to achieve graceful container removal (Kubernetes has PostStart/PreStop container lifecycle hooks, on Mesos we can write custom executors with that logic), but OCI spec is missing that feature.Question:
Can the OCI spec be extended to allow to do some actions before container process stop in a standardised way?
The text was updated successfully, but these errors were encountered: