Skip to content

Commit 42f778f

Browse files
committed
modify streaming io url form
sandbox address should be in the form of <ttrpc|grpc>+<unix|vsock|hvsock>://<uds-path|vsock-cid:vsock-port|uds-path:hvsock-port> for example: ttrpc+hvsock:///run/test.hvsock:1024 or: grpc+vsock://1111111:1024 and the Stdin/Stdout/Stderr will add a `streaming_id` as a parameter of the url result form is: <ttrpc|grpc>+<unix|vsock|hvsock>://<uds-path|vsock-cid:vsock-port|uds-path:hvsock-port>?streaming_id=<stream-id> for example ttrpc+hvsock:///run/test.hvsock:1024?streaming_id=111111 or grpc+vsock://1111111:1024?streaming_id=222222 Signed-off-by: Abel Feng <[email protected]>
1 parent bfdc224 commit 42f778f

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

internal/cri/io/container_io.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ func WithNewFIFOs(root string, tty, stdin bool) ContainerIOOpts {
7373
}
7474

7575
// WithStreams creates new streams for the container io.
76+
// The stream address is in format of `protocol://address?stream_id=xyz`.
77+
// It allocates ContainerID-stdin, ContainerID-stdout and ContainerID-stderr as streaming IDs.
78+
// For example, that advertiser address of shim is `ttrpc+unix:///run/demo.sock` and container ID is `app`.
79+
// There are three streams if stdin is enabled and TTY is disabled.
80+
//
81+
// - Stdin: ttrpc+unix:///run/demo.sock?stream_id=app-stdin
82+
// - Stdout: ttrpc+unix:///run/demo.sock?stream_id=app-stdout
83+
// - stderr: ttrpc+unix:///run/demo.sock?stream_id=app-stderr
84+
//
85+
// The streaming IDs will be used as unique key to establish stream tunnel.
86+
// And it should support reconnection with the same streaming ID if containerd restarts.
7687
func WithStreams(address string, tty, stdin bool) ContainerIOOpts {
7788
return func(c *ContainerIO) error {
7889
if address == "" {

internal/cri/io/exec_io.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func NewFifoExecIO(id, root string, tty, stdin bool) (*ExecIO, error) {
5555
}
5656

5757
// NewStreamExecIO creates exec io with streaming.
58+
// The stream address is in format of `protocol://address?stream_id=xyz`.
59+
// It allocates ExecID-stdin, ExecID-stdout and ExecID-stderr as streaming IDs.
60+
// For example, that advertiser address of shim is `ttrpc+unix:///run/demo.sock` and exec ID is `app`.
61+
// There are three streams if stdin is enabled and TTY is disabled.
62+
//
63+
// - Stdin: ttrpc+unix:///run/demo.sock?stream_id=app-stdin
64+
// - Stdout: ttrpc+unix:///run/demo.sock?stream_id=app-stdout
65+
// - stderr: ttrpc+unix:///run/demo.sock?stream_id=app-stderr
66+
//
67+
// The streaming IDs will be used as unique key to establish stream tunnel.
68+
// And it should support reconnection with the same streaming ID if containerd restarts.
5869
func NewStreamExecIO(id, address string, tty, stdin bool) (*ExecIO, error) {
5970
fifos, err := newStreams(address, id, tty, stdin)
6071
if err != nil {

internal/cri/io/helpers.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ func newStreams(address, id string, tty, stdin bool) (*cio.FIFOSet, error) {
105105
fifos := cio.NewFIFOSet(cio.Config{}, func() error { return nil })
106106
if stdin {
107107
streamID := id + "-stdin"
108-
fifos.Stdin = fmt.Sprintf("%s/streaming?id=%s", address, streamID)
108+
fifos.Stdin = fmt.Sprintf("%s?streaming_id=%s", address, streamID)
109109
}
110110
stdoutStreamID := id + "-stdout"
111-
fifos.Stdout = fmt.Sprintf("%s/streaming?id=%s", address, stdoutStreamID)
111+
fifos.Stdout = fmt.Sprintf("%s?streaming_id=%s", address, stdoutStreamID)
112112
if !tty {
113113
stderrStreamID := id + "-stderr"
114-
fifos.Stderr = fmt.Sprintf("%s/streaming?id=%s", address, stderrStreamID)
114+
fifos.Stderr = fmt.Sprintf("%s?streaming_id=%s", address, stderrStreamID)
115115
}
116116
fifos.Terminal = tty
117117
return fifos, nil
@@ -209,6 +209,8 @@ func openOutputStream(ctx context.Context, url string) (io.ReadCloser, error) {
209209
}
210210

211211
func openStream(ctx context.Context, urlStr string) (streamingapi.Stream, error) {
212+
// urlStr should be in the form of:
213+
// <ttrpc|grpc>+<unix|vsock|hvsock>://<uds-path|vsock-cid:vsock-port|uds-path:hvsock-port>?streaming_id=<stream-id>
212214
u, err := url.Parse(urlStr)
213215
if err != nil {
214216
return nil, fmt.Errorf("address url parse error: %v", err)
@@ -221,12 +223,7 @@ func openStream(ctx context.Context, urlStr string) (streamingapi.Stream, error)
221223
" the form of <protocol>+<unix|vsock|tcp>, i.e. ttrpc+unix or grpc+vsock")
222224
}
223225

224-
if u.Path != "streaming" {
225-
// TODO, support connect stream other than streaming api
226-
return nil, fmt.Errorf("only <address>/streaming?id=xxx supported")
227-
}
228-
229-
id := u.Query().Get("id")
226+
id := u.Query().Get("streaming_id")
230227
if id == "" {
231228
return nil, fmt.Errorf("no stream id in url queries")
232229
}

0 commit comments

Comments
 (0)