(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize)
| 46 | } |
| 47 | |
| 48 | func (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 | } |
no test coverage detected