Skip to content

Commit a68d753

Browse files
Scotttekton-robot
authored andcommitted
Re-add tekton.dev/task label to taskruns from ClusterTasks
In #2390 TaskRuns referencing ClusterTasks had their label changed from tekton.dev/task=<Name> to tekton.dev/clusterTask=<Name>. This is a backwards-incompatible change for teams relying on that original task label. This commit adds both labels to TaskRuns referencing ClusterTasks. We can then deprecate the tekton.dev/task= label on these TaskRuns in accordance with Pipelines' API deprecation policy.
1 parent a9c14e0 commit a68d753

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

docs/labels.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ The following labels are added to resources automatically:
5454
references.
5555
- `tekton.dev/clusterTask` is added to `TaskRuns` (and propagated to `Pods`) that
5656
reference an existing `ClusterTask`and contains the name of the `ClusterTask`
57-
that the `TaskRun` references.
57+
that the `TaskRun` references. For backwards compatibility, `TaskRuns` that
58+
reference a `ClusterTask` will also receive `tekton.dev/task`.
5859
- `tekton.dev/taskRun` is added to `Pods`, and contains the name of the
5960
`TaskRun` that created the `Pod`.
6061

@@ -88,4 +89,4 @@ the following command:
8889

8990
```shell
9091
kubectl get taskruns --all-namespaces -l tekton.dev/clusterTask=test-clustertask
91-
```
92+
```

pkg/reconciler/taskrun/taskrun.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,9 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1alpha1.TaskRun) error
224224
tr.ObjectMeta.Labels[key] = value
225225
}
226226
if tr.Spec.TaskRef != nil {
227+
tr.ObjectMeta.Labels[pipeline.GroupName+pipeline.TaskLabelKey] = taskMeta.Name
227228
if tr.Spec.TaskRef.Kind == "ClusterTask" {
228229
tr.ObjectMeta.Labels[pipeline.GroupName+pipeline.ClusterTaskLabelKey] = taskMeta.Name
229-
} else {
230-
tr.ObjectMeta.Labels[pipeline.GroupName+pipeline.TaskLabelKey] = taskMeta.Name
231230
}
232231
}
233232

pkg/reconciler/taskrun/taskrun_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ func TestReconcile(t *testing.T) {
795795
wantPod: tb.Pod("test-taskrun-with-cluster-task-pod-abcde",
796796
tb.PodNamespace("foo"),
797797
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
798+
tb.PodLabel(taskNameLabelKey, "test-cluster-task"),
798799
tb.PodLabel(clusterTaskNameLabelKey, "test-cluster-task"),
799800
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-cluster-task"),
800801
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),

0 commit comments

Comments
 (0)