Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pipelinerun as "cancelled" when taskrun is "cancelled" #1935

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
logger.Infof("TaskRun %s is cancelled, so PipelineRun %s is 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