Skip to content

Commit

Permalink
TEP-0090: Matrix - ChildReferences for TaskRuns
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`.

This change implements fetching of `ChildReferences` for `TaskRuns`
created from a matrixed `PipelineTask`.

[tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
  • Loading branch information
jerop authored and tekton-robot committed Jun 21, 2022
1 parent 09c7ce4 commit 9c2da98
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
case rprt.Run != nil:
childRefs = append(childRefs, rprt.getChildRefForRun())
case rprt.TaskRun != nil:
childRefs = append(childRefs, rprt.getChildRefForTaskRun())
childRefs = append(childRefs, rprt.getChildRefForTaskRun(rprt.TaskRun))
case len(rprt.TaskRuns) != 0:
for _, taskRun := range rprt.TaskRuns {
childRefs = append(childRefs, rprt.getChildRefForTaskRun(taskRun))
}
}
}
return childRefs
Expand All @@ -264,13 +268,13 @@ func (rprt *ResolvedPipelineRunTask) getChildRefForRun() v1beta1.ChildStatusRefe
}
}

func (rprt *ResolvedPipelineRunTask) getChildRefForTaskRun() v1beta1.ChildStatusReference {
func (rprt *ResolvedPipelineRunTask) getChildRefForTaskRun(taskRun *v1beta1.TaskRun) v1beta1.ChildStatusReference {
return v1beta1.ChildStatusReference{
TypeMeta: runtime.TypeMeta{
APIVersion: rprt.TaskRun.APIVersion,
APIVersion: taskRun.APIVersion,
Kind: pipeline.TaskRunControllerName,
},
Name: rprt.TaskRunName,
Name: taskRun.Name,
PipelineTaskName: rprt.PipelineTask.Name,
WhenExpressions: rprt.PipelineTask.WhenExpressions,
}
Expand Down
88 changes: 88 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,94 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {
PipelineTaskName: "single-custom-task-1",
}},
},
{
name: "matrixed-task",
state: PipelineRunState{{
TaskRunName: "matrixed-task-run-0",
PipelineTask: &v1beta1.PipelineTask{
Name: "matrixed-task",
TaskRef: &v1beta1.TaskRef{
Name: "task",
Kind: "Task",
APIVersion: "v1beta1",
},
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
Matrix: []v1beta1.Param{{
Name: "foobar",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}, {
Name: "quxbaz",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"qux", "baz"}},
}},
},
TaskRuns: []*v1beta1.TaskRun{{
TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"},
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-0"},
}, {
TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"},
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-1"},
}, {
TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"},
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-2"},
}, {
TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"},
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-3"},
}},
}},
childRefs: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "TaskRun",
},
Name: "matrixed-task-run-0",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}, {
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "TaskRun",
},
Name: "matrixed-task-run-1",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}, {
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "TaskRun",
},
Name: "matrixed-task-run-2",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}, {
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "TaskRun",
},
Name: "matrixed-task-run-3",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 9c2da98

Please sign in to comment.