@@ -332,29 +332,49 @@ func (c *Reconciler) finishReconcileUpdateEmitEvents(ctx context.Context, pr *v1
332332 return errs
333333}
334334
335- // resolvePipelineState will attempt to resolve each referenced task in the pipeline's spec and all of the resources
335+ // resolvePipelineState will attempt to resolve each referenced pipeline task in the pipeline's spec and all of the resources
336336// specified by those tasks.
337337func (c * Reconciler ) resolvePipelineState (
338338 ctx context.Context ,
339- tasks []v1.PipelineTask ,
339+ pipelineTasks []v1.PipelineTask ,
340340 pipelineMeta * metav1.ObjectMeta ,
341341 pr * v1.PipelineRun ,
342342 pst resources.PipelineRunState ,
343343) (resources.PipelineRunState , error ) {
344344 ctx , span := c .tracerProvider .Tracer (TracerName ).Start (ctx , "resolvePipelineState" )
345345 defer span .End ()
346- // Resolve each task individually because they each could have a different reference context (remote or local).
347- for _ , task := range tasks {
346+ // Resolve each pipeline task individually because they each could have a different reference context (remote or local).
347+ for _ , pipelineTask := range pipelineTasks {
348348 // We need the TaskRun name to ensure that we don't perform an additional remote resolution request for a PipelineTask
349349 // in the TaskRun reconciler.
350- trName := resources .GetTaskRunName (pr .Status .ChildReferences , task .Name , pr .Name )
350+ trName := resources .GetTaskRunName (
351+ pr .Status .ChildReferences ,
352+ pipelineTask .Name ,
353+ pr .Name ,
354+ )
351355
352356 // list VerificationPolicies for trusted resources
353357 vp , err := c .verificationPolicyLister .VerificationPolicies (pr .Namespace ).List (labels .Everything ())
354358 if err != nil {
355359 return nil , fmt .Errorf ("failed to list VerificationPolicies from namespace %s with error %w" , pr .Namespace , err )
356360 }
357- fn := tresources .GetTaskFunc (ctx , c .KubeClientSet , c .PipelineClientSet , c .resolutionRequester , pr , task .TaskRef , trName , pr .Namespace , pr .Spec .TaskRunTemplate .ServiceAccountName , vp )
361+
362+ getTaskFunc := tresources .GetTaskFunc (
363+ ctx ,
364+ c .KubeClientSet ,
365+ c .PipelineClientSet ,
366+ c .resolutionRequester ,
367+ pr ,
368+ pipelineTask .TaskRef ,
369+ trName ,
370+ pr .Namespace ,
371+ pr .Spec .TaskRunTemplate .ServiceAccountName ,
372+ vp ,
373+ )
374+
375+ getTaskRunFunc := func (name string ) (* v1.TaskRun , error ) {
376+ return c .taskRunLister .TaskRuns (pr .Namespace ).Get (name )
377+ }
358378
359379 getCustomRunFunc := func (name string ) (* v1beta1.CustomRun , error ) {
360380 r , err := c .customRunLister .CustomRuns (pr .Namespace ).Get (name )
@@ -366,12 +386,10 @@ func (c *Reconciler) resolvePipelineState(
366386
367387 resolvedTask , err := resources .ResolvePipelineTask (ctx ,
368388 * pr ,
369- fn ,
370- func (name string ) (* v1.TaskRun , error ) {
371- return c .taskRunLister .TaskRuns (pr .Namespace ).Get (name )
372- },
389+ getTaskFunc ,
390+ getTaskRunFunc ,
373391 getCustomRunFunc ,
374- task ,
392+ pipelineTask ,
375393 pst ,
376394 )
377395 if err != nil {
@@ -393,8 +411,9 @@ func (c *Reconciler) resolvePipelineState(
393411 }
394412 return nil , controller .NewPermanentError (err )
395413 }
414+
396415 if resolvedTask .ResolvedTask != nil && resolvedTask .ResolvedTask .VerificationResult != nil {
397- cond , err := conditionFromVerificationResult (resolvedTask .ResolvedTask .VerificationResult , pr , task .Name )
416+ cond , err := conditionFromVerificationResult (resolvedTask .ResolvedTask .VerificationResult , pr , pipelineTask .Name )
398417 pr .Status .SetCondition (cond )
399418 if err != nil {
400419 pr .Status .MarkFailed (v1 .PipelineRunReasonResourceVerificationFailed .String (), err .Error ())
@@ -403,6 +422,7 @@ func (c *Reconciler) resolvePipelineState(
403422 }
404423 pst = append (pst , resolvedTask )
405424 }
425+
406426 return pst , nil
407427}
408428
@@ -549,7 +569,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
549569 }
550570
551571 resources .ApplyParametersToWorkspaceBindings (ctx , pr )
552- // Make a deep copy of the Pipeline and its Tasks before value substution .
572+ // Make a deep copy of the Pipeline and its Tasks before value substitution .
553573 // This is used to find referenced pipeline-level params at each PipelineTask when validate param enum subset requirement
554574 originalPipeline := pipelineSpec .DeepCopy ()
555575 originalTasks := originalPipeline .Tasks
@@ -571,9 +591,9 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
571591 return controller .NewPermanentError (err )
572592 }
573593
574- // pipelineState holds a list of pipeline tasks after fetching their resolved Task specs.
575- // pipelineState also holds a taskRun for each pipeline task after the taskRun is created
576- // pipelineState is instantiated and updated on every reconcile cycle
594+ // pipelineRunState holds a list of pipeline tasks after fetching their resolved Task specs.
595+ // pipelineRunState also holds a taskRun for each pipeline task after the taskRun is created
596+ // pipelineRunState is instantiated and updated on every reconcile cycle
577597 // Resolve the set of tasks (and possibly task runs).
578598 tasks := pipelineSpec .Tasks
579599 if len (pipelineSpec .Finally ) > 0 {
@@ -584,7 +604,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
584604 // - those with a completed (Task|Custom)Run reference (i.e. those that finished running)
585605 // - those without a (Task|Custom)Run reference
586606 // We resolve the status for the former first, to collect all results available at this stage
587- // We know that tasks in progress or completed have had their fan-out alteady calculated so
607+ // We know that tasks in progress or completed have had their fan-out already calculated so
588608 // they can be safely processed in the first iteration. The underlying assumption is that if
589609 // a PipelineTask has at least one TaskRun associated, then all its TaskRuns have been
590610 // created already.
@@ -604,9 +624,9 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
604624 notStartedTasks = append (notStartedTasks , task )
605625 }
606626 }
627+
607628 // First iteration
608- pst := resources.PipelineRunState {}
609- pipelineRunState , err := c .resolvePipelineState (ctx , ranOrRunningTasks , pipelineMeta .ObjectMeta , pr , pst )
629+ pipelineRunState , err := c .resolvePipelineState (ctx , ranOrRunningTasks , pipelineMeta .ObjectMeta , pr , resources.PipelineRunState {})
610630 switch {
611631 case errors .Is (err , remote .ErrRequestInProgress ):
612632 message := fmt .Sprintf ("PipelineRun %s/%s awaiting remote resource" , pr .Namespace , pr .Name )
@@ -692,7 +712,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
692712 }
693713 }
694714
695- // check if pipeline run is not gracefully cancelled and there are active task runs, which require cancelling
715+ // check if pipeline run is gracefully cancelled and there are active pipeline task runs, which require cancelling
696716 if pr .IsGracefullyCancelled () && pipelineRunFacts .IsRunning () {
697717 // If the pipelinerun is cancelled, cancel tasks, but run finally
698718 err := gracefullyCancelPipelineRun (ctx , logger , pr , c .PipelineClientSet )
@@ -781,6 +801,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
781801 }
782802 }
783803 }
804+
784805 if err := c .runNextSchedulableTask (ctx , pr , pipelineRunFacts ); err != nil {
785806 return err
786807 }
@@ -811,14 +832,18 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
811832 pr .Status .ChildReferences = pipelineRunFacts .GetChildReferences ()
812833
813834 pr .Status .SkippedTasks = pipelineRunFacts .GetSkippedTasks ()
814-
815- taskStatus := pipelineRunFacts .GetPipelineTaskStatus ()
816- finalTaskStatus := pipelineRunFacts .GetPipelineFinalTaskStatus ()
817- taskStatus = kmap .Union (taskStatus , finalTaskStatus )
835+ pipelineTaskStatus := pipelineRunFacts .GetPipelineTaskStatus ()
836+ finalPipelineTaskStatus := pipelineRunFacts .GetPipelineFinalTaskStatus ()
837+ pipelineTaskStatus = kmap .Union (pipelineTaskStatus , finalPipelineTaskStatus )
818838
819839 if after .Status == corev1 .ConditionTrue || after .Status == corev1 .ConditionFalse {
820- pr .Status .Results , err = resources .ApplyTaskResultsToPipelineResults (ctx , pipelineSpec .Results ,
821- pipelineRunFacts .State .GetTaskRunsResults (), pipelineRunFacts .State .GetRunsResults (), taskStatus )
840+ pr .Status .Results , err = resources .ApplyTaskResultsToPipelineResults (
841+ ctx ,
842+ pipelineSpec .Results ,
843+ pipelineRunFacts .State .GetTaskRunsResults (),
844+ pipelineRunFacts .State .GetRunsResults (),
845+ pipelineTaskStatus ,
846+ )
822847 if err != nil {
823848 pr .Status .MarkFailed (v1 .PipelineRunReasonCouldntGetPipelineResult .String (),
824849 "Failed to get PipelineResult from TaskRun Results for PipelineRun %s: %s" ,
@@ -944,6 +969,7 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1.Pipeline
944969 }
945970 }
946971 }
972+
947973 return nil
948974}
949975
@@ -960,11 +986,12 @@ func (c *Reconciler) setFinallyStartedTimeIfNeeded(pr *v1.PipelineRun, facts *re
960986func (c * Reconciler ) createTaskRuns (ctx context.Context , rpt * resources.ResolvedPipelineTask , pr * v1.PipelineRun , facts * resources.PipelineRunFacts ) ([]* v1.TaskRun , error ) {
961987 ctx , span := c .tracerProvider .Tracer (TracerName ).Start (ctx , "createTaskRuns" )
962988 defer span .End ()
963- var taskRuns [] * v1. TaskRun
989+
964990 var matrixCombinations []v1.Params
965991 if rpt .PipelineTask .IsMatrixed () {
966992 matrixCombinations = rpt .PipelineTask .Matrix .FanOut ()
967993 }
994+
968995 // validate the param values meet resolved Task Param Enum requirements before creating TaskRuns
969996 if config .FromContextOrDefaults (ctx ).FeatureFlags .EnableParamEnum {
970997 for i := range rpt .TaskRunNames {
@@ -981,6 +1008,8 @@ func (c *Reconciler) createTaskRuns(ctx context.Context, rpt *resources.Resolved
9811008 }
9821009 }
9831010 }
1011+
1012+ var taskRuns []* v1.TaskRun
9841013 for i , taskRunName := range rpt .TaskRunNames {
9851014 var params v1.Params
9861015 if len (matrixCombinations ) > i {
@@ -993,6 +1022,7 @@ func (c *Reconciler) createTaskRuns(ctx context.Context, rpt *resources.Resolved
9931022 }
9941023 taskRuns = append (taskRuns , taskRun )
9951024 }
1025+
9961026 return taskRuns , nil
9971027}
9981028
0 commit comments