Skip to content

Commit

Permalink
[WIP] refactor fetching ClusterTask without TaskKind
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeJu committed Apr 18, 2023
1 parent 48acab6 commit 35f85d1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/reconciler/taskrun/resources/taskref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 35f85d1

Please sign in to comment.