-
Notifications
You must be signed in to change notification settings - Fork 347
Add container attach #128
Add container attach #128
Conversation
208ba89 to
7a0fefd
Compare
pkg/store/container/container.go
Outdated
| } | ||
|
|
||
| // WithContainerIO adds IO into the container. | ||
| func WithContainerIO(io *cio.ContainerIO) func(*Container) { |
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.
It 's better if func(*Container) could be defined as a type.
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.
Will do.
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.
Done.
pkg/server/io/io.go
Outdated
| } | ||
|
|
||
| // WithStdin enables stdin of the container io. | ||
| func WithStdin(stdin bool) func(*ContainerIO) error { |
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.
Define func(*ContainerIO) error as a type
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.
Will do.
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.
Done.
|
|
||
| var stdinCloser io.Closer | ||
| if c.stdinPath != "" && stdin != nil { | ||
| f, err := fifo.OpenFifo(c.closer.ctx, c.stdinPath, syscall.O_WRONLY|syscall.O_NONBLOCK, 0700) |
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.
Make sure c.closer != nil
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.
Good catch! Will do.
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.
Done.
94a8607 to
8b6e9d4
Compare
pkg/server/container_start.go
Outdated
| stdoutWC = cio.NewDiscardLogger() | ||
| stderrWC = cio.NewDiscardLogger() | ||
| } | ||
|
|
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.
Close if there is error.
|
@Random-Liu About |
pkg/server/container_attach.go
Outdated
| return c.streamServer.GetAttach(r) | ||
| } | ||
|
|
||
| func (c *criContainerdService) attach(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser, |
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.
Rename attach to attachContainer , like execInContainer, to avoid confusion with io.attach
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.
Will do.
The problem is that containerd io doesn't meet our requirement, e.g. |
|
@Random-Liu Got it, Thank you for your patience to explain. |
|
Will rebase this PR soon. |
8b6e9d4 to
4c0d367
Compare
|
@abhinandanpb @mikebrow Rebased, please take a look. |
54ba1de to
be449d4
Compare
mikebrow
left a comment
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.
halfway through review will get to the rest in the morn..
| assert.Equal(t, len(data), n) | ||
| assert.Equal(t, data, original.buf.String()) | ||
| assert.NoError(t, err) | ||
|
|
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.
maybe use another thread here to test the wait function?
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.
Why another thread is required? One thread seems more deterministic here.
| default: | ||
| assert.Fail(t, "write closer not closed") | ||
| } | ||
| } |
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.
no-op test for the no-op write closer :-)
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.
We mainly want to test WriteCloseInformer will close the inform channel when it is closed. And the test proves that it does. :)
c095f81 to
8755d8e
Compare
| } | ||
| // Also increase wait group here, so that `closer.Wait` will | ||
| // also wait for this fifo to be closed. | ||
| c.closer.wg.Add(1) |
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.
is there a corresponding Wait for this waitgroup ? Or is the closer implicitly waiting on this wg ?
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.
Yeah, ContainerIO.Close will wait for this. This makes sure that ContainerIO.Close won't remove the fifo directory when Attach is still using the stdin pipe.
|
|
||
| // Close stdin after first attach if StdinOnce is specified. | ||
| if cntr.Config.StdinOnce { | ||
| task.CloseIO(ctx, containerd.WithStdinCloser) |
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.
If StdinOnce is not specified when is the IO closed ? May be worth adding a comment as well.
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.
The IO will never close until the container dies, will add comment.
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.
Done.
ed9f2a1 to
cfba56e
Compare
|
@mikebrow @abhinandanpb Replied or addressed comments. |
mikebrow
left a comment
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
Signed-off-by: Lantao Liu <[email protected]>
Signed-off-by: Lantao Liu <[email protected]>
cfba56e to
45ee2e5
Compare
|
Apply LGTM based on #128 (review). Will merge after test passes. |
Add container attach
This PR added container attach support in cri-containerd, and also enabled the test.
The attach code is really error prone, so please pay extra attention to see whether there is goroutine leakage or deadlock.
@kubernetes-incubator/maintainers-cri-containerd