@@ -3925,6 +3925,132 @@ func TestReconcilePipeline_TaskSpecMetadata(t *testing.T) {
39253925 }
39263926}
39273927
3928+ func TestReconcileWithTaskResultsInFinalTasks (t * testing.T ) {
3929+ names .TestingSeed ()
3930+ ps := []* v1beta1.Pipeline {tb .Pipeline ("test-pipeline" , tb .PipelineNamespace ("foo" ), tb .PipelineSpec (
3931+ tb .PipelineTask ("dag-task-1" , "dag-task" ),
3932+ tb .PipelineTask ("dag-task-2" , "dag-task" ),
3933+ tb .FinalPipelineTask ("final-task-1" , "final-task-1" ,
3934+ tb .PipelineTaskParam ("finalParam" , "$(tasks.dag-task-1.results.aResult)" ),
3935+ ),
3936+ tb .FinalPipelineTask ("final-task-2" , "final-task-2" ,
3937+ tb .PipelineTaskParam ("finalParam" , "$(tasks.dag-task-2.results.aResult)" ),
3938+ ),
3939+ ))}
3940+ prs := []* v1beta1.PipelineRun {tb .PipelineRun ("test-pipeline-run-final-task-results" , tb .PipelineRunNamespace ("foo" ),
3941+ tb .PipelineRunSpec ("test-pipeline" ,
3942+ tb .PipelineRunServiceAccountName ("test-sa-0" ),
3943+ ),
3944+ )}
3945+ ts := []* v1beta1.Task {
3946+ tb .Task ("dag-task" , tb .TaskNamespace ("foo" )),
3947+ tb .Task ("final-task-1" , tb .TaskNamespace ("foo" ),
3948+ tb .TaskSpec (
3949+ tb .TaskParam ("finalParam" , v1beta1 .ParamTypeString ),
3950+ ),
3951+ ),
3952+ tb .Task ("final-task-2" , tb .TaskNamespace ("foo" ),
3953+ tb .TaskSpec (
3954+ tb .TaskParam ("finalParam" , v1beta1 .ParamTypeString ),
3955+ ),
3956+ ),
3957+ }
3958+ trs := []* v1beta1.TaskRun {
3959+ tb .TaskRun ("test-pipeline-run-final-task-results-dag-task-1-xxyyy" ,
3960+ tb .TaskRunNamespace ("foo" ),
3961+ tb .TaskRunOwnerReference ("PipelineRun" , "test-pipeline-run-final-task-results" ,
3962+ tb .OwnerReferenceAPIVersion ("tekton.dev/v1beta1" ),
3963+ tb .Controller , tb .BlockOwnerDeletion ,
3964+ ),
3965+ tb .TaskRunLabel ("tekton.dev/pipeline" , "test-pipeline" ),
3966+ tb .TaskRunLabel ("tekton.dev/pipelineRun" , "test-pipeline-run-final-task-results" ),
3967+ tb .TaskRunLabel ("tekton.dev/pipelineTask" , "dag-task-1" ),
3968+ tb .TaskRunSpec (
3969+ tb .TaskRunTaskRef ("hello-world" ),
3970+ tb .TaskRunServiceAccountName ("test-sa" ),
3971+ ),
3972+ tb .TaskRunStatus (
3973+ tb .StatusCondition (
3974+ apis.Condition {
3975+ Type : apis .ConditionSucceeded ,
3976+ Status : corev1 .ConditionTrue ,
3977+ },
3978+ ),
3979+ tb .TaskRunResult ("aResult" , "aResultValue" ),
3980+ ),
3981+ ),
3982+ tb .TaskRun ("test-pipeline-run-final-task-results-dag-task-2-xxyyy" ,
3983+ tb .TaskRunNamespace ("foo" ),
3984+ tb .TaskRunOwnerReference ("PipelineRun" , "test-pipeline-run-final-task-results" ,
3985+ tb .OwnerReferenceAPIVersion ("tekton.dev/v1beta1" ),
3986+ tb .Controller , tb .BlockOwnerDeletion ,
3987+ ),
3988+ tb .TaskRunLabel ("tekton.dev/pipeline" , "test-pipeline" ),
3989+ tb .TaskRunLabel ("tekton.dev/pipelineRun" , "test-pipeline-run-final-task-results" ),
3990+ tb .TaskRunLabel ("tekton.dev/pipelineTask" , "dag-task-2" ),
3991+ tb .TaskRunSpec (
3992+ tb .TaskRunTaskRef ("hello-world" ),
3993+ tb .TaskRunServiceAccountName ("test-sa" ),
3994+ ),
3995+ tb .TaskRunStatus (
3996+ tb .StatusCondition (
3997+ apis.Condition {
3998+ Type : apis .ConditionSucceeded ,
3999+ Status : corev1 .ConditionFalse ,
4000+ },
4001+ ),
4002+ ),
4003+ ),
4004+ }
4005+ d := test.Data {
4006+ PipelineRuns : prs ,
4007+ Pipelines : ps ,
4008+ Tasks : ts ,
4009+ TaskRuns : trs ,
4010+ }
4011+ prt := NewPipelineRunTest (d , t )
4012+ defer prt .Cancel ()
4013+
4014+ reconciledRun , clients := prt .reconcileRun ("foo" , "test-pipeline-run-final-task-results" , []string {}, false )
4015+
4016+ expectedTaskRunName := "test-pipeline-run-final-task-results-final-task-1-9l9zj"
4017+ expectedTaskRun := tb .TaskRun (expectedTaskRunName ,
4018+ tb .TaskRunNamespace ("foo" ),
4019+ tb .TaskRunOwnerReference ("PipelineRun" , "test-pipeline-run-final-task-results" ,
4020+ tb .OwnerReferenceAPIVersion ("tekton.dev/v1beta1" ),
4021+ tb .Controller , tb .BlockOwnerDeletion ,
4022+ ),
4023+ tb .TaskRunLabel ("tekton.dev/pipeline" , "test-pipeline" ),
4024+ tb .TaskRunLabel ("tekton.dev/pipelineRun" , "test-pipeline-run-final-task-results" ),
4025+ tb .TaskRunLabel ("tekton.dev/pipelineTask" , "final-task-1" ),
4026+ tb .TaskRunSpec (
4027+ tb .TaskRunTaskRef ("final-task-1" ),
4028+ tb .TaskRunServiceAccountName ("test-sa-0" ),
4029+ tb .TaskRunParam ("finalParam" , "aResultValue" ),
4030+ ),
4031+ )
4032+ // Check that the expected TaskRun was created
4033+ actual , err := clients .Pipeline .TektonV1beta1 ().TaskRuns ("foo" ).List (metav1.ListOptions {
4034+ LabelSelector : "tekton.dev/pipelineTask=final-task-1,tekton.dev/pipelineRun=test-pipeline-run-final-task-results" ,
4035+ Limit : 1 ,
4036+ })
4037+
4038+ if err != nil {
4039+ t .Fatalf ("Failure to list TaskRun's %s" , err )
4040+ }
4041+ if len (actual .Items ) != 1 {
4042+ t .Fatalf ("Expected 1 TaskRuns got %d" , len (actual .Items ))
4043+ }
4044+ actualTaskRun := actual .Items [0 ]
4045+ if d := cmp .Diff (& actualTaskRun , expectedTaskRun , ignoreResourceVersion ); d != "" {
4046+ t .Errorf ("expected to see TaskRun %v created. Diff %s" , expectedTaskRunName , diff .PrintWantGot (d ))
4047+ }
4048+
4049+ if s := reconciledRun .Status .TaskRuns ["test-pipeline-run-final-task-results-final-task-2-mz4c7" ].Status .GetCondition (apis .ConditionSucceeded ); s .Status != corev1 .ConditionFalse {
4050+ t .Fatalf ("Status expected to be %s but is %s" , corev1 .ConditionFalse , s .Status )
4051+ }
4052+ }
4053+
39284054// NewPipelineRunTest returns PipelineRunTest with a new PipelineRun controller created with specified state through data
39294055// This PipelineRunTest can be reused for multiple PipelineRuns by calling reconcileRun for each pipelineRun
39304056func NewPipelineRunTest (data test.Data , t * testing.T ) * PipelineRunTest {
0 commit comments