From 838beb4db343980492ccaca850fbd2c1ceb66509 Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Tue, 17 Dec 2024 17:38:24 +0200 Subject: [PATCH 1/5] Take DOKKU_FORCE_TTY setting into account for run commands with k3s-scheduler --- plugins/scheduler-k3s/k8s.go | 2 +- plugins/scheduler-k3s/triggers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scheduler-k3s/k8s.go b/plugins/scheduler-k3s/k8s.go index 1e8245fc8..009317633 100644 --- a/plugins/scheduler-k3s/k8s.go +++ b/plugins/scheduler-k3s/k8s.go @@ -385,7 +385,7 @@ func (k KubernetesClient) ExecCommand(ctx context.Context, input ExecCommandInpu size := t.GetSize() sizeQueue := t.MonitorSize(size) - actuallyTty := sizeQueue != nil + actuallyTty := (sizeQueue != nil) || os.Getenv("DOKKU_FORCE_TTY") == "true" if actuallyTty { req.Param("tty", "true") diff --git a/plugins/scheduler-k3s/triggers.go b/plugins/scheduler-k3s/triggers.go index 1b3bbbcf1..2b5bb67c3 100644 --- a/plugins/scheduler-k3s/triggers.go +++ b/plugins/scheduler-k3s/triggers.go @@ -1142,7 +1142,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args [] Image: image, ImagePullSecrets: imagePullSecrets, ImageSourceType: imageSourceType, - Interactive: attachToPod, + Interactive: attachToPod || os.Getenv("DOKKU_FORCE_TTY") == "true", Labels: labels, Namespace: namespace, ProcessType: processType, From f786c8c0bc869bfb6af81b703014f385fb5ac52e Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Tue, 17 Dec 2024 18:53:30 +0200 Subject: [PATCH 2/5] Fix k3s run:detached not returning pod name in a similar fashion to docker-local (as described in docs) --- plugins/scheduler-k3s/triggers.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/scheduler-k3s/triggers.go b/plugins/scheduler-k3s/triggers.go index 2b5bb67c3..141242f89 100644 --- a/plugins/scheduler-k3s/triggers.go +++ b/plugins/scheduler-k3s/triggers.go @@ -1192,7 +1192,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args [] } batchJobSelector := fmt.Sprintf("batch.kubernetes.io/job-name=%s", createdJob.Name) - _, err = waitForPodToExist(ctx, WaitForPodToExistInput{ + pods, err := waitForPodToExist(ctx, WaitForPodToExistInput{ Clientset: clientset, Namespace: namespace, RetryCount: 3, @@ -1202,6 +1202,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args [] return fmt.Errorf("Error waiting for pod to exist: %w", err) } if !attachToPod { + fmt.Println(pods[0].Name) return nil } @@ -1254,7 +1255,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args [] return fmt.Errorf("Error waiting for pod to be running: %w", err) } - pods, err := clientset.ListPods(ctx, ListPodsInput{ + pods, err = clientset.ListPods(ctx, ListPodsInput{ Namespace: namespace, LabelSelector: batchJobSelector, }) From 63182e80e04163f2c592dda37fe8419f03b8d839 Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Tue, 17 Dec 2024 19:17:24 +0200 Subject: [PATCH 3/5] Use common.ToBool to check DOKKU_FORCE_TTY --- plugins/scheduler-k3s/k8s.go | 2 +- plugins/scheduler-k3s/triggers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scheduler-k3s/k8s.go b/plugins/scheduler-k3s/k8s.go index 009317633..8ad39e454 100644 --- a/plugins/scheduler-k3s/k8s.go +++ b/plugins/scheduler-k3s/k8s.go @@ -385,7 +385,7 @@ func (k KubernetesClient) ExecCommand(ctx context.Context, input ExecCommandInpu size := t.GetSize() sizeQueue := t.MonitorSize(size) - actuallyTty := (sizeQueue != nil) || os.Getenv("DOKKU_FORCE_TTY") == "true" + actuallyTty := (sizeQueue != nil) || common.ToBool(os.Getenv("DOKKU_FORCE_TTY")) if actuallyTty { req.Param("tty", "true") diff --git a/plugins/scheduler-k3s/triggers.go b/plugins/scheduler-k3s/triggers.go index 141242f89..aede9c473 100644 --- a/plugins/scheduler-k3s/triggers.go +++ b/plugins/scheduler-k3s/triggers.go @@ -1142,7 +1142,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args [] Image: image, ImagePullSecrets: imagePullSecrets, ImageSourceType: imageSourceType, - Interactive: attachToPod || os.Getenv("DOKKU_FORCE_TTY") == "true", + Interactive: attachToPod || common.ToBool(os.Getenv("DOKKU_FORCE_TTY")), Labels: labels, Namespace: namespace, ProcessType: processType, From a0dc8fd44a0a7407eb6af2bd37fdeb3c64cb6fe9 Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Tue, 17 Dec 2024 21:53:23 +0200 Subject: [PATCH 4/5] Update docs regarding the returned container/pod name for detached command --- docs/processes/one-off-tasks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index 853b90bf2..b3bcc71d7 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -66,7 +66,7 @@ dokku run --no-tty node-js-app ls -lah > [!IMPORTANT] > New as of 0.25.0 -Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return a `CONTAINER_ID`. Detached containers are run without a tty and are also removed at the end of process execution. +Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return the container name (or pod name when using the k3s scheduler). Detached containers are run without a tty and are also removed at the end of process execution. ```shell dokku run:detached node-js-app ls -lah From fb4388b9e49e0fde177ddfd3738c6ee22e92b741 Mon Sep 17 00:00:00 2001 From: Tasos Maschalidis Date: Tue, 17 Dec 2024 22:23:02 +0200 Subject: [PATCH 5/5] Slight improvement in phrasing for tty functionality --- docs/processes/one-off-tasks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index b3bcc71d7..1df42652c 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -66,7 +66,7 @@ dokku run --no-tty node-js-app ls -lah > [!IMPORTANT] > New as of 0.25.0 -Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return the container name (or pod name when using the k3s scheduler). Detached containers are run without a tty and are also removed at the end of process execution. +Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return the container name (or pod name when using the k3s scheduler). Detached containers run without a tty by default and are also removed at the end of process execution. ```shell dokku run:detached node-js-app ls -lah