Skip to content

Commit 5375e76

Browse files
jeroptekton-robot
authored andcommitted
TEP-0090: Matrix - Get Names of Runs
[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 add a function to get names of `TaskRuns` from Child References. If none are available, it generates new names for `Runs` based on the `PipelineRun` and `PipelineTask` names. [tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
1 parent 7e119c5 commit 5375e76

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,25 @@ func getRunName(runsStatus map[string]*v1beta1.PipelineRunRunStatus, childRefs [
706706
return kmeta.ChildName(prName, fmt.Sprintf("-%s", ptName))
707707
}
708708

709+
// getNamesOfRuns should return a unique names for `Runs` if they have not already been defined,
710+
// and the existing ones otherwise.
711+
func getNamesOfRuns(childRefs []v1beta1.ChildStatusReference, ptName, prName string, combinationCount int) []string {
712+
if runNames := getRunNamesFromChildRefs(childRefs, ptName); runNames != nil {
713+
return runNames
714+
}
715+
return getNewTaskRunNames(ptName, prName, combinationCount)
716+
}
717+
718+
func getRunNamesFromChildRefs(childRefs []v1beta1.ChildStatusReference, ptName string) []string {
719+
var runNames []string
720+
for _, cr := range childRefs {
721+
if cr.Kind == pipeline.RunControllerName && cr.PipelineTaskName == ptName {
722+
runNames = append(runNames, cr.Name)
723+
}
724+
}
725+
return runNames
726+
}
727+
709728
// resolvePipelineTaskResources matches PipelineResources referenced by pt inputs and outputs with the
710729
// providedResources and returns an instance of ResolvedTaskResources.
711730
func resolvePipelineTaskResources(pt v1beta1.PipelineTask, ts *v1beta1.TaskSpec, taskName string, kind v1beta1.TaskKind, providedResources map[string]*resourcev1alpha1.PipelineResource) (*resources.ResolvedTaskResources, error) {

pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,69 @@ func TestGetNamesOfTaskRuns(t *testing.T) {
29062906
}
29072907
}
29082908

2909+
func TestGetNamesOfRuns(t *testing.T) {
2910+
prName := "mypipelinerun"
2911+
childRefs := []v1beta1.ChildStatusReference{{
2912+
TypeMeta: runtime.TypeMeta{Kind: "Run"},
2913+
Name: "mypipelinerun-mytask-0",
2914+
PipelineTaskName: "mytask",
2915+
}, {
2916+
TypeMeta: runtime.TypeMeta{Kind: "Run"},
2917+
Name: "mypipelinerun-mytask-1",
2918+
PipelineTaskName: "mytask",
2919+
}}
2920+
2921+
for _, tc := range []struct {
2922+
name string
2923+
ptName string
2924+
prName string
2925+
wantRunNames []string
2926+
}{{
2927+
name: "existing runs",
2928+
ptName: "mytask",
2929+
wantRunNames: []string{"mypipelinerun-mytask-0", "mypipelinerun-mytask-1"},
2930+
}, {
2931+
name: "new runs",
2932+
ptName: "mynewtask",
2933+
wantRunNames: []string{"mypipelinerun-mynewtask-0", "mypipelinerun-mynewtask-1"},
2934+
}, {
2935+
name: "new pipelinetask with long names",
2936+
ptName: "longtask-0123456789-0123456789-0123456789-0123456789-0123456789",
2937+
wantRunNames: []string{
2938+
"mypipelinerun09c563f6b29a3a2c16b98e6dc95979c5-longtask-01234567",
2939+
"mypipelinerunab643c1924b632f050e5a07fe482fc25-longtask-01234567",
2940+
},
2941+
}, {
2942+
name: "new runs, pipelinerun with long name",
2943+
ptName: "task3",
2944+
prName: "pipeline-run-0123456789-0123456789-0123456789-0123456789",
2945+
wantRunNames: []string{
2946+
"pipeline-run-01234567891276ed292277c9bebded38d907a517fe-task3-0",
2947+
"pipeline-run-01234567891276ed292277c9bebded38d907a517fe-task3-1",
2948+
},
2949+
}, {
2950+
name: "new runs, pipelinetask and pipelinerun with long name",
2951+
ptName: "task2-0123456789-0123456789-0123456789-0123456789-0123456789",
2952+
prName: "pipeline-run-0123456789-0123456789-0123456789-0123456789",
2953+
wantRunNames: []string{
2954+
"pipeline-run-0123456789-01234563c0313c59d28c85a2c2b3fd3b17a9514",
2955+
"pipeline-run-0123456789-01234569d54677e88e96776942290e00b578ca5",
2956+
},
2957+
}} {
2958+
t.Run(tc.name, func(t *testing.T) {
2959+
testPrName := prName
2960+
if tc.prName != "" {
2961+
testPrName = tc.prName
2962+
}
2963+
namesOfRunsFromChildRefs := getNamesOfRuns(childRefs, tc.ptName, testPrName, 2)
2964+
sort.Strings(namesOfRunsFromChildRefs)
2965+
if d := cmp.Diff(tc.wantRunNames, namesOfRunsFromChildRefs); d != "" {
2966+
t.Errorf("getRunName: %s", diff.PrintWantGot(d))
2967+
}
2968+
})
2969+
}
2970+
}
2971+
29092972
func TestGetRunName(t *testing.T) {
29102973
prName := "pipeline-run"
29112974
runsStatus := map[string]*v1beta1.PipelineRunRunStatus{

0 commit comments

Comments
 (0)