Skip to content

Commit

Permalink
Make pipelinerun as "cancelled" when taskrun is "cancelled"
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pli committed Jan 24, 2020
1 parent c6ee731 commit 55971b1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const (
// ReasonFailed indicates that the reason for the failure status is that one of the TaskRuns failed
ReasonFailed = "Failed"

// ReasonCancelled indicates that the reason for the cancelled status is that one of the TaskRuns cencelled
ReasonCancelled = "Cancelled"

// ReasonSucceeded indicates that the reason for the finished status is that all of the TaskRuns
// completed successfully
ReasonSucceeded = "Succeeded"
Expand Down Expand Up @@ -104,6 +107,20 @@ func (t ResolvedPipelineRunTask) IsFailure() bool {
return c.IsFalse() && retriesDone >= retries
}

// IsCancelled returns true only if the taskrun itself has cancelled
func (t ResolvedPipelineRunTask) IsCancelled() bool {
if t.TaskRun == nil {
return false
}

c := t.TaskRun.Status.GetCondition(apis.ConditionSucceeded)
if c == nil {
return false
}

return c.IsFalse() && c.Reason == v1alpha1.TaskRunSpecStatusCancelled
}

func (state PipelineRunState) toMap() map[string]*ResolvedPipelineRunTask {
m := make(map[string]*ResolvedPipelineRunTask)
for _, rprt := range state {
Expand Down Expand Up @@ -357,6 +374,16 @@ func GetPipelineConditionStatus(pr *v1alpha1.PipelineRun, state PipelineRunState

// A single failed task mean we fail the pipeline
for _, rprt := range state {
if rprt.IsCancelled() { //IsDone ensures we have crossed the retry limit
logger.Infof("TaskRun %s has cancelled, so PipelineRun %s has cancelled", rprt.TaskRunName, pr.Name)
return &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: ReasonCancelled,
Message: fmt.Sprintf("TaskRun %s has cencelled", rprt.TaskRun.Name),
}
}

if rprt.IsFailure() { //IsDone ensures we have crossed the retry limit
logger.Infof("TaskRun %s has failed, so PipelineRun %s has failed, retries done: %b", rprt.TaskRunName, pr.Name, len(rprt.TaskRun.Status.RetriesStatus))
return &apis.Condition{
Expand Down

0 comments on commit 55971b1

Please sign in to comment.