Skip to content

Refactor ctr restore to allow for tty allocation#7673

Merged
AkihiroSuda merged 1 commit intocontainerd:mainfrom
turan18:ctr-restore
Dec 6, 2022
Merged

Refactor ctr restore to allow for tty allocation#7673
AkihiroSuda merged 1 commit intocontainerd:mainfrom
turan18:ctr-restore

Conversation

@turan18
Copy link
Copy Markdown
Contributor

@turan18 turan18 commented Nov 15, 2022

ctr container restore restores a container from a specified checkpoint. The newly restored container will have the same Spec as that of the parent container(container which was checkpointed ). If the parent container was started with a new terminal allocated (eg: ctr run -t) its Spec will have {terminal : true}, letting runc know to create a new set of file descriptors for a new pseudoterminal.

The IO for the new container that will be restored is specified via the cio.NewCreator() function which takes in cio.WithStdio as an argument, effectively setting the IO of the new container to be the default OS stdio. The issue happens when attempting to restore a container whom Spec has {terminal: true}. Since no terminal has been allocated to the container (restore only uses os stdio), runc does not have a place to send the file descriptors it creates for the pseudoterminal, thowing the error => cannot allocate tty if runc will detach without setting console socket: unknown

I have refactored ctr container restore to account for tty allocation in the case where the Spec requires a terminal to be set. A lot of the changes mirror what has already been done within ctr run

Fixes: #7672

Signed-off-by: Yasin Turan [email protected]

@k8s-ci-robot
Copy link
Copy Markdown

Hi @turan18. 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.

@kzys
Copy link
Copy Markdown
Member

kzys commented Nov 15, 2022

Comment thread container_restore_opts.go Outdated
}

// Check if the Spec requires a terminal to be allocated -> { terminal: true or false }
func CheckSpecTTY(ctx context.Context, client *Client, desc ocispec.Descriptor) (*bool, error) {
Copy link
Copy Markdown
Member

@dcantah dcantah Nov 16, 2022

Choose a reason for hiding this comment

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

While the intention of your change as a whole was to use this to check if a restored container needs a tty, this file is solely for Restore related opts functions as of now (WithFooBar() NewContainerOpts). Although maybe there's another way to get the info you're after without this altogether

Comment thread cmd/ctr/commands/containers/restore.go Outdated
}

task, err := ctr.NewTask(ctx, cio.NewCreator(cio.WithStdio), topts...)
useTTY, err := containerd.CheckSpecTTY(ctx, client, checkpoint.Target())
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.

Never used the criu support here, but does the container object returned from client.Restore() have its spec filled in as normal? If so could we just check the spec returned from ctr.Spec() and see if terminal is set?

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.

Ugh github didn't select all of the lines I did -_-. I had lines 83-93 selected if that makes the comment easier to parse.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are correct. I have removed the unnecessary call to checkSpecTTY().

@turan18
Copy link
Copy Markdown
Contributor Author

turan18 commented Nov 16, 2022

Your PR description is great. Please copy some to the commit message itself.

https://github.com/containerd/project/blob/main/CONTRIBUTING.md#commit-messages

Got it. Done

@turan18 turan18 requested a review from dcantah November 16, 2022 18:10
Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda AkihiroSuda merged commit 698622b into containerd:main Dec 6, 2022
@turan18 turan18 deleted the ctr-restore branch January 3, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

ctr restore fails

6 participants