-
Notifications
You must be signed in to change notification settings - Fork 554
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
hooks: start with pre-start and post-stop hooks. #34
Conversation
|
||
``` | ||
"hooks" : { | ||
"pre-start": "/path/to/pre-start-hook", |
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.
Should this be an array for the args?
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.
As per the discussion in #20, have stuck with not using arguments but passing over a fd like stdin.
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.
Now I think that args might be useful. You can have one binary for multiple hooks.
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.
How about allowing arguments to be anything that the hooks want but still pass state over a fd?
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.
Perfect
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.
Updated.
If containers are launched under some daemon that also handles coordination, I would rather let it take care of all the lifecycle related hooks. For example, if running under systemd, why not let it invoke the pre-start and post-exit events with its Granted, my examples might be "orchestration events" rather than container life-cycle events but is there a compelling reason to explicitly add hooks for just the container life-cycle. Finally, if these hooks are being declared in the container manifest, why can't the container just have a script such as this as the entry point:
Just want to push back to make sure these are truly needed. |
@eyakubovich perhaps the In case of user namespaces, this allows a hook to customize the network namespace (as an examplle) before the container process is exec'ed. The counter argument to this is that why can't one just create a network namespace outside and then setns to it. However, that doesn't quite work, as each namespace has an owning user namespace and only the root user in that user namespace has all the privileges to make modifications to that namespace. Also, setns itself isn't allowed to a namespace belonging to parent user namespace or a sibling user namespace. So, such a The flow is that container One more thing of use that could be done during @LK4D4 please correct or amend as necessary. I will add this to the document. |
``` | ||
"hooks" : { | ||
"pre-start": ["/path/to/pre-start-hook", "arg1", "arg2"], | ||
"post-stop": ["/path/to/post-stop-hook", "arg1"] |
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.
We should consider the lessons learned from the docker plugins and make this more abstract names instead of absolute paths: moby/moby#13514 (comment) and moby/moby#13859
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.
@philips I don't mind doing that. We would be prescribing standard locations to load the hooks from then, right? Also, that doesn't gel quite well with allowing arbitrary arguments, IMO (which isn't necessarily bad but we need to define useful arguments).
@mrunalp Yeah, so |
Pushed update to specify directories for hooks. Still need to resolve whether we need any arguments at all? The case that @LK4D4 mentioned could be solved by symlinks or copying the hooks with different names. |
|
||
``` | ||
"hooks" : { | ||
"pre-start": ["pre-start-hook", "arg1", "arg2"], |
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 should be an array so that you can specify multiple binaries for a single hook.
"pre-start": [
["ps", "aux"],
["ip", "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.
👍 Updating
f5c8a45
to
11b92e4
Compare
## Hooks | ||
Hooks allows one to run code before/after various lifecycle events of the container. The state of the container is passed to the hooks over a well-known fd, so the hooks could get the information they need to do their work. | ||
|
||
Hooks are placed under a well known directories under which they are search for and executed. The list of directories that will be looked up are: |
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.
Do we need a specific directory to store the hooks in? Why can a hook not be any file on the filesystem?
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.
@crosbymichael That is up for debate. I am leaning towards any file. @philips do you have any arguments against?
Any more thoughts for these hooks? |
On Wed, Jul 01, 2015 at 01:55:54PM -0700, Mrunal Patel wrote:
I'd rather not specify well-known directories for hooks, since that To make it easy to distribute hooks, I'd rather have relative hook In any case, I feel like allowing absolute-paths for hooks makes sense |
On Wed, Jul 8, 2015 at 4:14 AM, W. Trevor King notifications@github.com
+1, location of hooks should be at implementation's discretion |
Updated to take out the hooks directory paragraph. |
On Wed, Jul 08, 2015 at 09:47:38AM -0700, Mrunal Patel wrote:
Hmm. Will runc take an argument or a RUNC_HOOK_PATH environment Since this all seems complicated, I went back and reread $ cat rootfs/bin/wrap.sh You could: runc wrap.sh docker --daemonor some such to get full control over your setup/teardown without any
|
@wking The hooks won't be run in the container's namespaces. They will be run from the host and they would get the state data including the container pid, so they could join the namespaces that they want to. I will clarify this in the doc if there is no objection. |
Pushed update with clarification about where the hooks will be executed from. |
Fixed. |
For post-stop I think it makes sense to log errors and continue executing the remaining hooks. Updated to reflect that in the document and moved the previous generic section to pre-start section. |
On Wed, Jul 08, 2015 at 11:45:09AM -0700, Mrunal Patel wrote:
It looks better to me now :). My main concern with host-PATH lookups that don't include the root "hooks" : { I think it makes more sense to include the root container-bundle $ PATH=".:$PATH" runc is easy enough ;). Another thing to consider here is whether the hook-block should be |
@crosbymichael Maybe I missing something. So, I need to run |
@LK4D4 if argv0 is an abs path then just set it as the path. |
@crosbymichael Okay, but I still think that Args+Path more understandable, then "if first element is abs path, then argv[0] is actually argv[1]" |
@crosbymichael WDYT? Need to decide one way or the other :) |
@crosbymichael No problem ;) I think it makes sense to add Path, too. Updated. |
LGTM |
Hook paths are absolute and are executed from the host's filesystem. | ||
|
||
### Pre-start | ||
The pre-start hooks are called after the container process is started but before the user supplied command is executed. |
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 would change this to after the container's namespaces are created
and not say started because it's confusing with the hooks name as prestart
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.
How about
The pre-start hooks are called after the container process is spawned, but before the user supplied command is executed.
They are called after the container namespaces are created on Linux, so they provide an opportunity to customize the container.
In Linux, for e.g., the network namespace could be configured in this hook.
Signed-off-by: Mrunal Patel <mrunalp@gmail.com> Add hooks to the spec Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
@crosbymichael updated |
LGTM |
hooks: start with pre-start and post-stop hooks.
Leaning on Go's docs [1]: > Args holds command line arguments, including the command as > Args[0]. If the Args field is empty or nil, Run uses {Path}. for the fallback wording. This restores the ability to explicitly set args[0] independent of the path, which was requested in opencontainers#34 [2] and ack-ed by Micheal [3] and Mrunal [4], but didn't match the examples that landed with opencontainers#34. [1]: http://golang.org/pkg/os/exec/#Cmd [2]: opencontainers#34 (comment) [3]: opencontainers#34 (comment) [4]: opencontainers#34 (comment) Signed-off-by: W. Trevor King <wking@tremily.us>
This follows Python's API, which has 'args' and 'executable' (our PATH) for Popen [1]). That allows most users (who don't need to distinguish between args[0] and the executable path) to just use args, while still providing a means to make that distinction (set 'path') for folks who do need it. This restores the ability to explicitly set args[0] independent of the path, which was requested in opencontainers#34 [2] and ack-ed by Micheal [3] and Mrunal [4], but didn't match the examples that landed with opencontainers#34. [1]: https://docs.python.org/3/library/subprocess.html#subprocess.Popen [2]: opencontainers#34 (comment) [3]: opencontainers#34 (comment) [4]: opencontainers#34 (comment) Signed-off-by: W. Trevor King <wking@tremily.us>
This follows Python's API, which has 'args' and 'executable' (our PATH) for Popen [1]). That allows most users (who don't need to distinguish between args[0] and the executable path) to just use args, while still providing a means to make that distinction (set 'path') for folks who do need it. This restores the ability to explicitly set args[0] independent of the path, which was requested in opencontainers#34 [2] and ack-ed by Micheal [3] and Mrunal [4], but didn't match the examples that landed with opencontainers#34. [1]: https://docs.python.org/3/library/subprocess.html#subprocess.Popen [2]: opencontainers#34 (comment) [3]: opencontainers#34 (comment) [4]: opencontainers#34 (comment) Signed-off-by: W. Trevor King <wking@tremily.us>
The language from 15dee2e (runtime: Add prestart/poststop hooks, 2015-08-03, opencontainers#34) landed well before we had glossary entries for the runtime and container namespaces (from 5dad125, config-linux: Specify host mount namespace for namespace paths, 2015-12-18, opencontainers#275). Now that we do have language to cover that concept, it's better to explicitly say that hooks run in the runtime namespace instead of leaving it to the reader to extrapolate from the filesystem requirement. With the new namespace wording, the "host's filesystem" wording is somewhat redundant. I've left it in though, because I think it helps to have a more gradual transition from hook paths to namespaces. Signed-off-by: W. Trevor King <wking@tremily.us>
The language from 15dee2e (runtime: Add prestart/poststop hooks, 2015-08-03, opencontainers#34) landed well before we had glossary entries for the runtime and container namespaces (from 5dad125, config-linux: Specify host mount namespace for namespace paths, 2015-12-18, opencontainers#275). Now that we do have language to cover that concept, it's better to explicitly say that hooks run in the runtime namespace instead of leaving it to the reader to extrapolate from the filesystem requirement. With the new namespace wording, the "host's filesystem" wording is somewhat redundant. I've left it in though, because I think it helps to have a more gradual transition from hook paths to namespaces. Signed-off-by: W. Trevor King <wking@tremily.us>
See #20
Starting with pre-start and post-stop and then will add more specific hooks tied to namespaces in Linux.
Signed-off-by: Mrunal Patel mrunalp@gmail.com