@@ -428,7 +428,15 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err
428428 return controller .NewPermanentError (err )
429429 }
430430
431- for _ , rprt := range pipelineRunState {
431+ // Build PipelineRunFacts with a list of resolved pipeline tasks,
432+ // dag tasks graph and final tasks graph
433+ pipelineRunFacts := & resources.PipelineRunFacts {
434+ State : pipelineRunState ,
435+ TasksGraph : d ,
436+ FinalTasksGraph : dfinally ,
437+ }
438+
439+ for _ , rprt := range pipelineRunFacts .State {
432440 err := taskrun .ValidateResolvedTaskResources (rprt .PipelineTask .Params , rprt .ResolvedTaskResources )
433441 if err != nil {
434442 logger .Errorf ("Failed to validate pipelinerun %q with error %v" , pr .Name , err )
@@ -437,7 +445,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err
437445 }
438446 }
439447
440- if pipelineRunState .IsBeforeFirstTaskRun () {
448+ if pipelineRunFacts . State .IsBeforeFirstTaskRun () {
441449 if pr .HasVolumeClaimTemplate () {
442450 // create workspace PVC from template
443451 if err = c .pvcHandler .CreatePersistentVolumeClaimsForWorkspaces (pr .Spec .Workspaces , pr .GetOwnerReference (), pr .Namespace ); err != nil {
@@ -467,11 +475,11 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err
467475 return controller .NewPermanentError (err )
468476 }
469477
470- if err := c .runNextSchedulableTask (ctx , pr , d , dfinally , pipelineRunState , as ); err != nil {
478+ if err := c .runNextSchedulableTask (ctx , pr , pipelineRunFacts , as ); err != nil {
471479 return err
472480 }
473481
474- after := pipelineRunState .GetPipelineConditionStatus (pr , logger , d , dfinally )
482+ after := pipelineRunFacts .GetPipelineConditionStatus (pr , logger )
475483 switch after .Status {
476484 case corev1 .ConditionTrue :
477485 pr .Status .MarkSucceeded (after .Reason , after .Message )
@@ -482,37 +490,28 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err
482490 }
483491 // Read the condition the way it was set by the Mark* helpers
484492 after = pr .Status .GetCondition (apis .ConditionSucceeded )
485- pr .Status .TaskRuns = pipelineRunState .GetTaskRunsStatus (pr )
486- pr .Status .SkippedTasks = pipelineRunState .GetSkippedTasks (pr , d )
493+ pr .Status .TaskRuns = pipelineRunFacts . State .GetTaskRunsStatus (pr )
494+ pr .Status .SkippedTasks = pipelineRunFacts .GetSkippedTasks ()
487495 logger .Infof ("PipelineRun %s status is being set to %s" , pr .Name , after )
488496 return nil
489497}
490498
491499// runNextSchedulableTask gets the next schedulable Tasks from the dag based on the current
492500// pipeline run state, and starts them
493501// after all DAG tasks are done, it's responsible for scheduling final tasks and start executing them
494- func (c * Reconciler ) runNextSchedulableTask (ctx context.Context , pr * v1beta1.PipelineRun , d * dag. Graph , dfinally * dag. Graph , pipelineRunState resources.PipelineRunState , as artifacts.ArtifactStorageInterface ) error {
502+ func (c * Reconciler ) runNextSchedulableTask (ctx context.Context , pr * v1beta1.PipelineRun , pipelineRunFacts * resources.PipelineRunFacts , as artifacts.ArtifactStorageInterface ) error {
495503
496504 logger := logging .FromContext (ctx )
497505 recorder := controller .GetEventRecorder (ctx )
498506
499- var nextRprts []* resources.ResolvedPipelineRunTask
500-
501- // when pipeline run is stopping, do not schedule any new task and only
502- // wait for all running tasks to complete and report their status
503- if ! pipelineRunState .IsStopping (d ) {
504- // candidateTasks is initialized to DAG root nodes to start pipeline execution
505- // candidateTasks is derived based on successfully finished tasks and/or skipped tasks
506- candidateTasks , err := dag .GetSchedulable (d , pipelineRunState .SuccessfulOrSkippedDAGTasks (d )... )
507- if err != nil {
508- logger .Errorf ("Error getting potential next tasks for valid pipelinerun %s: %v" , pr .Name , err )
509- return controller .NewPermanentError (err )
510- }
511- // nextRprts holds a list of pipeline tasks which should be executed next
512- nextRprts = pipelineRunState .GetNextTasks (candidateTasks )
507+ // nextRprts holds a list of pipeline tasks which should be executed next
508+ nextRprts , err := pipelineRunFacts .DAGExecutionQueue ()
509+ if err != nil {
510+ logger .Errorf ("Error getting potential next tasks for valid pipelinerun %s: %v" , pr .Name , err )
511+ return controller .NewPermanentError (err )
513512 }
514513
515- resolvedResultRefs , err := resources .ResolveResultRefs (pipelineRunState , nextRprts )
514+ resolvedResultRefs , err := resources .ResolveResultRefs (pipelineRunFacts . State , nextRprts )
516515 if err != nil {
517516 logger .Infof ("Failed to resolve all task params for %q with error %v" , pr .Name , err )
518517 pr .Status .MarkFailed (ReasonFailedValidation , err .Error ())
@@ -522,10 +521,10 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.Pip
522521 resources .ApplyTaskResults (nextRprts , resolvedResultRefs )
523522
524523 // GetFinalTasks only returns tasks when a DAG is complete
525- nextRprts = append (nextRprts , pipelineRunState .GetFinalTasks (d , dfinally )... )
524+ nextRprts = append (nextRprts , pipelineRunFacts .GetFinalTasks ()... )
526525
527526 for _ , rprt := range nextRprts {
528- if rprt == nil || rprt .Skip (pipelineRunState , d ) {
527+ if rprt == nil || rprt .Skip (pipelineRunFacts ) {
529528 continue
530529 }
531530 if rprt .ResolvedConditionChecks == nil || rprt .ResolvedConditionChecks .IsSuccess () {
0 commit comments