Documentation ¶
Index ¶
Constants ¶
const (
END_OF_TRANSMISSION = "\u0004"
)
Variables ¶
var TerminalSessions = SessionMap{Sessions: make(map[string]TerminalSession)}
TerminalSessions is a global variable that is used to manage all terminal sessions.
Functions ¶
func GenTerminalSessionId ¶
GenTerminalSessionId generates a random session ID string. This ID is used to identify the session when the client opens the WebSocket connection.
func HandleTerminalSession ¶
HandleTerminalSession is called for binding any new connections.
func WaitForTerminal ¶
func WaitForTerminal(k8sClient kubernetes.Interface, cfg *rest.Config, clusterName, namespaceName, podName, containerName, shell, sessionId string, logger *zap.Logger)
WaitForTerminal is called from capp controller as a goroutine. Waits for the WebSocket connection to be opened by the client the session to be Bound in handleTerminalSession. After the session is bound, it manages the session by opening the stream and closing it in case of an error or timeout.
Types ¶
type PtyHandler ¶
type PtyHandler interface { io.Reader io.Writer remotecommand.TerminalSizeQueue }
PtyHandler is what remotecommand expects from a pty.
type SessionMap ¶
type SessionMap struct { Sessions map[string]TerminalSession Lock sync.RWMutex }
SessionMap stores a map of all TerminalSession objects and a lock to avoid concurrent conflict.
func (*SessionMap) Close ¶
func (sm *SessionMap) Close(sessionId string)
Close shuts down the WebSocket connection. Can happen if the process exits or if there is an error starting up the process
func (*SessionMap) Get ¶
func (sm *SessionMap) Get(sessionId string) TerminalSession
Get returns a given terminalSession by sessionId.
func (*SessionMap) Set ¶
func (sm *SessionMap) Set(sessionId string, session TerminalSession)
Set stores a TerminalSession to the SessionMap.
type TerminalMessage ¶
TerminalMessage is the messaging protocol between the Client and the TerminalSession.
OP DIRECTION FIELD(S) USED DESCRIPTION --------------------------------------------------------------------- bind fe->be SessionID Id sent back from TerminalResponse stdin fe->be Data Keystrokes/paste buffer resize fe->be Rows, Cols New terminal_utils size stdout be->fe Data Output from the process toast be->fe Data OOB message to be shown to the user
type TerminalSession ¶
type TerminalSession struct { Id string Bound chan error WebSocket *websocket.Conn SizeChan chan remotecommand.TerminalSize }
TerminalSession implements PtyHandler (using a WebSocket connection) This is the object that is used to communicate with container terminal.
func (TerminalSession) Next ¶
func (t TerminalSession) Next() *remotecommand.TerminalSize
Next handles pty->process resize events Called in a loop from remotecommand as long as the process is running
func (TerminalSession) Read ¶
func (t TerminalSession) Read(p []byte) (int, error)
Read handles pty->process messages (stdin, resize) Called in a loop from remotecommand as long as the process is running
func (TerminalSession) Toast ¶
func (t TerminalSession) Toast(p string) error
Toast can be used to send the user any OOB messages. (OOB -messages are non-standard messages or notifications sent outside the main communication channel.) hterm puts these in the center of the terminal_utils