diff --git a/docs/labels.md b/docs/labels.md
index f376915b17c..e04386cb076 100644
--- a/docs/labels.md
+++ b/docs/labels.md
@@ -80,6 +80,12 @@ Tekton automatically adds labels to Tekton entities as described in the followin
No propagation. |
Name of the TaskRun that created the Pod . |
+
+ tekton.dev/finallyTask |
+ TaskRuns that are created for a finally tasks during the execution of a PipelineRun . |
+ TaskRuns, Pods |
+ true |
+
app.kubernetes.io/instance , app.kubernetes.io/component |
Pods , StatefulSets (Affinity Assistant) |
diff --git a/pkg/apis/pipeline/register.go b/pkg/apis/pipeline/register.go
index f34e682c67a..13932d5cd3f 100644
--- a/pkg/apis/pipeline/register.go
+++ b/pkg/apis/pipeline/register.go
@@ -48,6 +48,9 @@ const (
// RunKey is used as the label identifier for a Run
RunKey = "/run"
+
+ // FinallyLabelKey is used as the label identifier for a Finally task
+ FinallyLabelKey = "/finallyTask"
)
var (
diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go
index 94e4c6ad442..e0c0d884081 100644
--- a/pkg/reconciler/pipelinerun/pipelinerun.go
+++ b/pkg/reconciler/pipelinerun/pipelinerun.go
@@ -929,6 +929,14 @@ func combineTaskRunAndTaskSpecLabels(pr *v1beta1.PipelineRun, pipelineTask *v1be
labels[key] = value
}
}
+
+ // check if a task is part of the finally section, add a label to identify it during the runtime
+ for _, f := range pr.Status.PipelineSpec.Finally {
+ if pipelineTask.Name == f.Name {
+ labels[pipeline.GroupName+pipeline.FinallyLabelKey] = "true"
+ break
+ }
+ }
return labels
}
diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go
index 2f1bb9c8e14..2861adfdff5 100644
--- a/pkg/reconciler/pipelinerun/pipelinerun_test.go
+++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go
@@ -5448,6 +5448,7 @@ func TestReconciler_ReconcileKind_PipelineTaskContext(t *testing.T) {
tb.TaskRunLabel("tekton.dev/pipeline", pipelineName),
tb.TaskRunLabel("tekton.dev/pipelineRun", pipelineRunName),
tb.TaskRunLabel("tekton.dev/pipelineTask", "finaltask"),
+ tb.TaskRunLabel("tekton.dev/finallyTask", "true"),
tb.TaskRunSpec(
tb.TaskRunTaskRef("finaltask"),
tb.TaskRunServiceAccountName("test-sa"),
@@ -5681,6 +5682,7 @@ func TestReconcileWithTaskResultsInFinalTasks(t *testing.T) {
"tekton.dev/pipeline": "test-pipeline",
"tekton.dev/pipelineRun": "test-pipeline-run-final-task-results",
"tekton.dev/pipelineTask": "final-task-1",
+ "tekton.dev/finallyTask": "true",
},
Annotations: map[string]string{},
},