MCPcopy Index your code
hub / github.com/devspace-sh/devspace / StartAttachFromCMD

Function StartAttachFromCMD

pkg/devspace/services/attach/attach.go:23–57  ·  view source on GitHub ↗

StartAttachFromCMD opens a new terminal

(ctx devspacecontext.Context, selector targetselector.TargetSelector)

Source from the content-addressed store, hash-verified

21
22// StartAttachFromCMD opens a new terminal
23func 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
60func StartAttach(

Callers 1

RunMethod · 0.92

Calls 9

SelectSingleContainerMethod · 0.65
ContextMethod · 0.65
KubeClientMethod · 0.65
LogMethod · 0.65
ExecStreamMethod · 0.65
DoneMethod · 0.65
WarnfMethod · 0.45
InfofMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected