Skip to content

Commit

Permalink
adding label to identify a finally taskRun in a pipeline
Browse files Browse the repository at this point in the history
A label is added to a taskRun for a task which is part of the finally section.
The label added is tekton.dev/finallyTask and set to true for a finally task.
  • Loading branch information
pritidesai committed Jul 28, 2021
1 parent a728ce3 commit f5287b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Tekton automatically adds labels to Tekton entities as described in the followin
<td>No propagation.</td>
<td>Name of the <code>TaskRun</code> that created the <code>Pod</code>.</td>
</tr>
<tr>
<td><code>tekton.dev/finallyTask</code></td>
<td><code>TaskRuns</code> that are created for a <code>finally tasks</code> during the execution of a <code>PipelineRun</code>.</td>
<td><code>TaskRuns, Pods</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>app.kubernetes.io/instance</code>, <code>app.kubernetes.io/component</code></td>
<td><code>Pods</code>, <code>StatefulSets</code> (Affinity Assistant)</td>
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,15 @@ func getTaskrunLabels(pr *v1beta1.PipelineRun, pipelineTaskName string, includeP
if pipelineTaskName != "" {
labels[pipeline.GroupName+pipeline.PipelineTaskLabelKey] = pipelineTaskName
}
// check if a task is part of the finally section, add a label to identify it during the runtime
if pr.Status.PipelineSpec != nil {
for _, f := range pr.Status.PipelineSpec.Finally {
if pipelineTaskName == f.Name {
labels[pipeline.GroupName+pipeline.FinallyLabelKey] = "true"
break
}
}
}
return labels
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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{},
},
Expand Down

0 comments on commit f5287b0

Please sign in to comment.