-
Notifications
You must be signed in to change notification settings - Fork 553
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
runtime: fail when a poststart hook fails #1262
base: main
Are you sure you want to change the base?
Conversation
Poststart hooks exist in runc since 2015 [1], and since that time until today, if a hook returned an error, runc kills the container. In 2020, commit c166268 (PR opencontainers#1008) added the following text (which became part of runtime-spec release v1.0.2): > 9. The `poststart` MUST be invoked by the runtime. If any > `poststart` hook fails, the runtime MUST log a warning, but the > remaining hooks and lifecycle continue as if the hook had succeeded. Now, this text conflicted with the pre-existing runtime (runc) behavior, and it still conflicts with the current runc behavior. At this point, we can either fix runtimes or the spec. To my mind, fixing the spec is a better approach, because: - initial implementation predates the spec wording by a few years; - the wording in the spec was never implemented (in runc); - returning an error (and stopping the container) seems like a more versatile approach, since a hook can usually choose whether to return an error or not. [1]: opencontainers/runc#392 Signed-off-by: Kir Kolyshkin <[email protected]>
OTOH crun does not kill the container if a poststart hook has failed (and the code is from about 2017). Cc @giuseppe |
the spec behavior is validated by: https://github.com/opencontainers/runtime-tools/blob/master/validation/poststart_fail/poststart_fail.go and that is probably the reason I've implemented it this way for crun. I've no preference on the two behaviors, with the spec behavior the user has more control to decide when to stop the container at the risk of just not seeing/ignoring the warning. The runc behavior instead makes easier to detect when the poststart hook fails, but it terminates the container process once it is already started (is it always safe to do so?) EDIT: yes it is safe as we call the hooks before exec'ing the container init process |
shall we refer k8s poststart https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/ |
@ningmingxiao I think k8s poststart is unrelated. IIRC the post-start is just the kubelet doing an exec in the container. |
This is another thing to fix in spec. It currently says
but practically runc call hooks before exec'ing container init. If crun is doing the same, maybe we should revise the spec. |
I make a test
crun run poststart after user-specified process. because pid is bigger than 2628 |
While you're taking a look at the whole hook situation, you might also want to take a glimpse at #1039. |
I think the same situation also happened in |
@opencontainers/runtime-spec-maintainers PTAL |
Quite agree, the other reason is that maybe we can’t know the user-specified process is really executed successfully because of ‘execve’(of cause we can know it fails). |
Poststart hooks exist in runc since 2015 1, and since that time until today, if a hook returned an error, runc kills the container.
In 2020, commit c166268 (PR #1008) added the following text (which became part of runtime-spec release v1.0.2):
Now, this text conflicted with the pre-existing runtime (runc) behavior, and it still conflicts with the current runc behavior.
At this point, we can either fix runtimes or the spec.
To my mind, fixing the spec is a better approach, because: