diff --git a/pkg/reconciler/pipelinerun/resources/apply.go b/pkg/reconciler/pipelinerun/resources/apply.go index f57ec189497..0cb2c700072 100644 --- a/pkg/reconciler/pipelinerun/resources/apply.go +++ b/pkg/reconciler/pipelinerun/resources/apply.go @@ -330,7 +330,7 @@ func replaceParamValues(params v1beta1.Params, stringReplacements map[string]str // and omitted from the returned slice. A nil slice is returned if no results are passed in or all // results are invalid. func ApplyTaskResultsToPipelineResults( - ctx context.Context, + _ context.Context, results []v1beta1.PipelineResult, taskRunResults map[string][]v1beta1.TaskRunResult, customTaskResults map[string][]v1beta1.CustomRunResult, diff --git a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go index fc2d6a8c5a7..f538f643236 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go @@ -183,7 +183,7 @@ func TestGetPipelineFunc(t *testing.T) { Name: "simple", Bundle: u.Host + "/remote-pipeline-without-defaults", }, - expected: simplePipelineWithSpecParamAndKind(v1beta1.ParamTypeString, v1beta1.NamespacedTaskKind), + expected: simplePipelineWithSpecParamAndKind(), }} for _, tc := range testcases { @@ -886,7 +886,7 @@ func simplePipelineWithSpecAndParam(pt v1beta1.ParamType) *v1beta1.Pipeline { return p } -func simplePipelineWithSpecParamAndKind(pt v1beta1.ParamType, tk v1beta1.TaskKind) *v1beta1.Pipeline { +func simplePipelineWithSpecParamAndKind() *v1beta1.Pipeline { p := simplePipelineWithBaseSpec() p.Spec.Params = []v1beta1.ParamSpec{{ Name: "foo", diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go index ae8cd47e1d4..607ea27f6a8 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go @@ -665,11 +665,7 @@ func (t *ResolvedPipelineTask) resolvePipelineRunTaskWithTaskRun( } } - if err := t.resolveTaskResources(ctx, getTask, pipelineTask, taskRun); err != nil { - return err - } - - return nil + return t.resolveTaskResources(ctx, getTask, pipelineTask, taskRun) } func (t *ResolvedPipelineTask) resolveTaskResources( @@ -812,7 +808,7 @@ func getRunNamesFromChildRefs(childRefs []v1beta1.ChildStatusReference, ptName s // resolvePipelineTaskResources matches PipelineResources referenced by pt inputs and outputs with the // providedResources and returns an instance of ResolvedTask. -func resolvePipelineTaskResources(pt v1beta1.PipelineTask, ts *v1beta1.TaskSpec, taskName string, kind v1beta1.TaskKind) (*resources.ResolvedTask, error) { +func resolvePipelineTaskResources(_ v1beta1.PipelineTask, ts *v1beta1.TaskSpec, taskName string, kind v1beta1.TaskKind) (*resources.ResolvedTask, error) { rtr := resources.ResolvedTask{ TaskName: taskName, TaskSpec: ts, diff --git a/pkg/reconciler/pipelinerun/resources/resultrefresolution.go b/pkg/reconciler/pipelinerun/resources/resultrefresolution.go index 094d628b622..c6c97c1e67d 100644 --- a/pkg/reconciler/pipelinerun/resources/resultrefresolution.go +++ b/pkg/reconciler/pipelinerun/resources/resultrefresolution.go @@ -71,29 +71,6 @@ func validateArrayResultsIndex(allResolvedResultRefs ResolvedResultRefs) (Resolv return allResolvedResultRefs, "", nil } -// extractResultRefs resolves any ResultReference that are found in param or pipeline result -// Returns nil if none are found -func extractResultRefsForParam(pipelineRunState PipelineRunState, param v1beta1.Param) (ResolvedResultRefs, error) { - expressions, ok := v1beta1.GetVarSubstitutionExpressionsForParam(param) - if ok { - return extractResultRefs(expressions, pipelineRunState) - } - return nil, nil -} - -func extractResultRefs(expressions []string, pipelineRunState PipelineRunState) (ResolvedResultRefs, error) { - resultRefs := v1beta1.NewResultRefs(expressions) - var resolvedResultRefs ResolvedResultRefs - for _, resultRef := range resultRefs { - resolvedResultRef, _, err := resolveResultRef(pipelineRunState, resultRef) - if err != nil { - return nil, err - } - resolvedResultRefs = append(resolvedResultRefs, resolvedResultRef) - } - return removeDup(resolvedResultRefs), nil -} - func removeDup(refs ResolvedResultRefs) ResolvedResultRefs { if refs == nil { return nil diff --git a/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go b/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go index 9c2577c7df6..09d04cddd40 100644 --- a/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go @@ -1,8 +1,6 @@ package resources import ( - "fmt" - "sort" "strings" "testing" @@ -22,10 +20,6 @@ var ( Type: apis.ConditionSucceeded, Status: corev1.ConditionTrue, } - failedCondition = apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - } ) var pipelineRunState = PipelineRunState{{ @@ -172,339 +166,6 @@ var pipelineRunState = PipelineRunState{{ }, }} -func TestTaskParamResolver_ResolveResultRefs(t *testing.T) { - for _, tt := range []struct { - name string - pipelineRunState PipelineRunState - param v1beta1.Param - want ResolvedResultRefs - wantErr bool - }{{ - name: "successful resolution: param not using result reference", - pipelineRunState: PipelineRunState{{ - TaskRunName: "aTaskRun", - TaskRun: &v1beta1.TaskRun{ObjectMeta: metav1.ObjectMeta{Name: "aTaskRun"}}, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("explicitValueNoResultReference"), - }, - want: nil, - wantErr: false, - }, { - name: "successful resolution: using result reference", - pipelineRunState: PipelineRunState{{ - TaskRunName: "aTaskRun", - TaskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aTaskRun"}, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{successCondition}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - TaskRunResults: []v1beta1.TaskRunResult{{ - Name: "aResult", - Value: *v1beta1.NewStructuredValues("aResultValue"), - }}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult)"), - }, - want: ResolvedResultRefs{{ - Value: *v1beta1.NewStructuredValues("aResultValue"), - ResultReference: v1beta1.ResultRef{ - PipelineTask: "aTask", - Result: "aResult", - }, - FromTaskRun: "aTaskRun", - }}, - wantErr: false, - }, { - name: "successful resolution: using multiple result reference", - pipelineRunState: PipelineRunState{{ - TaskRunName: "aTaskRun", - TaskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aTaskRun"}, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{successCondition}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - TaskRunResults: []v1beta1.TaskRunResult{{ - Name: "aResult", - Value: *v1beta1.NewStructuredValues("aResultValue"), - }}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }, { - TaskRunName: "bTaskRun", - TaskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{Name: "bTaskRun"}, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{successCondition}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - TaskRunResults: []v1beta1.TaskRunResult{{ - Name: "bResult", - Value: *v1beta1.NewStructuredValues("bResultValue"), - }}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "bTask", - TaskRef: &v1beta1.TaskRef{Name: "bTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult) $(tasks.bTask.results.bResult)"), - }, - want: ResolvedResultRefs{{ - Value: *v1beta1.NewStructuredValues("aResultValue"), - ResultReference: v1beta1.ResultRef{ - PipelineTask: "aTask", - Result: "aResult", - }, - FromTaskRun: "aTaskRun", - }, { - Value: *v1beta1.NewStructuredValues("bResultValue"), - ResultReference: v1beta1.ResultRef{ - PipelineTask: "bTask", - Result: "bResult", - }, - FromTaskRun: "bTaskRun", - }}, - wantErr: false, - }, { - name: "successful resolution: duplicate result references", - pipelineRunState: PipelineRunState{{ - TaskRunName: "aTaskRun", - TaskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aTaskRun"}, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{successCondition}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - TaskRunResults: []v1beta1.TaskRunResult{{ - Name: "aResult", - Value: *v1beta1.NewStructuredValues("aResultValue"), - }}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult) $(tasks.aTask.results.aResult)"), - }, - want: ResolvedResultRefs{{ - Value: *v1beta1.NewStructuredValues("aResultValue"), - ResultReference: v1beta1.ResultRef{ - PipelineTask: "aTask", - Result: "aResult", - }, - FromTaskRun: "aTaskRun", - }}, - wantErr: false, - }, { - name: "unsuccessful resolution: referenced result doesn't exist in referenced task", - pipelineRunState: PipelineRunState{{ - TaskRunName: "aTaskRun", - TaskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aTaskRun"}, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{successCondition}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult)"), - }, - want: nil, - wantErr: true, - }, { - name: "unsuccessful resolution: pipeline task missing", - pipelineRunState: PipelineRunState{}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult)"), - }, - want: nil, - wantErr: true, - }, { - name: "unsuccessful resolution: task run missing", - pipelineRunState: PipelineRunState{{ - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult)"), - }, - want: nil, - wantErr: true, - }, { - name: "failed resolution: using result reference to a failed task", - pipelineRunState: PipelineRunState{{ - TaskRunName: "aTaskRun", - TaskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aTaskRun"}, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{failedCondition}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aTask", - TaskRef: &v1beta1.TaskRef{Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aTask.results.aResult)"), - }, - want: nil, - wantErr: true, - }, { - name: "successful resolution: using result reference to a Run", - pipelineRunState: PipelineRunState{{ - CustomTask: true, - RunObjectName: "aRun", - RunObject: &v1beta1.CustomRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aRun"}, - Status: v1beta1.CustomRunStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{successCondition}, - }, - CustomRunStatusFields: v1beta1.CustomRunStatusFields{ - Results: []v1beta1.CustomRunResult{{ - Name: "aResult", - Value: "aResultValue", - }}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aCustomPipelineTask", - TaskRef: &v1beta1.TaskRef{APIVersion: "example.dev/v0", Kind: "Example", Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aCustomPipelineTask.results.aResult)"), - }, - want: ResolvedResultRefs{{ - Value: *v1beta1.NewStructuredValues("aResultValue"), - ResultReference: v1beta1.ResultRef{ - PipelineTask: "aCustomPipelineTask", - Result: "aResult", - }, - FromRun: "aRun", - }}, - wantErr: false, - }, { - name: "failed resolution: using result reference to a failed Run", - pipelineRunState: PipelineRunState{{ - CustomTask: true, - RunObjectName: "aRun", - RunObject: &v1beta1.CustomRun{ - ObjectMeta: metav1.ObjectMeta{Name: "aRun"}, - Status: v1beta1.CustomRunStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{failedCondition}, - }, - }, - }, - PipelineTask: &v1beta1.PipelineTask{ - Name: "aCustomPipelineTask", - TaskRef: &v1beta1.TaskRef{APIVersion: "example.dev/v0", Kind: "Example", Name: "aTask"}, - }, - }}, - param: v1beta1.Param{ - Name: "targetParam", - Value: *v1beta1.NewStructuredValues("$(tasks.aCustomPipelineTask.results.aResult)"), - }, - want: nil, - wantErr: true, - }} { - t.Run(tt.name, func(t *testing.T) { - t.Logf("test name: %s\n", tt.name) - got, err := extractResultRefsForParam(tt.pipelineRunState, tt.param) - // sort result ref based on task name to guarantee an certain order - sort.SliceStable(got, func(i, j int) bool { - fromI := got[i].FromTaskRun - if fromI == "" { - fromI = got[i].FromRun - } - fromJ := got[j].FromTaskRun - if fromJ == "" { - fromJ = got[j].FromRun - } - return strings.Compare(fromI, fromJ) < 0 - }) - if (err != nil) != tt.wantErr { - t.Fatalf("ResolveResultRef() error = %v, wantErr %v", err, tt.wantErr) - } - if len(tt.want) != len(got) { - t.Fatalf("incorrect number of refs, want %d, got %d", len(tt.want), len(got)) - } - for _, rGot := range got { - foundMatch := false - for _, rWant := range tt.want { - if d := cmp.Diff(rGot, rWant); d == "" { - foundMatch = true - } - } - if !foundMatch { - t.Fatalf("Expected resolved refs:\n%s\n\nbut received:\n%s\n", resolvedSliceAsString(tt.want), resolvedSliceAsString(got)) - } - } - }) - } -} - -func resolvedSliceAsString(rs []*ResolvedResultRef) string { - var s []string - for _, r := range rs { - s = append(s, fmt.Sprintf("%#v", *r)) - } - return fmt.Sprintf("[\n%s\n]", strings.Join(s, ",\n")) -} - func TestResolveResultRefs(t *testing.T) { for _, tt := range []struct { name string