StartAttachFromCMD opens a new terminal
(ctx devspacecontext.Context, selector targetselector.TargetSelector)
| 21 | |
| 22 | // StartAttachFromCMD opens a new terminal |
| 23 | func StartAttachFromCMD(ctx devspacecontext.Context, selector targetselector.TargetSelector) error { |
| 24 | container, err := selector.SelectSingleContainer(ctx.Context(), ctx.KubeClient(), ctx.Log()) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | |
| 29 | if !container.Container.TTY || !container.Container.Stdin { |
| 30 | ctx.Log().Warnf("To be able to interact with the container its options tty (currently `%t`) and stdin (currently `%t`) must both be `true`", container.Container.TTY, container.Container.Stdin) |
| 31 | } |
| 32 | |
| 33 | ctx.Log().Infof("Attaching to pod:container %s:%s", ansi.Color(container.Pod.Name, "white+b"), ansi.Color(container.Container.Name, "white+b")) |
| 34 | ctx.Log().Info("If you don't see a command prompt, try pressing enter.") |
| 35 | |
| 36 | done := make(chan error) |
| 37 | go func() { |
| 38 | done <- ctx.KubeClient().ExecStream(ctx.Context(), &kubectl.ExecStreamOptions{ |
| 39 | Pod: container.Pod, |
| 40 | Container: container.Container.Name, |
| 41 | TTY: container.Container.TTY, |
| 42 | Stdin: os.Stdin, |
| 43 | Stdout: os.Stdout, |
| 44 | Stderr: os.Stderr, |
| 45 | SubResource: kubectl.SubResourceAttach, |
| 46 | }) |
| 47 | }() |
| 48 | |
| 49 | // wait until either client has finished or we got interrupted |
| 50 | select { |
| 51 | case <-ctx.Context().Done(): |
| 52 | <-done |
| 53 | return nil |
| 54 | case err := <-done: |
| 55 | return err |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // StartAttach opens a new terminal |
| 60 | func StartAttach( |
no test coverage detected