Skip to content

Commit 28ac12f

Browse files
committed
TEP-0090: Get ChildReferences for Runs
[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
1 parent 4c021dc commit 28ac12f

File tree

2 files changed

+118
-5
lines changed

2 files changed

+118
-5
lines changed

pkg/reconciler/pipelinerun/resources/pipelinerunstate.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
245245
for _, rpt := range state {
246246
switch {
247247
case rpt.Run != nil:
248-
childRefs = append(childRefs, rpt.getChildRefForRun())
248+
childRefs = append(childRefs, rpt.getChildRefForRun(rpt.Run.Name))
249249
case rpt.TaskRun != nil:
250250
childRefs = append(childRefs, rpt.getChildRefForTaskRun(rpt.TaskRun))
251251
case len(rpt.TaskRuns) != 0:
@@ -254,18 +254,24 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
254254
childRefs = append(childRefs, rpt.getChildRefForTaskRun(taskRun))
255255
}
256256
}
257+
case len(rpt.Runs) != 0:
258+
for _, run := range rpt.Runs {
259+
if run != nil {
260+
childRefs = append(childRefs, rpt.getChildRefForRun(run.Name))
261+
}
262+
}
257263
}
258264
}
259265
return childRefs
260266
}
261267

262-
func (t *ResolvedPipelineTask) getChildRefForRun() v1beta1.ChildStatusReference {
268+
func (t *ResolvedPipelineTask) getChildRefForRun(runName string) v1beta1.ChildStatusReference {
263269
return v1beta1.ChildStatusReference{
264270
TypeMeta: runtime.TypeMeta{
265271
APIVersion: v1alpha1.SchemeGroupVersion.String(),
266272
Kind: pipeline.RunControllerName,
267273
},
268-
Name: t.RunName,
274+
Name: runName,
269275
PipelineTaskName: t.PipelineTask.Name,
270276
WhenExpressions: t.PipelineTask.WhenExpressions,
271277
}

pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,15 +2744,122 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {
27442744
}},
27452745
}},
27462746
},
2747+
{
2748+
name: "unresolved-matrixed-custom-task",
2749+
state: PipelineRunState{{
2750+
PipelineTask: &v1beta1.PipelineTask{
2751+
Name: "matrixed-task",
2752+
TaskRef: &v1beta1.TaskRef{
2753+
Kind: "Example",
2754+
APIVersion: "example.dev/v0",
2755+
},
2756+
WhenExpressions: []v1beta1.WhenExpression{{
2757+
Input: "foo",
2758+
Operator: selection.In,
2759+
Values: []string{"foo", "bar"},
2760+
}},
2761+
Matrix: []v1beta1.Param{{
2762+
Name: "foobar",
2763+
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
2764+
}, {
2765+
Name: "quxbaz",
2766+
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"qux", "baz"}},
2767+
}},
2768+
},
2769+
CustomTask: true,
2770+
}},
2771+
childRefs: nil,
2772+
},
2773+
{
2774+
name: "matrixed-custom-task",
2775+
state: PipelineRunState{{
2776+
PipelineTask: &v1beta1.PipelineTask{
2777+
Name: "matrixed-task",
2778+
TaskRef: &v1beta1.TaskRef{
2779+
APIVersion: "example.dev/v0",
2780+
Kind: "Example",
2781+
},
2782+
WhenExpressions: []v1beta1.WhenExpression{{
2783+
Input: "foo",
2784+
Operator: selection.In,
2785+
Values: []string{"foo", "bar"},
2786+
}},
2787+
Matrix: []v1beta1.Param{{
2788+
Name: "foobar",
2789+
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
2790+
}, {
2791+
Name: "quxbaz",
2792+
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"qux", "baz"}},
2793+
}},
2794+
},
2795+
CustomTask: true,
2796+
Runs: []*v1alpha1.Run{{
2797+
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-0"},
2798+
}, {
2799+
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-1"},
2800+
}, {
2801+
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-2"},
2802+
}, {
2803+
ObjectMeta: metav1.ObjectMeta{Name: "matrixed-run-3"},
2804+
}},
2805+
}},
2806+
childRefs: []v1beta1.ChildStatusReference{{
2807+
TypeMeta: runtime.TypeMeta{
2808+
APIVersion: "tekton.dev/v1alpha1",
2809+
Kind: "Run",
2810+
},
2811+
Name: "matrixed-task-run-0",
2812+
PipelineTaskName: "matrixed-task",
2813+
WhenExpressions: []v1beta1.WhenExpression{{
2814+
Input: "foo",
2815+
Operator: selection.In,
2816+
Values: []string{"foo", "bar"},
2817+
}},
2818+
}, {
2819+
TypeMeta: runtime.TypeMeta{
2820+
APIVersion: "tekton.dev/v1alpha1",
2821+
Kind: "Run",
2822+
},
2823+
Name: "matrixed-task-run-1",
2824+
PipelineTaskName: "matrixed-task",
2825+
WhenExpressions: []v1beta1.WhenExpression{{
2826+
Input: "foo",
2827+
Operator: selection.In,
2828+
Values: []string{"foo", "bar"},
2829+
}},
2830+
}, {
2831+
TypeMeta: runtime.TypeMeta{
2832+
APIVersion: "tekton.dev/v1alpha1",
2833+
Kind: "Run",
2834+
},
2835+
Name: "matrixed-task-run-2",
2836+
PipelineTaskName: "matrixed-task",
2837+
WhenExpressions: []v1beta1.WhenExpression{{
2838+
Input: "foo",
2839+
Operator: selection.In,
2840+
Values: []string{"foo", "bar"},
2841+
}},
2842+
}, {
2843+
TypeMeta: runtime.TypeMeta{
2844+
APIVersion: "tekton.dev/v1alpha1",
2845+
Kind: "Run",
2846+
},
2847+
Name: "matrixed-task-run-3",
2848+
PipelineTaskName: "matrixed-task",
2849+
WhenExpressions: []v1beta1.WhenExpression{{
2850+
Input: "foo",
2851+
Operator: selection.In,
2852+
Values: []string{"foo", "bar"},
2853+
}},
2854+
}},
2855+
},
27472856
}
2748-
27492857
for _, tc := range testCases {
27502858
t.Run(tc.name, func(t *testing.T) {
27512859
childRefs := tc.state.GetChildReferences()
27522860
if d := cmp.Diff(tc.childRefs, childRefs); d != "" {
27532861
t.Errorf("Didn't get expected child references for %s: %s", tc.name, diff.PrintWantGot(d))
27542862
}
2755-
27562863
})
27572864
}
27582865
}

0 commit comments

Comments
 (0)