@@ -62,7 +62,7 @@ func GetTaskFuncFromTaskRun(ctx context.Context, k8s kubernetes.Interface, tekto
6262 // if the spec is already in the status, do not try to fetch it again, just use it as source of truth.
6363 // Same for the Source field in the Status.Provenance.
6464 if taskrun .Status .TaskSpec != nil {
65- return func (_ context.Context , name string ) (v1beta1.TaskObject , * v1beta1.ConfigSource , error ) {
65+ return func (_ context.Context , name string ) (* v1beta1.Task , * v1beta1.ConfigSource , error ) {
6666 var configsource * v1beta1.ConfigSource
6767 if taskrun .Status .Provenance != nil {
6868 configsource = taskrun .Status .Provenance .ConfigSource
@@ -85,7 +85,7 @@ func GetVerifiedTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton c
8585 owner kmeta.OwnerRefable , taskref * v1beta1.TaskRef , trName string , namespace , saName string , verificationpolicies []* v1alpha1.VerificationPolicy ) GetTask {
8686 get := GetTaskFunc (ctx , k8s , tekton , requester , owner , taskref , trName , namespace , saName )
8787
88- return func (context.Context , string ) (v1beta1.TaskObject , * v1beta1.ConfigSource , error ) {
88+ return func (context.Context , string ) (* v1beta1.Task , * v1beta1.ConfigSource , error ) {
8989 t , s , err := get (ctx , taskref .Name )
9090 if err != nil {
9191 return nil , nil , fmt .Errorf ("failed to get task: %w" , err )
@@ -117,7 +117,7 @@ func GetTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset
117117 case cfg .FeatureFlags .EnableTektonOCIBundles && tr != nil && tr .Bundle != "" :
118118 // Return an inline function that implements GetTask by calling Resolver.Get with the specified task type and
119119 // casting it to a TaskObject.
120- return func (ctx context.Context , name string ) (v1beta1.TaskObject , * v1beta1.ConfigSource , error ) {
120+ return func (ctx context.Context , name string ) (* v1beta1.Task , * v1beta1.ConfigSource , error ) {
121121 // If there is a bundle url at all, construct an OCI resolver to fetch the task.
122122 kc , err := k8schain .New (ctx , k8s , k8schain.Options {
123123 Namespace : namespace ,
@@ -133,7 +133,7 @@ func GetTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset
133133 case tr != nil && tr .Resolver != "" && requester != nil :
134134 // Return an inline function that implements GetTask by calling Resolver.Get with the specified task type and
135135 // casting it to a TaskObject.
136- return func (ctx context.Context , name string ) (v1beta1.TaskObject , * v1beta1.ConfigSource , error ) {
136+ return func (ctx context.Context , name string ) (* v1beta1.Task , * v1beta1.ConfigSource , error ) {
137137 var replacedParams v1beta1.Params
138138 if ownerAsTR , ok := owner .(* v1beta1.TaskRun ); ok {
139139 stringReplacements , arrayReplacements := paramsFromTaskRun (ctx , ownerAsTR )
@@ -165,8 +165,8 @@ func GetTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset
165165// resolveTask accepts an impl of remote.Resolver and attempts to
166166// fetch a task with given name. An error is returned if the
167167// remoteresource doesn't work or the returned data isn't a valid
168- // v1beta1.TaskObject .
169- func resolveTask (ctx context.Context , resolver remote.Resolver , name string , kind v1beta1.TaskKind , k8s kubernetes.Interface ) (v1beta1.TaskObject , * v1beta1.ConfigSource , error ) {
168+ // * v1beta1.Task .
169+ func resolveTask (ctx context.Context , resolver remote.Resolver , name string , kind v1beta1.TaskKind , k8s kubernetes.Interface ) (* v1beta1.Task , * v1beta1.ConfigSource , error ) {
170170 // Because the resolver will only return references with the same kind (eg ClusterTask), this will ensure we
171171 // don't accidentally return a Task with the same name but different kind.
172172 obj , configSource , err := resolver .Get (ctx , strings .TrimSuffix (strings .ToLower (string (kind )), "s" ), name )
@@ -181,16 +181,18 @@ func resolveTask(ctx context.Context, resolver remote.Resolver, name string, kin
181181}
182182
183183// readRuntimeObjectAsTask tries to convert a generic runtime.Object
184- // into a v1beta1.TaskObject type so that its meta and spec fields
184+ // into a * v1beta1.Task type so that its meta and spec fields
185185// can be read. v1 object will be converted to v1beta1 and returned.
186- // An error is returned if the given object is not a
187- // TaskObject or if there is an error validating or upgrading an
188- // older TaskObject into its v1beta1 equivalent.
186+ // An error is returned if the given object is not a Task nor a ClusterTask
187+ // or if there is an error validating or upgrading an older TaskObject into
188+ // its v1beta1 equivalent.
189189// TODO(#5541): convert v1beta1 obj to v1 once we use v1 as the stored version
190- func readRuntimeObjectAsTask (ctx context.Context , obj runtime.Object ) (v1beta1.TaskObject , error ) {
190+ func readRuntimeObjectAsTask (ctx context.Context , obj runtime.Object ) (* v1beta1.Task , error ) {
191191 switch obj := obj .(type ) {
192- case v1beta1.TaskObject :
192+ case * v1beta1.Task :
193193 return obj , nil
194+ case * v1beta1.ClusterTask :
195+ return convertClusterTaskToTask (* obj ), nil
194196 case * v1.Task :
195197 t := & v1beta1.Task {
196198 TypeMeta : metav1.TypeMeta {
@@ -217,13 +219,13 @@ type LocalTaskRefResolver struct {
217219// return an error if it can't find an appropriate Task for any reason.
218220// TODO: if we want to set source for in-cluster task, set it here.
219221// https://github.com/tektoncd/pipeline/issues/5522
220- func (l * LocalTaskRefResolver ) GetTask (ctx context.Context , name string ) (v1beta1.TaskObject , * v1beta1.ConfigSource , error ) {
222+ func (l * LocalTaskRefResolver ) GetTask (ctx context.Context , name string ) (* v1beta1.Task , * v1beta1.ConfigSource , error ) {
221223 if l .Kind == v1beta1 .ClusterTaskKind {
222224 task , err := l .Tektonclient .TektonV1beta1 ().ClusterTasks ().Get (ctx , name , metav1.GetOptions {})
223225 if err != nil {
224226 return nil , nil , err
225227 }
226- return task , nil , nil
228+ return convertClusterTaskToTask ( * task ) , nil , nil
227229 }
228230
229231 // If we are going to resolve this reference locally, we need a namespace scope.
@@ -241,3 +243,21 @@ func (l *LocalTaskRefResolver) GetTask(ctx context.Context, name string) (v1beta
241243func IsGetTaskErrTransient (err error ) bool {
242244 return strings .Contains (err .Error (), errEtcdLeaderChange )
243245}
246+
247+ // convertClusterTaskToTask converts deprecated v1beta1 ClusterTasks to Tasks for
248+ // the rest of reconciling process since GetTask func and its upstream callers only
249+ // fetches the task spec and stores it in the taskrun status while the kind info
250+ // is not being used.
251+ func convertClusterTaskToTask (ct v1beta1.ClusterTask ) * v1beta1.Task {
252+ t := & v1beta1.Task {
253+ TypeMeta : metav1.TypeMeta {
254+ Kind : "Task" ,
255+ APIVersion : "tekton.dev/v1beta1" ,
256+ },
257+ }
258+
259+ t .Spec = ct .Spec
260+ t .ObjectMeta .Name = ct .ObjectMeta .Name
261+
262+ return t
263+ }
0 commit comments