Skip to content

Commit

Permalink
TEP-0090: Get ChildReferences for Runs
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 `Runs`
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 28, 2022
1 parent 88ea861 commit 29f68de
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 5 deletions.
12 changes: 9 additions & 3 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
for _, rpt := range state {
switch {
case rpt.Run != nil:
childRefs = append(childRefs, rpt.getChildRefForRun())
childRefs = append(childRefs, rpt.getChildRefForRun(rpt.Run.Name))
case rpt.TaskRun != nil:
childRefs = append(childRefs, rpt.getChildRefForTaskRun(rpt.TaskRun))
case len(rpt.TaskRuns) != 0:
Expand All @@ -254,18 +254,24 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
childRefs = append(childRefs, rpt.getChildRefForTaskRun(taskRun))
}
}
case len(rpt.Runs) != 0:
for _, run := range rpt.Runs {
if run != nil {
childRefs = append(childRefs, rpt.getChildRefForRun(run.Name))
}
}
}
}
return childRefs
}

func (t *ResolvedPipelineTask) getChildRefForRun() v1beta1.ChildStatusReference {
func (t *ResolvedPipelineTask) getChildRefForRun(runName string) v1beta1.ChildStatusReference {
return v1beta1.ChildStatusReference{
TypeMeta: runtime.TypeMeta{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: pipeline.RunControllerName,
},
Name: t.RunName,
Name: runName,
PipelineTaskName: t.PipelineTask.Name,
WhenExpressions: t.PipelineTask.WhenExpressions,
}
Expand Down
111 changes: 109 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2744,15 +2744,122 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {
}},
}},
},
{
name: "unresolved-matrixed-custom-task",
state: PipelineRunState{{
PipelineTask: &v1beta1.PipelineTask{
Name: "matrixed-task",
TaskRef: &v1beta1.TaskRef{
Kind: "Example",
APIVersion: "example.dev/v0",
},
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"}},
}},
},
CustomTask: true,
}},
childRefs: nil,
},
{
name: "matrixed-custom-task",
state: PipelineRunState{{
PipelineTask: &v1beta1.PipelineTask{
Name: "matrixed-task",
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Example",
},
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"}},
}},
},
CustomTask: true,
Runs: []*v1alpha1.Run{{
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-0"},
}, {
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-1"},
}, {
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-2"},
}, {
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-3"},
}},
}},
childRefs: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1alpha1",
Kind: "Run",
},
Name: "matrixed-run-0",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}, {
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1alpha1",
Kind: "Run",
},
Name: "matrixed-run-1",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}, {
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1alpha1",
Kind: "Run",
},
Name: "matrixed-run-2",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}, {
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1alpha1",
Kind: "Run",
},
Name: "matrixed-run-3",
PipelineTaskName: "matrixed-task",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
childRefs := tc.state.GetChildReferences()
if d := cmp.Diff(tc.childRefs, childRefs); d != "" {
t.Errorf("Didn't get expected child references for %s: %s", tc.name, diff.PrintWantGot(d))
}

})
}
}

0 comments on commit 29f68de

Please sign in to comment.