From b9d275d1fb1842d8602b3eab4d7fdbf8bad84d3b Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Sun, 2 Dec 2018 17:47:16 -0800 Subject: [PATCH] Separate task spec resolution from resource resolution This is so that the PipelineRun reconciler can use the same resource resolution. When the PipelineRun resolves resources, there are not yet any TaskRuns to pass along, those get created later. Seems a bit weird that the resolution function still needs to be passed the taskspec + name at all really, but we'll see how this goes! This is part of #213 --- .../taskrun/resources/taskrunresolution.go | 47 +-- .../resources/taskrunresolution_test.go | 321 ++++++------------ .../v1alpha1/taskrun/resources/taskspec.go | 48 +++ .../taskrun/resources/taskspec_test.go | 103 ++++++ pkg/reconciler/v1alpha1/taskrun/taskrun.go | 17 +- 5 files changed, 284 insertions(+), 252 deletions(-) create mode 100644 pkg/reconciler/v1alpha1/taskrun/resources/taskspec.go create mode 100644 pkg/reconciler/v1alpha1/taskrun/resources/taskspec_test.go diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution.go b/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution.go index c114065f0d7..922f0c67446 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution.go @@ -38,32 +38,25 @@ type ResolvedTaskRun struct { // GetResource is a function used to retrieve PipelineResources. type GetResource func(string) (*v1alpha1.PipelineResource, error) -// GetTask is a function used to retrieve Tasks. -type GetTask func(string) (*v1alpha1.Task, error) - -// ResolveTaskRun looks up CRDs referenced by the TaskRun and returns an instance -// of TaskRunResource with all of the relevant data populated. If referenced CRDs can't -// be found, an error is returned. -func ResolveTaskRun(tr *v1alpha1.TaskRun, getTask GetTask, gr GetResource) (*ResolvedTaskRun, error) { - var err error +// ResolveTaskRun looks up PipelineResources referenced by inputs and outputs and returns +// a structure that unites the resolved references nad the Task Spec. If referenced PipelineResources +// can't be found, an error is returned. +func ResolveTaskRun(ts *v1alpha1.TaskSpec, taskName string, inputs []v1alpha1.TaskRunResource, outputs []v1alpha1.TaskRunResource, gr GetResource) (*ResolvedTaskRun, error) { rtr := ResolvedTaskRun{ - Inputs: map[string]*v1alpha1.PipelineResource{}, - Outputs: map[string]*v1alpha1.PipelineResource{}, - } - - rtr.TaskSpec, rtr.TaskName, err = getTaskSpec(tr, getTask) - if err != nil { - return nil, fmt.Errorf("couldn't retrieve referenced Task %q: %s", tr.Spec.TaskRef.Name, err) + TaskName: taskName, + TaskSpec: ts, + Inputs: map[string]*v1alpha1.PipelineResource{}, + Outputs: map[string]*v1alpha1.PipelineResource{}, } - for _, r := range tr.Spec.Inputs.Resources { + for _, r := range inputs { rr, err := gr(r.ResourceRef.Name) if err != nil { return nil, fmt.Errorf("couldn't retrieve referenced input PipelineResource %q: %s", r.ResourceRef.Name, err) } rtr.Inputs[r.Name] = rr } - for _, r := range tr.Spec.Outputs.Resources { + for _, r := range outputs { rr, err := gr(r.ResourceRef.Name) if err != nil { return nil, fmt.Errorf("couldn't retrieve referenced output PipelineResource %q: %s", r.ResourceRef.Name, err) @@ -72,23 +65,3 @@ func ResolveTaskRun(tr *v1alpha1.TaskRun, getTask GetTask, gr GetResource) (*Res } return &rtr, nil } - -func getTaskSpec(taskRun *v1alpha1.TaskRun, getTask GetTask) (*v1alpha1.TaskSpec, string, error) { - taskSpec := &v1alpha1.TaskSpec{} - taskName := "" - if taskRun.Spec.TaskRef != nil && taskRun.Spec.TaskRef.Name != "" { - // Get related task for taskrun - t, err := getTask(taskRun.Spec.TaskRef.Name) - if err != nil { - return nil, taskName, fmt.Errorf("error when listing tasks for taskRun %s %v", taskRun.Name, err) - } - taskSpec = &t.Spec - taskName = t.Name - } else if taskRun.Spec.TaskSpec != nil { - taskSpec = taskRun.Spec.TaskSpec - taskName = taskRun.Name - } else { - return taskSpec, taskName, fmt.Errorf("TaskRun %s not providing TaskRef or TaskSpec", taskRun.Name) - } - return taskSpec, taskName, nil -} diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution_test.go b/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution_test.go index 616656fb795..ec341aff9df 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution_test.go @@ -26,257 +26,154 @@ import ( ) func TestResolveTaskRun(t *testing.T) { - inputs := v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResource{{ - Name: "repoToBuildFrom", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "git-repo", - }, - }, { - Name: "clusterToUse", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "k8s-cluster", - }, - }}, - } + inputs := []v1alpha1.TaskRunResource{{ + Name: "repoToBuildFrom", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "git-repo", + }, + }, { + Name: "clusterToUse", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "k8s-cluster", + }, + }} - outputs := v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResource{{ - Name: "imageToBuild", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "image", - }, - }, { - Name: "gitRepoToUpdate", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "another-git-repo", - }, - }}, - } + outputs := []v1alpha1.TaskRunResource{{ + Name: "imageToBuild", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "image", + }, + }, { + Name: "gitRepoToUpdate", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "another-git-repo", + }, + }} + + taskName := "orchestrate" + taskSpec := &v1alpha1.TaskSpec{ + Steps: []corev1.Container{{ + Name: "step1", + }}} - task := &v1alpha1.Task{ + resources := []*v1alpha1.PipelineResource{{ ObjectMeta: metav1.ObjectMeta{ - Name: "orchestrate", + Name: "git-repo", }, - Spec: v1alpha1.TaskSpec{ - Steps: []corev1.Container{{ - Name: "step1", - }}, + }, { + ObjectMeta: metav1.ObjectMeta{ + Name: "k8s-cluster", + }, + }, { + ObjectMeta: metav1.ObjectMeta{ + Name: "image", }, - } - - tests := []struct { - name string - taskRun *v1alpha1.TaskRun - wantTaskName string - }{{ - name: "using task ref", - taskRun: &v1alpha1.TaskRun{ - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: "orchestrate", - }, - Inputs: inputs, - Outputs: outputs, - }}, - wantTaskName: "orchestrate", }, { - name: "using embedded task spec", - taskRun: &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskSpec: &v1alpha1.TaskSpec{ - Steps: []corev1.Container{{ - Name: "step1", - }}, - }, - Inputs: inputs, - Outputs: outputs, - }, + ObjectMeta: metav1.ObjectMeta{ + Name: "another-git-repo", }, - wantTaskName: "foo", - }, + }} + resourceIndex := 0 + gr := func(n string) (*v1alpha1.PipelineResource, error) { + r := resources[resourceIndex] + resourceIndex++ + return r, nil } - for _, ts := range tests { - t.Run(ts.name, func(t *testing.T) { - gt := func(n string) (*v1alpha1.Task, error) { return task, nil } - resources := []*v1alpha1.PipelineResource{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-repo", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "k8s-cluster", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "image", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "another-git-repo", - }, - }} - resourceIndex := 0 - gr := func(n string) (*v1alpha1.PipelineResource, error) { - r := resources[resourceIndex] - resourceIndex++ - return r, nil - } + rtr, err := ResolveTaskRun(taskSpec, taskName, inputs, outputs, gr) + if err != nil { + t.Fatalf("Did not expect error trying to resolve TaskRun: %s", err) + } - rtr, err := ResolveTaskRun(ts.taskRun, gt, gr) - if err != nil { - t.Fatalf("Did not expect error trying to resolve TaskRun: %s", err) - } + if rtr.TaskName != "orchestrate" { + t.Errorf("Expected task name `orchestrate` Task but got: %v", rtr.TaskName) + } + if rtr.TaskSpec == nil || len(rtr.TaskSpec.Steps) != 1 || rtr.TaskSpec.Steps[0].Name != "step1" { + t.Errorf("Task not resolved, expected task's spec to be used but spec was: %v", rtr.TaskSpec) + } - if rtr.TaskName != ts.wantTaskName { - t.Errorf("Task not resolved, expected `orchestrate` Task but got: %v", rtr.TaskName) + if len(rtr.Inputs) == 2 { + r, ok := rtr.Inputs["repoToBuildFrom"] + if !ok { + t.Errorf("Expected value present in map for `repoToBuildFrom' but it was missing") + } else { + if r.Name != "git-repo" { + t.Errorf("Expected to use resource `git-repo` for `repoToBuildFrom` but used %s", r.Name) } - if rtr.TaskSpec == nil || len(rtr.TaskSpec.Steps) != 1 || rtr.TaskSpec.Steps[0].Name != "step1" { - t.Errorf("Task not resolved, expected task's spec to be used but spec was: %v", rtr.TaskSpec) + } + r, ok = rtr.Inputs["clusterToUse"] + if !ok { + t.Errorf("Expected value present in map for `clusterToUse' but it was missing") + } else { + if r.Name != "k8s-cluster" { + t.Errorf("Expected to use resource `k8s-cluster` for `clusterToUse` but used %s", r.Name) } - - if len(rtr.Inputs) == 2 { - r, ok := rtr.Inputs["repoToBuildFrom"] - if !ok { - t.Errorf("Expected value present in map for `repoToBuildFrom' but it was missing") - } else { - if r.Name != "git-repo" { - t.Errorf("Expected to use resource `git-repo` for `repoToBuildFrom` but used %s", r.Name) - } - } - r, ok = rtr.Inputs["clusterToUse"] - if !ok { - t.Errorf("Expected value present in map for `clusterToUse' but it was missing") - } else { - if r.Name != "k8s-cluster" { - t.Errorf("Expected to use resource `k8s-cluster` for `clusterToUse` but used %s", r.Name) - } - } - } else { - t.Errorf("Expected 2 resolved inputs but instead had: %v", rtr.Inputs) + } + } else { + t.Errorf("Expected 2 resolved inputs but instead had: %v", rtr.Inputs) + } + + if len(rtr.Outputs) == 2 { + r, ok := rtr.Outputs["imageToBuild"] + if !ok { + t.Errorf("Expected value present in map for `imageToBuild' but it was missing") + } else { + if r.Name != "image" { + t.Errorf("Expected to use resource `image` for `imageToBuild` but used %s", r.Name) } - - if len(rtr.Outputs) == 2 { - r, ok := rtr.Outputs["imageToBuild"] - if !ok { - t.Errorf("Expected value present in map for `imageToBuild' but it was missing") - } else { - if r.Name != "image" { - t.Errorf("Expected to use resource `image` for `imageToBuild` but used %s", r.Name) - } - } - r, ok = rtr.Outputs["gitRepoToUpdate"] - if !ok { - t.Errorf("Expected value present in map for `gitRepoToUpdate' but it was missing") - } else { - if r.Name != "another-git-repo" { - t.Errorf("Expected to use resource `another-git-repo` for `gitRepoToUpdate` but used %s", r.Name) - } - } - } else { - t.Errorf("Expected 2 resolved outputs but instead had: %v", rtr.Outputs) + } + r, ok = rtr.Outputs["gitRepoToUpdate"] + if !ok { + t.Errorf("Expected value present in map for `gitRepoToUpdate' but it was missing") + } else { + if r.Name != "another-git-repo" { + t.Errorf("Expected to use resource `another-git-repo` for `gitRepoToUpdate` but used %s", r.Name) } - - }) + } + } else { + t.Errorf("Expected 2 resolved outputs but instead had: %v", rtr.Outputs) } } -func TestResolveTaskRun_missingTask(t *testing.T) { - tr := &v1alpha1.TaskRun{ - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: "orchestrate", - }, - }, - } - - gt := func(n string) (*v1alpha1.Task, error) { return nil, fmt.Errorf("nope") } - gr := func(n string) (*v1alpha1.PipelineResource, error) { return &v1alpha1.PipelineResource{}, nil } - - _, err := ResolveTaskRun(tr, gt, gr) - if err == nil { - t.Fatalf("Expected to get error because task couldn't be resolved") - } -} func TestResolveTaskRun_missingOutput(t *testing.T) { - tr := &v1alpha1.TaskRun{ - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: "orchestrate", - }, - Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResource{{ - Name: "repoToUpdate", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "another-git-repo", - }, - }, - }, - }, - }} + outputs := []v1alpha1.TaskRunResource{{ + Name: "repoToUpdate", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "another-git-repo", + }}} - gt := func(n string) (*v1alpha1.Task, error) { return &v1alpha1.Task{}, nil } gr := func(n string) (*v1alpha1.PipelineResource, error) { return nil, fmt.Errorf("nope") } - _, err := ResolveTaskRun(tr, gt, gr) + _, err := ResolveTaskRun(&v1alpha1.TaskSpec{}, "orchestrate", []v1alpha1.TaskRunResource{}, outputs, gr) if err == nil { t.Fatalf("Expected to get error because output resource couldn't be resolved") } } func TestResolveTaskRun_missingInput(t *testing.T) { - tr := &v1alpha1.TaskRun{ - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: "orchestrate", - }, - Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResource{{ - Name: "repoToBuildFrom", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "git-repo", - }, - }, - }, - }, - }} + inputs := []v1alpha1.TaskRunResource{{ + Name: "repoToBuildFrom", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: "git-repo", + }}} - gt := func(n string) (*v1alpha1.Task, error) { return &v1alpha1.Task{}, nil } gr := func(n string) (*v1alpha1.PipelineResource, error) { return nil, fmt.Errorf("nope") } - _, err := ResolveTaskRun(tr, gt, gr) + _, err := ResolveTaskRun(&v1alpha1.TaskSpec{}, "orchestrate", inputs, []v1alpha1.TaskRunResource{}, gr) if err == nil { - t.Fatalf("Expected to get error because input resource couldn't be resolved") + t.Fatalf("Expected to get error because output resource couldn't be resolved") } } func TestResolveTaskRun_noResources(t *testing.T) { - tr := &v1alpha1.TaskRun{ - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: "orchestrate", - }, - }, - } - task := &v1alpha1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "orchestrate", - }, - Spec: v1alpha1.TaskSpec{ - Steps: []corev1.Container{{ - Name: "step1", - }}, - }, - } + taskSpec := &v1alpha1.TaskSpec{ + Steps: []corev1.Container{{ + Name: "step1", + }}} - gt := func(n string) (*v1alpha1.Task, error) { return task, nil } gr := func(n string) (*v1alpha1.PipelineResource, error) { return &v1alpha1.PipelineResource{}, nil } - rtr, err := ResolveTaskRun(tr, gt, gr) + rtr, err := ResolveTaskRun(taskSpec, "orchestrate", []v1alpha1.TaskRunResource{}, []v1alpha1.TaskRunResource{}, gr) if err != nil { t.Fatalf("Did not expect error trying to resolve TaskRun: %s", err) } diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/taskspec.go b/pkg/reconciler/v1alpha1/taskrun/resources/taskspec.go new file mode 100644 index 00000000000..533868bba88 --- /dev/null +++ b/pkg/reconciler/v1alpha1/taskrun/resources/taskspec.go @@ -0,0 +1,48 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either extress or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resources + +import ( + "fmt" + + "github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1" +) + +// GetTask is a function used to retrieve Tasks. +type GetTask func(string) (*v1alpha1.Task, error) + +// GetTaskSpec will retrieve the Task Spec associated with the provieded TaskRun. This can come from a +// reference Task or from an embeded Task spec. +func GetTaskSpec(taskRunSpec *v1alpha1.TaskRunSpec, taskRunName string, getTask GetTask) (*v1alpha1.TaskSpec, string, error) { + taskSpec := &v1alpha1.TaskSpec{} + taskName := "" + if taskRunSpec.TaskRef != nil && taskRunSpec.TaskRef.Name != "" { + // Get related task for taskrun + t, err := getTask(taskRunSpec.TaskRef.Name) + if err != nil { + return nil, taskName, fmt.Errorf("error when listing tasks for taskRun %s %v", taskRunName, err) + } + taskSpec = &t.Spec + taskName = t.Name + } else if taskRunSpec.TaskSpec != nil { + taskSpec = taskRunSpec.TaskSpec + taskName = taskRunName + } else { + return taskSpec, taskName, fmt.Errorf("TaskRun %s not providing TaskRef or TaskSpec", taskRunName) + } + return taskSpec, taskName, nil +} diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/taskspec_test.go b/pkg/reconciler/v1alpha1/taskrun/resources/taskspec_test.go new file mode 100644 index 00000000000..f5efa879da5 --- /dev/null +++ b/pkg/reconciler/v1alpha1/taskrun/resources/taskspec_test.go @@ -0,0 +1,103 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either extress or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resources + +import ( + "fmt" + "testing" + + "github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestGetTaskSpec_Ref(t *testing.T) { + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "orchestrate", + }, + Spec: v1alpha1.TaskSpec{ + Steps: []corev1.Container{{ + Name: "step1", + }}, + }, + } + spec := &v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "orchestrate", + }, + } + gt := func(n string) (*v1alpha1.Task, error) { return task, nil } + taskSpec, name, err := GetTaskSpec(spec, "mytaskrun", gt) + + if err != nil { + t.Fatalf("Did not expect error getting task spec but got: %s", err) + } + + if name != "orchestrate" { + t.Errorf("Expected task name to be `orchestrate` but was %q", name) + } + + if len(taskSpec.Steps) != 1 || taskSpec.Steps[0].Name != "step1" { + t.Errorf("Task Spec not resolved as expected, expected referenced Task spec but got: %v", taskSpec) + } +} + +func TestGetTaskSpec_Embedded(t *testing.T) { + spec := &v1alpha1.TaskRunSpec{ + TaskSpec: &v1alpha1.TaskSpec{ + Steps: []corev1.Container{{ + Name: "step1", + }}, + }} + gt := func(n string) (*v1alpha1.Task, error) { return nil, fmt.Errorf("shouldn't be called") } + taskSpec, name, err := GetTaskSpec(spec, "mytaskrun", gt) + + if err != nil { + t.Fatalf("Did not expect error getting task spec but got: %s", err) + } + + if name != "mytaskrun" { + t.Errorf("Expected task name for embedded task to default to name of task run but was %q", name) + } + + if len(taskSpec.Steps) != 1 || taskSpec.Steps[0].Name != "step1" { + t.Errorf("Task Spec not resolved as expected, expected embedded Task spec but got: %v", taskSpec) + } +} + +func TestGetTaskSpec_Invalid(t *testing.T) { + spec := &v1alpha1.TaskRunSpec{} + gt := func(n string) (*v1alpha1.Task, error) { return nil, fmt.Errorf("shouldn't be called") } + _, _, err := GetTaskSpec(spec, "mytaskrun", gt) + if err == nil { + t.Fatalf("Expected error resolving spec with no embedded or referenced task spec but didn't get error") + } +} + +func TestGetTaskSpec_Error(t *testing.T) { + spec := &v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "orchestrate", + }, + } + gt := func(n string) (*v1alpha1.Task, error) { return nil, fmt.Errorf("something went wrong") } + _, _, err := GetTaskSpec(spec, "mytaskrun", gt) + if err == nil { + t.Fatalf("Expected error when unable to find referenced Task but got none") + } +} diff --git a/pkg/reconciler/v1alpha1/taskrun/taskrun.go b/pkg/reconciler/v1alpha1/taskrun/taskrun.go index 493df203280..cdcf5b6f3f3 100644 --- a/pkg/reconciler/v1alpha1/taskrun/taskrun.go +++ b/pkg/reconciler/v1alpha1/taskrun/taskrun.go @@ -182,9 +182,20 @@ func (c *Reconciler) Reconcile(ctx context.Context, key string) error { } func (c *Reconciler) reconcile(ctx context.Context, tr *v1alpha1.TaskRun) error { - rtr, err := resources.ResolveTaskRun(tr, c.taskLister.Tasks(tr.Namespace).Get, c.resourceLister.PipelineResources(tr.Namespace).Get) + spec, taskName, err := resources.GetTaskSpec(&tr.Spec, tr.Name, c.taskLister.Tasks(tr.Namespace).Get) if err != nil { - c.Logger.Error("Failed to resolve references for taskrun %s with error %v", tr.Name, err) + c.Logger.Error("Failed to determine Task spec to use for taskrun %s: %v", tr.Name, err) + tr.Status.SetCondition(&duckv1alpha1.Condition{ + Type: duckv1alpha1.ConditionSucceeded, + Status: corev1.ConditionFalse, + Reason: ReasonFailedResolution, + Message: err.Error(), + }) + return nil + } + rtr, err := resources.ResolveTaskRun(spec, taskName, tr.Spec.Inputs.Resources, tr.Spec.Outputs.Resources, c.resourceLister.PipelineResources(tr.Namespace).Get) + if err != nil { + c.Logger.Error("Failed to resolve references for taskrun %s: %v", tr.Name, err) tr.Status.SetCondition(&duckv1alpha1.Condition{ Type: duckv1alpha1.ConditionSucceeded, Status: corev1.ConditionFalse, @@ -195,7 +206,7 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1alpha1.TaskRun) error } if err := ValidateTaskRunAndTask(tr.Spec.Inputs.Params, rtr); err != nil { - c.Logger.Error("Failed to validate taskrun %s with error %v", tr.Name, err) + c.Logger.Error("Failed to validate taskrun %s: %v", tr.Name, err) tr.Status.SetCondition(&duckv1alpha1.Condition{ Type: duckv1alpha1.ConditionSucceeded, Status: corev1.ConditionFalse,