diff --git a/pkg/reconciler/taskrun/resources/taskref.go b/pkg/reconciler/taskrun/resources/taskref.go index a2b547cdbcc..84da4fd31d9 100644 --- a/pkg/reconciler/taskrun/resources/taskref.go +++ b/pkg/reconciler/taskrun/resources/taskref.go @@ -237,10 +237,12 @@ func convertClusterTaskToTask(ctx context.Context, ct v1beta1.ClusterTask) (*v1. Kind: "Task", APIVersion: "tekton.dev/v1beta1", }, + // We need to keep ObjectMeta to keep consistent with the existing Task logic. + // TaskRun will inherit the original Annotations and Labels information. + ObjectMeta: ct.ObjectMeta, } t.Spec = ct.Spec - t.ObjectMeta.Name = ct.ObjectMeta.Name v1Task := &v1.Task{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/reconciler/taskrun/resources/taskref_test.go b/pkg/reconciler/taskrun/resources/taskref_test.go index 916340d2a6b..6d54f7b748b 100644 --- a/pkg/reconciler/taskrun/resources/taskref_test.go +++ b/pkg/reconciler/taskrun/resources/taskref_test.go @@ -198,6 +198,12 @@ func TestLocalTaskRef(t *testing.T) { &v1beta1.ClusterTask{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster-task", + Annotations: map[string]string{ + "foo": "bar", + }, + Labels: map[string]string{ + "foo": "bar", + }, }, }, &v1beta1.ClusterTask{ @@ -217,6 +223,12 @@ func TestLocalTaskRef(t *testing.T) { }, ObjectMeta: metav1.ObjectMeta{ Name: "cluster-task", + Annotations: map[string]string{ + "foo": "bar", + }, + Labels: map[string]string{ + "foo": "bar", + }, }, }, wantErr: nil,