Skip to content

libpod: Execute poststop hooks locally #864

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

Closed
wants to merge 1 commit into from

Conversation

wking
Copy link
Contributor

@wking wking commented May 31, 2018

Builds on #857, review that first.

Execute the poststop hooks ourselves instead of delegating to the runtime, since some runtimes do not seem to handle these reliably.

This may be enough for #730, but I'm not sure.

Also, while the hooks package is well-covered by unit tests and this pull requests adds unit tests for Container.postDeleteHooks, we don't seem to have integration tests exercising the whole system. fdcf633 (#155) added a hook test, but its fileutils.CopyFile call has no error checking and (as far as I can see) no source hooks.json to copy. I expect we want to patch up that test, but I'm leaving it to follow-up (or parallel) work.

@wking wking force-pushed the local-post-delete-hooks branch from 21c986e to af512d0 Compare May 31, 2018 20:44
@wking
Copy link
Contributor Author

wking commented May 31, 2018

Hey, cloud Podman is actually happy for once :). Too bad I'll have to rebase after #857 lands :p.

@wking wking force-pushed the local-post-delete-hooks branch from af512d0 to cc81973 Compare May 31, 2018 22:36
@wking
Copy link
Contributor Author

wking commented May 31, 2018

#857 landed, so I've rebased this onto master.

@@ -552,6 +554,11 @@ func (c *Container) reinit(ctx context.Context) error {
if err := c.runtime.ociRuntime.deleteContainer(c); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

@wking It might be worth making a wrapper for this that calls deleteContainer() and then postDeleteHooks(), given that we want to always call postrun hooks deleting the container in runc.

@wking wking force-pushed the local-post-delete-hooks branch from cc81973 to ac567d6 Compare June 1, 2018 14:26
@wking
Copy link
Contributor Author

wking commented Jun 1, 2018

I've pushed cc819730 -> ac567d6b with a rebase onto master and a delete wrapper.

@mheon
Copy link
Member

mheon commented Jun 1, 2018

Test failures are infra issues

@rhatdan
Copy link
Member

rhatdan commented Jun 1, 2018

Rebase please

Instead of delegating to the runtime, since some runtimes do not seem
to handle these reliably [1].

[1]: containers#730 (comment)

Signed-off-by: W. Trevor King <[email protected]>
@wking wking force-pushed the local-post-delete-hooks branch from ac567d6 to 31dead9 Compare June 1, 2018 20:25
@wking
Copy link
Contributor Author

wking commented Jun 1, 2018

Rebase please

Rebased with ac567d6b -> 31dead9 (no conflicts).

@rhatdan
Copy link
Member

rhatdan commented Jun 2, 2018

@mheon PTAL

@mheon
Copy link
Member

mheon commented Jun 2, 2018

I have a few concerns around ordering - do poststop hooks need to execute while the container is still mounted? If they do, we might want to move delete earlier in the process for container and pod removal.

@rhatdan
Copy link
Member

rhatdan commented Jun 3, 2018

Yes I think poststop should be run while the container storage is intact.

It looks like oci-systemd-hook is removing ROOTFS/etc/machine-id. (Not sure why this is necessary.)

oci-register-machine unregistered (Sent a dbus message) the container with systemd-machinectl, but we are removing this hook. It causes much more problems then it is worth.

oci-umount does not do poststop.

I am a little surprised at how little we do in poststop.

@wking
Copy link
Contributor Author

wking commented Jun 4, 2018

I have a few concerns around ordering - do poststop hooks need to execute while the container is still mounted?

The spec requires poststop hooks to run after deletion, so I think the timing of these is correct as this PR stands. If you want hooks that fire before deletion, I think we need to use an extension stage. We've talked about a postexit stage to fire from conmon after the container process exits. And you could also add a predelete extension stage to fire right before we call the OCI runtime's delete. However, there are potential compatibility issues with a host-scoped hook directory containing package-scoped extension stages, so we may need to move to package-scoped hook directories if we add those. In the meantime, this PR implements the OCI-defined semantics for poststop.

@rhatdan
Copy link
Member

rhatdan commented Jun 4, 2018

Pk. Lets merge
@rh-atomic-bot r+

@rh-atomic-bot
Copy link
Collaborator

📌 Commit 31dead9 has been approved by rhatdan

@mheon
Copy link
Member

mheon commented Jun 4, 2018

@wking I'm mostly concerned about ordering relative to us unmounting the container's storage. I don't believe the OCI spec mandates when that will happen, and there may be hooks that assume that the container's root filesystem is still accessible at this stage. If so, we may want to move the deletion phase earlier in removeContainer() where we can guarantee there is still a mounted root filesystem.

@wking
Copy link
Contributor Author

wking commented Jun 4, 2018

I'm mostly concerned about ordering relative to us unmounting the container's storage. I don't believe the OCI spec mandates when that will happen...

Right, it just talks about deleting resources allocated during create.

... and there may be hooks that assume that the container's root filesystem is still accessible at this stage.

Why would you want to run a hook after delete if the hook required the container mounts to still exist? I expect that those hooks should be moved to the postexit or predelete extension stages discussed above. If, for some reason, you really do want access to the container filesystem post-delete, you could hack that in by bind-mounting the mount namespace in a prestart or poststart hook, and then removing your bind mount in a poststop hook (firing after delete). Or you could launch a process in that mount namespace to hold it open after the container process executes. But both of those seem like more work than adding an extension stage that fires between the container-process exit and delete and moving the hooks to that extension stage. Also, holding a mount namespace open will work with runc, but it's probably not going to help you out with VM-based containers, etc.

@rh-atomic-bot
Copy link
Collaborator

⌛ Testing commit 31dead9 with merge c9f7634...

@mheon
Copy link
Member

mheon commented Jun 4, 2018

@wking Fair enough - it does sound rather unreasonable to expect container resources to still exist after deletion. This does make things simpler for us, too.

@rh-atomic-bot
Copy link
Collaborator

☀️ Test successful - status-papr
Approved by: rhatdan
Pushing c9f7634 to master...

@wking wking deleted the local-post-delete-hooks branch June 4, 2018 22:08
@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 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 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 this pull request may close these issues.

4 participants