From 1739d5ec160a15164e98783f10224333f171cfb8 Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Tue, 10 Dec 2024 01:44:23 +0200 Subject: [PATCH] Check if tty is actually used and support proper output when it's not --- plugins/scheduler-k3s/k8s.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/scheduler-k3s/k8s.go b/plugins/scheduler-k3s/k8s.go index bcae90030..38b6522f7 100644 --- a/plugins/scheduler-k3s/k8s.go +++ b/plugins/scheduler-k3s/k8s.go @@ -339,7 +339,6 @@ func (k KubernetesClient) ExecCommand(ctx context.Context, input ExecCommandInpu req.Param("stdin", "true") req.Param("stdout", "true") req.Param("stderr", "true") - req.Param("tty", "true") if input.Entrypoint != "" { req.Param("command", input.Entrypoint) @@ -370,6 +369,20 @@ func (k KubernetesClient) ExecCommand(ctx context.Context, input ExecCommandInpu size := t.GetSize() sizeQueue := t.MonitorSize(size) + actuallyTty := sizeQueue != nil + + if actuallyTty { + req.Param("tty", "true") + } else { + req.Param("tty", "false") + t = term.TTY{ + In: os.Stdin, + Out: stdout, + Raw: false, + } + size = t.GetSize() + sizeQueue = t.MonitorSize(size) + } return t.Safe(func() error { exec, err := remotecommand.NewSPDYExecutor(&k.RestConfig, "POST", req.URL()) @@ -381,7 +394,7 @@ func (k KubernetesClient) ExecCommand(ctx context.Context, input ExecCommandInpu Stdin: os.Stdin, Stdout: stdout, Stderr: stderr, - Tty: true, + Tty: actuallyTty, TerminalSizeQueue: sizeQueue, }) })