Skip to content

Add new snapshots command in ctr for getting an image's snapshot layer mounts#4797

Closed
katiewasnothere wants to merge 1 commit intocontainerd:masterfrom
katiewasnothere:image_layer_mounts
Closed

Add new snapshots command in ctr for getting an image's snapshot layer mounts#4797
katiewasnothere wants to merge 1 commit intocontainerd:masterfrom
katiewasnothere:image_layer_mounts

Conversation

@katiewasnothere
Copy link
Copy Markdown

@katiewasnothere katiewasnothere commented Dec 3, 2020

This PR adds a new command to ctr's snapshot commands for retrieving the snapshot mounts of an image from a given snapshotter on a given platform. Adding this utility to the snapshot commands makes it clear what the purpose is and what the caller's responsibilities are (iow cleaning up the snapshot).

This new command is helpful for functional/unit tests in shims because it allows users to retrieve the layer mounts that would be used for creating a new container. Users can then manipulate or use these layer mounts as needed to test specific scenarios.

As an example, in https://github.com/microsoft/hcsshim we have a functional tests package for unit testing here. However, in order for us to unit test our shim, we must manually start a container or VM with an image's layer mounts. We're currently relying on an older docker command as seen here to retrieve those. This PR would replace the out of date docker command.

Signed-off-by: Kathryn Baldauf [email protected]

@k8s-ci-robot
Copy link
Copy Markdown

Hi @katiewasnothere. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@katiewasnothere
Copy link
Copy Markdown
Author

@kevpar @ambarve @dcantah @anmaxvl fyi

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 3, 2020

Build succeeded.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 3, 2020

Build succeeded.

Comment thread cmd/ctr/commands/images/mounts.go Outdated
@ambarve
Copy link
Copy Markdown
Contributor

ambarve commented Dec 4, 2020

I think having two commands with such similar names but different purpose can be confusing and also doesn't follow the convention. For example, with ctr snapshotter mount and mounts are just aliases for the same command. I think the better approach is to add a new --list-only flag to the image mount command. What do you think?

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Dec 4, 2020

Agree here, --list-only or --dry-run on the mount command. Or a combination like --show --dry-run... or always show the mounts and add --dry-run.

Comment thread cmd/ctr/commands/images/mounts.go Outdated
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 4, 2020

Build succeeded.

Comment thread cmd/ctr/commands/images/mount.go Outdated
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 8, 2020

Build succeeded.

@katiewasnothere katiewasnothere changed the title Add new images command in ctr for getting an image's layer mounts Add new snapshots command in ctr for getting an image's snapshot layer mounts Dec 9, 2020
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 9, 2020

Build succeeded.

@katiewasnothere
Copy link
Copy Markdown
Author

@ambarve @cpuguy83 I reworked this PR to instead make a new command in the list of snapshots commands. I've updated the title and the description. @ambarve and I were discussing the previous design and we decided that what the goal of my changes were just weren't very compatible with that route. Particularly around the "dry-run" and side effects. This new design makes it more clear what's going on and what work the caller needs to do to clean up or not. It also avoids any complications with the Mount.All command on different platforms (ex: getting the snapshots for a linux image on windows).

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 9, 2020

Build succeeded.

Comment thread cmd/ctr/commands/snapshots/snapshots.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it might be okay to make this a required parameter just like the prepare command. Unless there is a specific use case where we don't care about the key with which the snapshot is created.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah that might be a good idea so that we can make sure people know what key to remove later

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done :)

Comment thread cmd/ctr/commands/snapshots/snapshots.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should provide the option of creating a read-only (View) snapshot too. We can add a --read-only flag for the command.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done :)

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Dec 11, 2020

Build succeeded.

ArgsUsage: "[flags] <key> <image name>",
Description: `Creates a new snapshot from a specified image.

When you're done, use the remove command.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We already have prepareCommand and viewCommand for creating snapshots. Would it make sense to extend those instead? This one seems like does the same, but offers more CLI flags.

@katiewasnothere
Copy link
Copy Markdown
Author

We already have prepareCommand and viewCommand for creating snapshots. Would it make sense to extend those instead? This one seems like does the same, but offers more CLI flags.

I thought about that too, but I'm not sure how much we're okay with changing the expectations for those commands. The goal of this new command is really to take an image name, like "docker.io/library/alpine:latest", and get a new snapshot created with the mounts printed to stdout. Prepare and View both start out with image key and optionally the chain ID of the parent. I think there could be some refactoring done, but I'm not sure if it would make sense to try to merge them together. Thoughts?

@mxpv
Copy link
Copy Markdown
Member

mxpv commented Dec 11, 2020

My thinking is that the proposed function is basically a superset of pull + prepare/view.

Pull already fetches/unpacks the image with respect to platform, the only missing piece is --print-chainid
That chain id can be then passed to prepare/view as a parent, mounts are already printed as well.

@katiewasnothere
Copy link
Copy Markdown
Author

@mxpv that sounds reasonable to me. In that case, I'll close this PR and open a new one with the suggested change instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants