From 4e7cdfe7ba5fd47db405796c774bfcbeb3c2f45e Mon Sep 17 00:00:00 2001 From: qingliu Date: Tue, 23 Jan 2024 17:20:58 +0800 Subject: [PATCH] fix: ensure clustertask annotations are synced to taskrun fix #7601 --- pkg/reconciler/taskrun/resources/taskref.go | 4 +++- pkg/reconciler/taskrun/resources/taskref_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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,