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

Function StartAttach

pkg/devspace/services/attach/attach.go:60–147  ·  view source on GitHub ↗

StartAttach opens a new terminal

(
	ctx devspacecontext.Context,
	devContainer *latest.DevContainer,
	selector targetselector.TargetSelector,
	stdout io.Writer,
	stderr io.Writer,
	stdin io.Reader,
	parent *tomb.Tomb,
)

Source from the content-addressed store, hash-verified

58
59// StartAttach opens a new terminal
60func StartAttach(
61 ctx devspacecontext.Context,
62 devContainer *latest.DevContainer,
63 selector targetselector.TargetSelector,
64 stdout io.Writer,
65 stderr io.Writer,
66 stdin io.Reader,
67 parent *tomb.Tomb,
68) (err error) {
69 // restart on error
70 defer func() {
71 if err != nil {
72 if ctx.IsDone() {
73 return
74 }
75
76 ctx.Log().Infof("Restarting because: %s", err)
77 select {
78 case <-ctx.Context().Done():
79 return
80 case <-time.After(time.Second * 3):
81 }
82 err = StartAttach(ctx, devContainer, selector, stdout, stderr, stdin, parent)
83 return
84 }
85
86 ctx.Log().Debugf("Stopped attach")
87 }()
88
89 before := log.GetBaseInstance().GetLevel()
90 log.GetBaseInstance().SetLevel(logrus.PanicLevel)
91 defer log.GetBaseInstance().SetLevel(before)
92
93 container, err := selector.WithContainer(devContainer.Container).SelectSingleContainer(ctx.Context(), ctx.KubeClient(), ctx.Log())
94 if err != nil {
95 return err
96 }
97
98 ctx.Log().Infof("Attaching to pod:container %s:%s", ansi.Color(container.Pod.Name, "white+b"), ansi.Color(container.Container.Name, "white+b"))
99 errChan := make(chan error)
100 parent.Go(func() error {
101 interruptpkg.Global.Stop()
102 defer interruptpkg.Global.Start()
103
104 errChan <- ctx.KubeClient().ExecStream(ctx.Context(), &kubectl.ExecStreamOptions{
105 Pod: container.Pod,
106 Container: container.Container.Name,
107 TTY: container.Container.TTY,
108 Stdin: stdin,
109 Stdout: stdout,
110 Stderr: stderr,
111 SubResource: kubectl.SubResourceAttach,
112 })
113 return nil
114 })
115
116 select {
117 case <-ctx.Context().Done():

Callers 1

startAttachMethod · 0.92

Calls 15

GetBaseInstanceFunction · 0.92
IsUnexpectedExitCodeFunction · 0.92
GoMethod · 0.80
IsDoneMethod · 0.65
LogMethod · 0.65
DoneMethod · 0.65
ContextMethod · 0.65
SelectSingleContainerMethod · 0.65
WithContainerMethod · 0.65
KubeClientMethod · 0.65
StopMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected