From 2e34d0484f888e0a550370b5e19b5f34bb5d6ab9 Mon Sep 17 00:00:00 2001 From: zwwang Date: Wed, 11 May 2022 16:09:36 +0800 Subject: [PATCH] wait for pipelineloop-break-operation task final status before breaking the loop --- .../pipelinelooprun/pipelinelooprun.go | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go b/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go index aba1290618..59e1fe63c8 100644 --- a/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go +++ b/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go @@ -748,36 +748,40 @@ func (c *Reconciler) updatePipelineRunStatus(ctx context.Context, iterationEleme } for _, runStatus := range pr.Status.Runs { if strings.HasPrefix(runStatus.PipelineTaskName, "pipelineloop-break-operation") { - err = c.cancelAllPipelineRuns(ctx, run) - if err != nil { - return 0, nil, nil, fmt.Errorf("could not cancel PipelineRuns belonging to Run %s."+ - " %#v", run.Name, err) + if !runStatus.Status.GetCondition(apis.ConditionSucceeded).IsUnknown() { + err = c.cancelAllPipelineRuns(ctx, run) + if err != nil { + return 0, nil, nil, fmt.Errorf("could not cancel PipelineRuns belonging to Run %s."+ + " %#v", run.Name, err) + } + // Mark run successful and stop the loop pipelinerun + run.Status.MarkRunSucceeded(pipelineloopv1alpha1.PipelineLoopRunReasonSucceeded.String(), + "PipelineRuns completed successfully with the conditions are met") + run.Status.Results = []runv1alpha1.RunResult{{ + Name: "condition", + Value: "pass", + }} + break } - // Mark run successful and stop the loop pipelinerun - run.Status.MarkRunSucceeded(pipelineloopv1alpha1.PipelineLoopRunReasonSucceeded.String(), - "PipelineRuns completed successfully with the conditions are met") - run.Status.Results = []runv1alpha1.RunResult{{ - Name: "condition", - Value: "pass", - }} - break } } for _, taskRunStatus := range pr.Status.TaskRuns { if strings.HasPrefix(taskRunStatus.PipelineTaskName, "pipelineloop-break-operation") { - err = c.cancelAllPipelineRuns(ctx, run) - if err != nil { - return 0, nil, nil, fmt.Errorf("could not cancel PipelineRuns belonging to task run %s."+ - " %#v", run.Name, err) + if !taskRunStatus.Status.GetCondition(apis.ConditionSucceeded).IsUnknown() { + err = c.cancelAllPipelineRuns(ctx, run) + if err != nil { + return 0, nil, nil, fmt.Errorf("could not cancel PipelineRuns belonging to task run %s."+ + " %#v", run.Name, err) + } + // Mark run successful and stop the loop pipelinerun + run.Status.MarkRunSucceeded(pipelineloopv1alpha1.PipelineLoopRunReasonSucceeded.String(), + "PipelineRuns completed successfully with the conditions are met") + run.Status.Results = []runv1alpha1.RunResult{{ + Name: "condition", + Value: "pass", + }} + break } - // Mark run successful and stop the loop pipelinerun - run.Status.MarkRunSucceeded(pipelineloopv1alpha1.PipelineLoopRunReasonSucceeded.String(), - "PipelineRuns completed successfully with the conditions are met") - run.Status.Results = []runv1alpha1.RunResult{{ - Name: "condition", - Value: "pass", - }} - break } } }