Skip to content

Commit

Permalink
TEP-0090: Matrix - Implement isRunning
Browse files Browse the repository at this point in the history
[TEP-0090: Matrix][tep-0090] proposed executing a `PipelineTask` in
parallel `TaskRuns` and `Runs` with substitutions from combinations
of `Parameters` in a `Matrix`.

In this change, we implement the `isRunning` member function of
`ResolvedPipelineRunTask`. If the `ResolvedPipelineRunTask` is
matrixed, it is running if any of its `TaskRuns` not completed.

[tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
  • Loading branch information
jerop authored and tekton-robot committed Jun 15, 2022
1 parent fcbeb45 commit d48cfdd
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ func (t ResolvedPipelineRunTask) isDone(facts *PipelineRunFacts) bool {

// isRunning returns true only if the task is neither succeeded, cancelled nor failed
func (t ResolvedPipelineRunTask) isRunning() bool {
if t.IsCustomTask() {
switch {
case t.IsCustomTask():
if t.Run == nil {
return false
}
} else {
case t.IsMatrixed():
if len(t.TaskRuns) == 0 {
return false
}
default:
if t.TaskRun == nil {
return false
}
Expand Down
118 changes: 118 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3452,6 +3452,124 @@ func TestIsRunning(t *testing.T) {
CustomTask: true,
},
want: false,
}, {
name: "matrixed taskruns not started",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
},
want: false,
}, {
name: "matrixed taskruns running",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{makeStarted(trs[0]), makeStarted(trs[1])},
},
want: true,
}, {
name: "one matrixed taskrun running",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{makeStarted(trs[0]), makeSucceeded(trs[1])},
},
want: true,
}, {
name: "matrixed taskruns succeeded",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{makeSucceeded(trs[0]), makeSucceeded(trs[1])},
},
want: false,
}, {
name: "matrixed taskruns failed",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{makeFailed(trs[0]), makeFailed(trs[1])},
},
want: false,
}, {
name: "one matrixed taskrun failed, one matrixed taskrun running",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{makeFailed(trs[0]), makeStarted(trs[1])},
},
want: true,
}, {
name: "matrixed taskruns failed: retries remaining",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{makeFailed(trs[0]), makeFailed(trs[1])},
},
want: true,
}, {
name: "matrixed taskruns failed: one taskrun with retries remaining",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{makeFailed(trs[0]), withRetries(makeFailed(trs[1]))},
},
want: true,
}, {
name: "matrixed taskruns failed: no retries remaining",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{withRetries(makeFailed(trs[0])), withRetries(makeFailed(trs[1]))},
},
want: false,
}, {
name: "matrixed taskruns cancelled",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{withCancelled(makeFailed(trs[0])), withCancelled(makeFailed(trs[1]))},
},
want: false,
}, {
name: "one matrixed taskrun cancelled, one matrixed taskrun running",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{withCancelled(makeFailed(trs[0])), makeStarted(trs[1])},
},
want: true,
}, {
name: "matrixed taskruns cancelled but not failed",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{withCancelled(newTaskRun(trs[0])), withCancelled(newTaskRun(trs[1]))},
},
want: true,
}, {
name: "one matrixed taskrun cancelled but not failed",
rprt: ResolvedPipelineRunTask{
PipelineTask: matrixedPipelineTask,
TaskRuns: []*v1beta1.TaskRun{withCancelled(newTaskRun(trs[0])), makeStarted(trs[1])},
},
want: true,
}, {
name: "matrixed taskruns cancelled: retries remaining",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{withCancelled(makeFailed(trs[0])), withCancelled(makeFailed(trs[1]))},
},
want: false,
}, {
name: "one matrixed taskrun cancelled: retries remaining, one matrixed taskrun running",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{withCancelled(makeFailed(trs[0])), makeStarted(trs[1])},
},
want: true,
}, {
name: "matrixed taskruns cancelled: no retries remaining",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{withCancelled(withRetries(makeFailed(trs[0]))), withCancelled(withRetries(makeFailed(trs[1])))},
},
want: false,
}, {
name: "one matrixed taskrun cancelled: no retries remaining, one matrixed taskrun running",
rprt: ResolvedPipelineRunTask{
PipelineTask: withPipelineTaskRetries(*matrixedPipelineTask, 1),
TaskRuns: []*v1beta1.TaskRun{withCancelled(withRetries(makeFailed(trs[0]))), makeStarted(trs[1])},
},
want: true,
}} {
t.Run(tc.name, func(t *testing.T) {
if got := tc.rprt.isRunning(); got != tc.want {
Expand Down

0 comments on commit d48cfdd

Please sign in to comment.