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