Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Conversation

@Random-Liu
Copy link
Member

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

@Random-Liu Random-Liu force-pushed the add-container-attach branch 2 times, most recently from 208ba89 to 7a0fefd Compare August 12, 2017 00:16
}

// WithContainerIO adds IO into the container.
func WithContainerIO(io *cio.ContainerIO) func(*Container) {
Copy link
Member

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.

Copy link
Member Author

@Random-Liu Random-Liu Aug 14, 2017

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

}

// WithStdin enables stdin of the container io.
func WithStdin(stdin bool) func(*ContainerIO) error {
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

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)
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@Random-Liu Random-Liu force-pushed the add-container-attach branch 3 times, most recently from 94a8607 to 8b6e9d4 Compare August 15, 2017 00:36
stdoutWC = cio.NewDiscardLogger()
stderrWC = cio.NewDiscardLogger()
}

Copy link
Member Author

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.

@miaoyq
Copy link
Member

miaoyq commented Aug 16, 2017

@Random-Liu About io, I think that we can reuse the implementation in containerd instead of implementing it again here, Just a suggestion : )

return c.streamServer.GetAttach(r)
}

func (c *criContainerdService) attach(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser,
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

@Random-Liu
Copy link
Member Author

Random-Liu commented Aug 16, 2017

@Random-Liu About io, I think that we can reuse the implementation in containerd instead of implementing it again here, Just a suggestion : )

The problem is that containerd io doesn't meet our requirement, e.g. tee support. I've made containerd IO an interface containerd/containerd#1343, I'll make our io implement that interface after #113 is merged.

@miaoyq
Copy link
Member

miaoyq commented Aug 17, 2017

@Random-Liu Got it, Thank you for your patience to explain.

@Random-Liu
Copy link
Member Author

Will rebase this PR soon.

@Random-Liu Random-Liu force-pushed the add-container-attach branch from 8b6e9d4 to 4c0d367 Compare August 18, 2017 04:02
@Random-Liu
Copy link
Member Author

@abhinandanpb @mikebrow Rebased, please take a look.

@Random-Liu Random-Liu force-pushed the add-container-attach branch 5 times, most recently from 54ba1de to be449d4 Compare August 21, 2017 18:31
@Random-Liu
Copy link
Member Author

Random-Liu commented Aug 21, 2017

@mikebrow I skipped the golang tip test, because it keeps failing even though golang 1.8.x works. And it didn't fail before, seems like a bug in golang HEAD.

Since #145 will remove golang tip test, I'll remove it in this PR.

Copy link
Member

@mikebrow mikebrow left a 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)

Copy link
Member

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?

Copy link
Member Author

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")
}
}
Copy link
Member

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 :-)

Copy link
Member Author

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. :)

@Random-Liu Random-Liu force-pushed the add-container-attach branch from c095f81 to 8755d8e Compare August 22, 2017 05:37
}
// Also increase wait group here, so that `closer.Wait` will
// also wait for this fifo to be closed.
c.closer.wg.Add(1)
Copy link
Member

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 ?

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

@Random-Liu Random-Liu Aug 23, 2017

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@Random-Liu Random-Liu force-pushed the add-container-attach branch 2 times, most recently from ed9f2a1 to cfba56e Compare August 23, 2017 22:31
@Random-Liu
Copy link
Member Author

@mikebrow @abhinandanpb Replied or addressed comments.

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

/LGTM

@Random-Liu Random-Liu force-pushed the add-container-attach branch from cfba56e to 45ee2e5 Compare August 23, 2017 23:50
@Random-Liu
Copy link
Member Author

Random-Liu commented Aug 23, 2017

Apply LGTM based on #128 (review).

Will merge after test passes.

@Random-Liu Random-Liu merged commit 60c7f51 into containerd:master Aug 24, 2017
@Random-Liu Random-Liu deleted the add-container-attach branch August 24, 2017 00:20
lanchongyizu pushed a commit to lanchongyizu/cri-containerd that referenced this pull request Sep 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants