MCPcopy
hub / github.com/1Panel-dev/KubePi / WaitForTerminal

Function WaitForTerminal

pkg/terminal/shell.go:287–316  ·  view source on GitHub ↗

WaitForTerminal is called from apihandler.handleAttach as a goroutine Waits for the SockJS connection to be opened by the client the session to be Bound in handleTerminalSession

(k8sClient kubernetes.Interface, cfg *rest.Config, namespace string, podName string, containerName string, sessionId string, shell string)

Source from the content-addressed store, hash-verified

285// WaitForTerminal is called from apihandler.handleAttach as a goroutine
286// Waits for the SockJS connection to be opened by the client the session to be Bound in handleTerminalSession
287func WaitForTerminal(k8sClient kubernetes.Interface, cfg *rest.Config, namespace string, podName string, containerName string, sessionId string, shell string) {
288 select {
289 case <-TerminalSessions.Get(sessionId).Bound:
290 close(TerminalSessions.Get(sessionId).Bound)
291
292 var err error
293 validShells := []string{shell}
294
295 if isValidShell(validShells, shell) {
296 cmd := []string{shell}
297 err = startProcess(k8sClient, cfg, cmd, namespace, podName, containerName, TerminalSessions.Get(sessionId))
298 } else {
299 // No shell given or it was not valid: try some shells until one succeeds or all fail
300 // FIXME: if the first shell fails then the first keyboard event is lost
301 for _, testShell := range validShells {
302 cmd := []string{testShell}
303 if err = startProcess(k8sClient, cfg, cmd, namespace, podName, containerName, TerminalSessions.Get(sessionId)); err == nil {
304 break
305 }
306 }
307 }
308
309 if err != nil {
310 TerminalSessions.Close(sessionId, 2, err.Error())
311 return
312 }
313
314 TerminalSessions.Close(sessionId, 1, "Process exited")
315 }
316}
317
318//node shell
319func WaitForNodeShellTerminal(k8sClient kubernetes.Interface, cfg *rest.Config,nodeName string, sessionId string) {

Callers 1

Calls 5

isValidShellFunction · 0.85
startProcessFunction · 0.85
ErrorMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected