Skip to content

Commit

Permalink
Adapt cherry-pick from #7407 to 0.47.x
Browse files Browse the repository at this point in the history
Add some missing functions.

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester authored and tekton-robot committed Jan 3, 2024
1 parent 66b22ed commit 37920b1
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 69 deletions.
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1beta1/customrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ func (r *CustomRun) IsSuccessful() bool {
return r != nil && r.Status.GetCondition(apis.ConditionSucceeded).IsTrue()
}

// IsFailure returns true if the TaskRun's status indicates that it has failed.
func (tr *CustomRun) IsFailure() bool {
return tr != nil && tr.Status.GetCondition(apis.ConditionSucceeded).IsFalse()
}

// GetCustomRunKey return the customrun's key for timeout handler map
func (r *CustomRun) GetCustomRunKey() string {
// The address of the pointer is a threadsafe unique identifier for the customrun
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1beta1/run_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type RunObject interface {
IsCancelled() bool
HasStarted() bool
IsDone() bool
IsFailure() bool

GetRetryCount() int
}
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ func (tr *TaskRun) IsCancelled() bool {
return tr.Spec.Status == TaskRunSpecStatusCancelled
}

// IsFailure returns true if the TaskRun's status indicates that it has failed.
func (tr *TaskRun) IsFailure() bool {
return tr != nil && tr.Status.GetCondition(apis.ConditionSucceeded).IsFalse()
}

// IsTaskRunResultVerified returns true if the TaskRun's results have been validated by spire.
func (tr *TaskRun) IsTaskRunResultVerified() bool {
return tr.Status.GetCondition(apis.ConditionType(TaskRunConditionResultsVerified.String())).IsTrue()
Expand Down
32 changes: 32 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,38 @@ func (t ResolvedPipelineTask) isConditionStatusFalse() bool {
return false
}

// haveAnyRunsFailed returns true when any of the taskRuns/customRuns have succeeded condition with status set to false
func (t ResolvedPipelineTask) haveAnyRunsFailed() bool {
if t.IsCustomTask() {
return t.haveAnyCustomRunsFailed()
}
return t.haveAnyTaskRunsFailed()
}

// haveAnyTaskRunsFailed returns true when any of the taskRuns have succeeded condition with status set to false
func (t ResolvedPipelineTask) haveAnyTaskRunsFailed() bool {
if len(t.TaskRuns) > 0 || t.PipelineTask.IsMatrixed() {
for _, taskRun := range t.TaskRuns {
if taskRun.IsFailure() {
return true
}
}
}
return t.TaskRun.IsFailure()
}

// haveAnyCustomRunsFailed returns true when a CustomRun has succeeded condition with status set to false
func (t ResolvedPipelineTask) haveAnyCustomRunsFailed() bool {
if len(t.RunObjects) > 0 || t.PipelineTask.IsMatrixed() {
for _, customRun := range t.RunObjects {
if customRun.IsFailure() {
return true
}
}
}
return t.RunObject != nil && t.RunObject.IsFailure()
}

func (t *ResolvedPipelineTask) checkParentsDone(facts *PipelineRunFacts) bool {
if facts.isFinalTask(t.PipelineTask.Name) {
return true
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,10 @@ func (facts *PipelineRunFacts) GetPipelineFinalTaskStatus() map[string]string {
switch {
// execution status is Succeeded when a task has succeeded condition with status set to true
case t.isSuccessful():
s = v1.TaskRunReasonSuccessful.String()
s = v1beta1.TaskRunReasonSuccessful.String()
// execution status is Failed when a task has succeeded condition with status set to false
case t.haveAnyRunsFailed():
s = v1.TaskRunReasonFailed.String()
s = v1beta1.TaskRunReasonFailed.String()
default:
// None includes skipped as well
s = PipelineTaskStateNone
Expand Down
Loading

0 comments on commit 37920b1

Please sign in to comment.