-
Notifications
You must be signed in to change notification settings - Fork 606
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
feat: support '--detach-keys' for 'nerdctl (run|start)' #2128
Conversation
@AkihiroSuda PTAL, thanks! |
1b2898a
to
e99afb1
Compare
pkg/consoleutil/detach.go
Outdated
if ds.closed { | ||
return 0, syscall.EBADF | ||
} |
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.
not sure if this condition is relevant here (is it possible to read from already closed (detached) 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.
I think you're right. It turned out IO.Cancel()
doesn't really close the FIFOs (containerd/containerd#8326), so if this check is removed, closer()
will keep being called, and the debug logs (i.e., "Cancelling IO"
and "IO cancelled"
) will overflow my screen. As a result, when term.EscapeError
is detected, I'm returning a non-nil error for now , and I added a TODO to return a nil error afrer the issue is fixed and before this PR can be merged.
pkg/consoleutil/detach.go
Outdated
closed bool | ||
} | ||
|
||
// NewDetachableStdin returns a new TTY proxy reader |
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.
NewDetachableStdin returns a new detachableStdin
which uses a TTY proxy reader to read specified detach keys from stdin, in which case closer will be called
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.
Hmm, I'm not sure if we want to mention the underlying unexported struct here, maybe the users of this function shouldn't need to know that implementation detail?
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.
LGTM, but just one thing was confusing me : NewDetachableStdin returns a new TTY proxy reader
. In fact the NewDetachableStdin
is not returning a TTY proxy reader but it is wrapping a a TTY proxy reader
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.
Ah you're right! Updated the comment accordingly, plz let me know if it works for you :)
|
After we detach from a container, we should be able to reattach to it again. Docker: ➜ ~ docker attach test
/ #
/ #
/ # read escape sequence
➜ ~ docker attach test
/ #
/ #
/ # read escape sequence |
1305692
to
585588c
Compare
585588c
to
d81485a
Compare
8047c15
to
cce73c3
Compare
cce73c3
to
cc33276
Compare
@fahedouch Thanks a lot for the quick review! In the new revision, besides addressing the comments, I also made it print |
cc33276
to
4314ef7
Compare
The latest revision: If I davidhyc@lima-dev:/Users/davidhyc/dev/containerd/nerdctl$ ./_output/nerdctl run -it --name detach busybox
/ #
/ # INFO[0001] read detach keys
davidhyc@lima-dev:/Users/davidhyc/dev/containerd/nerdctl$ nerdctl ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd3b77abf607 docker.io/library/busybox:latest "sh" 4 seconds ago Up detach |
a723f80
to
2a7d60c
Compare
please see |
Needs rebase |
@AkihiroSuda Thank you for the reminder. Could you help take a look at containerd/containerd#8326 and/or containerd/containerd#8334? I'll rebase the feature branch after the blocker is resolved, thanks! |
a0635be
to
8e25eae
Compare
@fahedouch PTAL, thanks! The failed jobs seem to be flaky as all the jobs pass at least once: |
go.mod
Outdated
@@ -57,12 +58,14 @@ require ( | |||
golang.org/x/term v0.8.0 | |||
golang.org/x/text v0.9.0 | |||
gopkg.in/yaml.v3 v3.0.1 | |||
gotest.tools v2.2.0+incompatible | |||
gotest.tools/v3 v3.4.0 |
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.
Can we avoid mixing up v2 and v3?
go.mod
Outdated
@@ -37,6 +37,7 @@ require ( | |||
github.com/mitchellh/mapstructure v1.5.0 | |||
github.com/moby/sys/mount v0.3.3 | |||
github.com/moby/sys/signal v0.7.0 | |||
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 |
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.
Control flow: 1. Detect if the detach keys are present in stdin. 2. After detecting the detach keys, cancel the current I/O operations by calling IO.Cancel(). This means that the underlying I/O FIFOs should be left intact, and containerd should keep writing to/reading from those FIFOs, but nerdctl should stop writing to/reading from them. 3. After starting the task, we need to call IO.Wait(), and after it returns, we need to see if the container exits or it's just the user detaching from the container by checking the state of the container. Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
8e25eae
to
ec49140
Compare
@AkihiroSuda Thanks for the reminder. Both are fixed. |
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.
Thanks
Control Flow
cio.IO.Cancel()
should be used for this, but there's an issue:IO.Cancel()
becomes a no-op if the FIFOs are already opened containerd#8326.IO.Wait
, and after it returns, we need to see if the container exits or it's just the user detaching from the container by checking the state of the container.Notes
nerdctl exec --detach-keys
in a follow-up PR so that we can minimize the changes needed in this PR as the control flow of it is a bit different from that ofrun|start
.TODOs
Before this PR can be merged, I need to:
temporarily use the containerd feature branch
commit and use the released containerd version.