From bfd83b217ab8be7ddd1465e894d69461acd0f382 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Wed, 25 Sep 2024 13:44:46 +0100 Subject: [PATCH] Mark steps as deleted when TaskRun fails Today this is done after the Pod is handled. If Pod deletion fails for some reason, the steps are not updated. Tekton only makes one attempt to delete the Pod to try and avoid that it keeps running even if the TaskRun failed. If this deletion fails for whatever reason, Tekton should still update the TaskRun status to mark the steps as failed, as they are failed from Tekton POV. Fixes: #8293 Signed-off-by: Andrea Frittoli --- pkg/reconciler/taskrun/taskrun.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 47a254af469..a11942fcb2a 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -783,6 +783,12 @@ func (c *Reconciler) failTaskRun(ctx context.Context, tr *v1.TaskRun, reason v1. return nil } + // When the TaskRun is failed, we mark all running/waiting steps as failed + // This is regardless of what happens with the Pod, which may be cancelled, + // deleted, non existing or fail to delete + // See https://github.com/tektoncd/pipeline/issues/8293 for more details. + terminateStepsInPod(tr, reason) + var err error if reason == v1.TaskRunReasonCancelled && (config.FromContextOrDefaults(ctx).FeatureFlags.EnableKeepPodOnCancel) { logger.Infof("Canceling task run %q by entrypoint", tr.Name) @@ -795,7 +801,6 @@ func (c *Reconciler) failTaskRun(ctx context.Context, tr *v1.TaskRun, reason v1. return err } - terminateStepsInPod(tr, reason) return nil }