Skip to content

Commit

Permalink
Get Names of TaskRuns from ChildReferences only
Browse files Browse the repository at this point in the history
In tektoncd/community#736, we decided that
`Matrix` will use `ChildReferences` only. Therefore, it is unnecessary
to check the `TaskRuns` field of `PipelineRun` status when getting the
names of `TaskRuns` for matrixed `PipelineTasks`.

Related PR: tektoncd#5019
  • Loading branch information
jerop committed Jun 24, 2022
1 parent b12907f commit 7ed3c92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
20 changes: 3 additions & 17 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func ResolvePipelineTask(
}
rpt.Run = run
case rpt.IsMatrixed():
rpt.TaskRunNames = GetNamesOfTaskRuns(pipelineRun.Status.TaskRuns, pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name, pipelineTask.GetMatrixCombinationsCount())
rpt.TaskRunNames = GetNamesOfTaskRuns(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name, pipelineTask.GetMatrixCombinationsCount())
for _, taskRunName := range rpt.TaskRunNames {
if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, taskRunName, getTask, getTaskRun, pipelineTask, providedResources); err != nil {
return nil, err
Expand Down Expand Up @@ -648,12 +648,8 @@ func GetTaskRunName(taskRunsStatus map[string]*v1beta1.PipelineRunTaskRunStatus,
}

// GetNamesOfTaskRuns should return unique names for `TaskRuns` if one has not already been defined, and the existing one otherwise.
func GetNamesOfTaskRuns(taskRunsStatus map[string]*v1beta1.PipelineRunTaskRunStatus, childRefs []v1beta1.ChildStatusReference, ptName, prName string, combinationCount int) []string {
var taskRunNames []string
if taskRunNames = getTaskRunNamesFromChildRefs(childRefs, ptName); taskRunNames != nil {
return taskRunNames
}
if taskRunNames = getTaskRunNamesFromTaskRunsStatus(taskRunsStatus, ptName); taskRunNames != nil {
func GetNamesOfTaskRuns(childRefs []v1beta1.ChildStatusReference, ptName, prName string, combinationCount int) []string {
if taskRunNames := getTaskRunNamesFromChildRefs(childRefs, ptName); taskRunNames != nil {
return taskRunNames
}
return getNewTaskRunNames(ptName, prName, combinationCount)
Expand All @@ -669,16 +665,6 @@ func getTaskRunNamesFromChildRefs(childRefs []v1beta1.ChildStatusReference, ptNa
return taskRunNames
}

func getTaskRunNamesFromTaskRunsStatus(taskRunsStatus map[string]*v1beta1.PipelineRunTaskRunStatus, ptName string) []string {
var taskRunNames []string
for k, v := range taskRunsStatus {
if v.PipelineTaskName == ptName {
taskRunNames = append(taskRunNames, k)
}
}
return taskRunNames
}

func getNewTaskRunNames(ptName, prName string, combinationCount int) []string {
var taskRunNames []string
for i := 0; i < combinationCount; i++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2831,15 +2831,6 @@ func TestGetTaskRunName(t *testing.T) {

func TestGetNamesOfTaskRuns(t *testing.T) {
prName := "mypipelinerun"
taskRunsStatus := map[string]*v1beta1.PipelineRunTaskRunStatus{
"mypipelinerun-mytask-0": {
PipelineTaskName: "mytask",
},
"mypipelinerun-mytask-1": {
PipelineTaskName: "mytask",
},
}

childRefs := []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
Name: "mypipelinerun-mytask-0",
Expand Down Expand Up @@ -2892,12 +2883,7 @@ func TestGetNamesOfTaskRuns(t *testing.T) {
if tc.prName != "" {
testPrName = tc.prName
}
namesOfTaskRunsFromTaskRunsStatus := GetNamesOfTaskRuns(taskRunsStatus, nil, tc.ptName, testPrName, 2)
sort.Strings(namesOfTaskRunsFromTaskRunsStatus)
if d := cmp.Diff(tc.wantTrNames, namesOfTaskRunsFromTaskRunsStatus); d != "" {
t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d))
}
namesOfTaskRunsFromChildRefs := GetNamesOfTaskRuns(nil, childRefs, tc.ptName, testPrName, 2)
namesOfTaskRunsFromChildRefs := GetNamesOfTaskRuns(childRefs, tc.ptName, testPrName, 2)
sort.Strings(namesOfTaskRunsFromChildRefs)
if d := cmp.Diff(tc.wantTrNames, namesOfTaskRunsFromChildRefs); d != "" {
t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d))
Expand Down

0 comments on commit 7ed3c92

Please sign in to comment.