Skip to content

Commit bcc68db

Browse files
committed
Merge branch 'master' of https://github.com/mintoolkit/mint
2 parents 3986d94 + b059444 commit bcc68db

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

pkg/app/master/command/debug/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Volume struct {
3232
}
3333

3434
type CommandParams struct {
35-
KubeComm *KubernetesHandlerComm
35+
RuntimeCommunicator *RuntimeCommunicator
3636
/// the runtime environment type
3737
Runtime string
3838
/// the running container which we want to attach to

pkg/app/master/command/debug/handle_docker_runtime.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,18 @@ func HandleDockerRuntime(
181181
}
182182

183183
//todo: need to validate that the session container exists and it's running
184-
185-
r, w := io.Pipe()
186-
go io.Copy(w, os.Stdin)
184+
var input io.Reader
185+
if commandParams.TUI {
186+
input = &TUIReader{inputChan: commandParams.RuntimeCommunicator.InputChan}
187+
} else {
188+
r, w := io.Pipe()
189+
input = r
190+
go io.Copy(w, os.Stdin)
191+
}
187192

188193
options := dockerapi.AttachToContainerOptions{
189194
Container: containerID,
190-
InputStream: r,
195+
InputStream: input,
191196
OutputStream: os.Stdout,
192197
ErrorStream: os.Stderr,
193198
Stdin: true,
@@ -252,6 +257,15 @@ func HandleDockerRuntime(
252257
Terminal: commandParams.DoTerminal,
253258
}
254259

260+
if commandParams.TUI {
261+
reader := &TUIReader{inputChan: commandParams.RuntimeCommunicator.InputChan}
262+
options.IO = container.ExecutionIO{
263+
Input: reader,
264+
Output: os.Stdout,
265+
Error: os.Stderr,
266+
}
267+
}
268+
255269
exe, err := container.NewExecution(
256270
xc,
257271
logger,

pkg/app/master/command/debug/handle_kubernetes_runtime.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ func HandleKubernetesRuntime(
819819
fmt.Printf("\n")
820820
//note: blocks until done streaming or failure...
821821
if commandParams.TUI {
822-
// TODO - move KubeComm off of command params
823-
reader := &KubeReader{inputChan: commandParams.KubeComm.InputChan}
822+
// TODO - move RuntimeCommunicator off of command params
823+
reader := &TUIReader{inputChan: commandParams.RuntimeCommunicator.InputChan}
824824
err = attach.StreamWithContext(
825825
ctx,
826826
remotecommand.StreamOptions{
@@ -862,16 +862,16 @@ func HandleKubernetesRuntime(
862862
// as per the comment in `debug/tui.go`.
863863
// An InputReader usable by Docker, Podman, Kubernetes, and Containerd
864864
// will be added to this directory.
865-
type KubeReader struct {
865+
type TUIReader struct {
866866
inputChan chan InputKey
867867
}
868868

869-
func (kr *KubeReader) Read(p []byte) (n int, err error) {
870-
inputKey, ok := <-kr.inputChan
869+
func (tuiReader *TUIReader) Read(p []byte) (n int, err error) {
870+
inputKey, ok := <-tuiReader.inputChan
871871
if !ok {
872872
return 0, io.EOF
873873
}
874-
log.Debugf("KubeReader received inputKey %v", inputKey)
874+
log.Debugf("TUIReader received inputKey %v", inputKey)
875875
switch inputKey.Special {
876876
case NotSpecial:
877877
p[0] = byte(inputKey.Rune)

pkg/app/master/command/debug/tui.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type TUI struct {
3838
// Handle kubernetes session connections
3939
subscriptionHandler subscriptionHandler
4040
isListening bool
41-
kubeComm *KubernetesHandlerComm
41+
runtimeCommunicator *RuntimeCommunicator
4242
exitedSession bool
4343
}
4444

@@ -94,15 +94,15 @@ type subscriptionHandler struct {
9494
}
9595

9696
// newSubscription creates a new subscription handler with an async data channel
97-
func newSubscription(gcvalues *command.GenericParams, kubeComm *KubernetesHandlerComm) subscriptionHandler {
97+
func newSubscription(gcvalues *command.GenericParams, runtimeCommunicator *RuntimeCommunicator) subscriptionHandler {
9898
dataChan := make(chan terminalStartMessage)
99-
go launchSessionHandler(dataChan, gcvalues, kubeComm)
99+
go launchSessionHandler(dataChan, gcvalues, runtimeCommunicator)
100100
return subscriptionHandler{
101101
dataChan: dataChan,
102102
}
103103
}
104104

105-
func launchSessionHandler(dataChan chan terminalStartMessage, gcvalues *command.GenericParams, kubeComm *KubernetesHandlerComm) {
105+
func launchSessionHandler(dataChan chan terminalStartMessage, gcvalues *command.GenericParams, runtimeCommunicator *RuntimeCommunicator) {
106106
// Create a subscription channel and define subscriptionChannels map for passing data
107107
subscriptionChannel := make(chan interface{})
108108
subscriptionChannels := map[string]chan interface{}{
@@ -117,21 +117,34 @@ func launchSessionHandler(dataChan chan terminalStartMessage, gcvalues *command.
117117
subscriptionChannels,
118118
)
119119

120-
// Define command parameters for k8s runtime
120+
// Define command parameters for docker runtime
121121
// + Hard coded values at the moment for this PoC
122122
cparams := &CommandParams{
123-
Runtime: "k8s",
124-
TargetRef: "nginx",
125-
Kubeconfig: crt.KubeconfigDefault,
126-
TargetNamespace: "default",
123+
Runtime: "docker",
124+
TargetRef: "docker-amor",
127125
DebugContainerImage: BusyboxImage,
128126
DoFallbackToTargetUser: true,
129127
DoRunAsTargetShell: true,
130128
DoTerminal: true,
131-
KubeComm: kubeComm,
129+
RuntimeCommunicator: runtimeCommunicator,
132130
TUI: true,
133131
}
134132

133+
// Connect to active session | Kubernetes session
134+
// cparams := &CommandParams{
135+
// Runtime: "docker",
136+
// TargetRef: "docker-amor",
137+
// // Kubeconfig: crt.KubeconfigDefault,
138+
// // TargetNamespace: "default",
139+
// DebugContainerImage: BusyboxImage,
140+
// DoFallbackToTargetUser: true,
141+
// DoRunAsTargetShell: true,
142+
// DoTerminal: true,
143+
// RuntimeCommunicator: runtimeCommunicator,
144+
// TUI: true,
145+
// ActionConnectSession: true,
146+
// }
147+
135148
// TODO - Pass runtime communicator
136149
go OnCommand(xc, gcvalues, cparams)
137150

@@ -160,7 +173,7 @@ func launchSessionHandler(dataChan chan terminalStartMessage, gcvalues *command.
160173
if infoValue, exists := channelResponse["info"]; exists {
161174
if infoValue == "terminal.start" {
162175
dataChan <- terminalStartMessage("Session ready. Opening session below...\nPress esc to exit session.\n")
163-
kubeComm.InputChan <- InputKey{Special: Enter}
176+
runtimeCommunicator.InputChan <- InputKey{Special: Enter}
164177
}
165178
}
166179
}
@@ -198,7 +211,7 @@ func InitialTUI(standalone bool, gcvalues *command.GenericParams) *TUI {
198211
// This handler should not live on CommandParams,
199212
// but be passed in to OnCommand, then to the respective
200213
// runtime handler.
201-
type KubernetesHandlerComm struct {
214+
type RuntimeCommunicator struct {
202215
InputChan chan InputKey
203216
}
204217

@@ -348,7 +361,7 @@ func (m TUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
348361
}
349362

350363
select {
351-
case m.kubeComm.InputChan <- inputKey:
364+
case m.runtimeCommunicator.InputChan <- inputKey:
352365
// Key sent successfully
353366
default:
354367
// Channel is full or closed, handle accordingly
@@ -390,11 +403,11 @@ func (m TUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
390403
// this can be done by rendering state output,
391404
m.isListening = true
392405
log.Debug("Start listening")
393-
kubeComm := &KubernetesHandlerComm{
406+
runtimeCommunicator := &RuntimeCommunicator{
394407
InputChan: make(chan InputKey, 100),
395408
}
396-
m.kubeComm = kubeComm
397-
m.subscriptionHandler = newSubscription(m.gcvalues, kubeComm)
409+
m.runtimeCommunicator = runtimeCommunicator
410+
m.subscriptionHandler = newSubscription(m.gcvalues, runtimeCommunicator)
398411
return m, listenToAsyncData(m.subscriptionHandler.dataChan)
399412

400413
}

pkg/app/master/container/execution.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,18 @@ func (ref *Execution) monitorSysExitSync() {
530530
}
531531

532532
func (ref *Execution) startTerminal() {
533-
r, w := io.Pipe()
534-
go io.Copy(w, os.Stdin)
533+
var input io.Reader
534+
if ref.options.IO.Input == nil {
535+
r, w := io.Pipe()
536+
input = r
537+
go io.Copy(w, os.Stdin)
538+
} else {
539+
input = ref.options.IO.Input
540+
}
541+
535542
options := dockerapi.AttachToContainerOptions{
536543
Container: ref.ContainerID,
537-
InputStream: r,
544+
InputStream: input,
538545
OutputStream: os.Stdout,
539546
ErrorStream: os.Stderr,
540547
Stdin: true,

0 commit comments

Comments
 (0)