diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go index 3de5edd6b41..38b0e45ae55 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go @@ -627,7 +627,8 @@ func resolveTask( pipelineTask v1.PipelineTask, ) (*resources.ResolvedTask, error) { rt := &resources.ResolvedTask{} - if pipelineTask.TaskRef != nil { + switch { + case pipelineTask.TaskRef != nil: // If the TaskRun has already a stored TaskSpec in its status, use it as source of truth if taskRun != nil && taskRun.Status.TaskSpec != nil { rt.TaskSpec = taskRun.Status.TaskSpec @@ -652,8 +653,13 @@ func resolveTask( } } rt.Kind = pipelineTask.TaskRef.Kind - } else { + case pipelineTask.TaskSpec != nil: rt.TaskSpec = &pipelineTask.TaskSpec.TaskSpec + default: + // If the alpha feature is enabled, and the user has configured pipelineSpec or pipelineRef, it will enter here. + // Currently, the controller is not yet adapted, and to avoid a panic, an error message is provided here. + // TODO: Adjust the logic here once the feature is supported in the future. + return nil, fmt.Errorf("Currently, Task %q does not support PipelineRef or PipelineSpec, please use TaskRef or TaskSpec instead", pipelineTask.Name) } rt.TaskSpec.SetDefaults(ctx) return rt, nil diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index cc6b38e5c5e..f247fd01c7c 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "sort" + "strings" "testing" "time" @@ -2434,6 +2435,31 @@ func TestResolvePipelineRun_PipelineTaskHasNoResources(t *testing.T) { } } +func TestResolvePipelineRun_PipelineTaskHasPipelineRef(t *testing.T) { + pt := v1.PipelineTask{ + Name: "pipeline-in-pipeline", + PipelineRef: &v1.PipelineRef{Name: "pipeline"}, + } + + getTask := func(ctx context.Context, name string) (*v1.Task, *v1.RefSource, *trustedresources.VerificationResult, error) { + return task, nil, nil, nil + } + getTaskRun := func(name string) (*v1.TaskRun, error) { return &trs[0], nil } + pr := v1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun", + }, + } + + _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetCustomRun, pt, nil) + if err == nil { + t.Errorf("Error getting tasks for fake pipeline %s, expected an error but got nil.", p.ObjectMeta.Name) + } + if !strings.Contains(err.Error(), "does not support PipelineRef or PipelineSpec") { + t.Errorf("Error getting tasks for fake pipeline %s: expected contains keyword but got %s", p.ObjectMeta.Name, err) + } +} + func TestResolvePipelineRun_TaskDoesntExist(t *testing.T) { pts := []v1.PipelineTask{{ Name: "mytask1",