From 106f8ebbe284ba29d96af6ba950aa976b297612f Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Mon, 11 May 2026 11:48:59 +0300 Subject: [PATCH 1/5] Add conditional pod cleanup in CompleteScriptAsync method --- .../Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs b/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs index 668d7cd01..e5c6255c0 100644 --- a/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs +++ b/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs @@ -124,7 +124,8 @@ public async Task CancelScriptAsync(CancelKube public async Task CompleteScriptAsync(CompleteKubernetesScriptCommandV1 command, CancellationToken cancellationToken) { var workspace = workspaceFactory.GetWorkspace(command.ScriptTicket, WorkspaceReadinessCheck.Skip); - await workspace.Delete(cancellationToken); + if (!KubernetesConfig.DisableAutomaticPodCleanup) + await workspace.Delete(cancellationToken); scriptLogProvider.Delete(command.ScriptTicket); scriptPodSinceTimeStore.Delete(command.ScriptTicket); From 5b09aa5623e235a0c36bc0ad704de2e584975395 Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Mon, 11 May 2026 13:36:17 +0300 Subject: [PATCH 2/5] Update markAsInitialised function to use configurationDirectory for initialization --- docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh b/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh index c3640ca2a..f7f2140cc 100644 --- a/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh +++ b/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh @@ -414,7 +414,7 @@ function setPollingProxy() { function markAsInitialised() { # There is a startupProbe which checks for this file - mkdir -p /etc/octopus && touch /etc/octopus/initialized + mkdir -p "$configurationDirectory" && touch "$configurationDirectory/initialized" } setupVariablesForRegistrationCheck From 095118ca2b6832e361c9d0bfe41efe9d2e1efc0b Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Mon, 11 May 2026 14:37:38 +0300 Subject: [PATCH 3/5] added more logs --- docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh b/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh index f7f2140cc..e26b02db3 100644 --- a/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh +++ b/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh @@ -29,7 +29,9 @@ applicationsDirectory=/home/Octopus/Applications if [[ -n "$TentacleApplications" ]]; then applicationsDirectory="$TentacleApplications" fi - +echo "Creating config directory" +echo "Permissions for $configurationDirectory:" +ls -lan / | grep etc mkdir -p $configurationDirectory mkdir -p $applicationsDirectory From ad40eef8869b4b378bc23afca39ebc72fbb1a6b6 Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Mon, 11 May 2026 15:21:33 +0300 Subject: [PATCH 4/5] keep volume for failed scripts when debug left --- .../Scripts/Kubernetes/KubernetesScriptServiceV1.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs b/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs index e5c6255c0..29725a143 100644 --- a/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs +++ b/source/Octopus.Tentacle/Services/Scripts/Kubernetes/KubernetesScriptServiceV1.cs @@ -124,7 +124,11 @@ public async Task CancelScriptAsync(CancelKube public async Task CompleteScriptAsync(CompleteKubernetesScriptCommandV1 command, CancellationToken cancellationToken) { var workspace = workspaceFactory.GetWorkspace(command.ScriptTicket, WorkspaceReadinessCheck.Skip); - if (!KubernetesConfig.DisableAutomaticPodCleanup) + + var podExitCode = podStatusProvider.TryGetTrackedScriptPod(command.ScriptTicket)?.State.ExitCode ?? 0; + + // Preserve the workspace when the script pod failed so the files are available for debugging. + if (!KubernetesConfig.DisableAutomaticPodCleanup && podExitCode != 0) await workspace.Delete(cancellationToken); scriptLogProvider.Delete(command.ScriptTicket); From ce3cf1d0cc7f3e796c5d44a5badfbc096e2a9f30 Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Mon, 25 May 2026 23:31:49 +0300 Subject: [PATCH 5/5] revert back changes with /etc/octopus --- docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh b/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh index e26b02db3..56348b3b6 100644 --- a/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh +++ b/docker/kubernetes-agent-tentacle/scripts/configure-and-run.sh @@ -416,7 +416,7 @@ function setPollingProxy() { function markAsInitialised() { # There is a startupProbe which checks for this file - mkdir -p "$configurationDirectory" && touch "$configurationDirectory/initialized" + mkdir -p /etc/octopus && touch /etc/octopus/initialized } setupVariablesForRegistrationCheck