MCPcopy Index your code
hub / github.com/containerd/containerd / attachContainer

Method attachContainer

internal/cri/server/container_attach.go:48–87  ·  view source on GitHub ↗
(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser,
	tty bool, resize <-chan remotecommand.TerminalSize)

Source from the content-addressed store, hash-verified

46}
47
48func (c *criService) attachContainer(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser,
49 tty bool, resize <-chan remotecommand.TerminalSize) error {
50 ctx, cancel := context.WithCancel(ctx)
51 defer cancel()
52 // Get container from our container store.
53 cntr, err := c.containerStore.Get(id)
54 if err != nil {
55 return fmt.Errorf("failed to find container %q in store: %w", id, err)
56 }
57 id = cntr.ID
58
59 state := cntr.Status.Get().State()
60 if state != runtime.ContainerState_CONTAINER_RUNNING {
61 return fmt.Errorf("container is in %s state", criContainerStateToString(state))
62 }
63
64 task, err := cntr.Container.Task(ctx, nil)
65 if err != nil {
66 return fmt.Errorf("failed to load task: %w", err)
67 }
68 handleResizing(ctx, resize, func(size remotecommand.TerminalSize) {
69 if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
70 log.G(ctx).WithError(err).Errorf("Failed to resize task %q console", id)
71 }
72 })
73
74 opts := cio.AttachOptions{
75 Stdin: stdin,
76 Stdout: stdout,
77 Stderr: stderr,
78 Tty: tty,
79 StdinOnce: cntr.Config.StdinOnce,
80 CloseStdin: func() error {
81 return task.CloseIO(ctx, containerd.WithStdinCloser)
82 },
83 }
84 // TODO(random-liu): Figure out whether we need to support historical output.
85 cntr.IO.Attach(ctx, opts)
86 return nil
87}

Callers 1

AttachMethod · 0.80

Implementers 1

criServiceinternal/cri/server/service.go

Calls 8

handleResizingFunction · 0.85
GetMethod · 0.65
StateMethod · 0.65
TaskMethod · 0.65
ResizeMethod · 0.65
CloseIOMethod · 0.65
AttachMethod · 0.45

Tested by

no test coverage detected