diff --git a/pkg/reconciler/taskrun/resources/taskref.go b/pkg/reconciler/taskrun/resources/taskref.go index 134360f68f2..14317583240 100644 --- a/pkg/reconciler/taskrun/resources/taskref.go +++ b/pkg/reconciler/taskrun/resources/taskref.go @@ -295,10 +295,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 62eba5f2653..27379a2f94b 100644 --- a/pkg/reconciler/taskrun/resources/taskref_test.go +++ b/pkg/reconciler/taskrun/resources/taskref_test.go @@ -228,6 +228,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{ @@ -247,6 +253,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,