diff --git a/pkg/reconciler/taskrun/resources/taskref.go b/pkg/reconciler/taskrun/resources/taskref.go index 10d774eea94..3b00efd88f3 100644 --- a/pkg/reconciler/taskrun/resources/taskref.go +++ b/pkg/reconciler/taskrun/resources/taskref.go @@ -218,23 +218,28 @@ type LocalTaskRefResolver struct { // GetTask will resolve either a Task or ClusterTask from the local cluster using a versioned Tekton client. It will // return an error if it can't find an appropriate Task for any reason. func (l *LocalTaskRefResolver) GetTask(ctx context.Context, name string) (*v1beta1.Task, *v1beta1.RefSource, error) { + var ctErr error if l.Kind == v1beta1.ClusterTaskKind { - task, err := l.Tektonclient.TektonV1beta1().ClusterTasks().Get(ctx, name, metav1.GetOptions{}) - if err != nil { - return nil, nil, err + clusterTask, err := l.Tektonclient.TektonV1beta1().ClusterTasks().Get(ctx, name, metav1.GetOptions{}) + if clusterTask != nil { + return convertClusterTaskToTask(*clusterTask), nil, nil } - return convertClusterTaskToTask(*task), nil, nil + ctErr = err } - // If we are going to resolve this reference locally, we need a namespace scope. if l.Namespace == "" { return nil, nil, fmt.Errorf("must specify namespace to resolve reference to task %s", name) } task, err := l.Tektonclient.TektonV1beta1().Tasks(l.Namespace).Get(ctx, name, metav1.GetOptions{}) - if err != nil { + if task != nil { + return task, nil, nil + } + + if l.Kind == v1beta1.NamespacedTaskKind && err != nil { return nil, nil, err } - return task, nil, nil + + return nil, nil, ctErr } // IsGetTaskErrTransient returns true if an error returned by GetTask is retryable.