Skip to content

Commit

Permalink
matrix taskRun names ends in instance id
Browse files Browse the repository at this point in the history
matrix creates multiple taskRuns using the specified combination of inputs.
The taskRun name in general is predictable unless it exceeds the max. number
of characters (63). When the combination of a pipelineTask name and the
pipelineRun name exceeds 63 characters, the taskRun names looses all their
instance indices.

Updating the taskRun name generation such that in case of a matrix task,
when the generated taskRun name exceeds k8s restriction of 63 characters,
the taskRun name is truncated and instance id of matrix is appended.

Signed-off-by: Priti Desai <[email protected]>
  • Loading branch information
pritidesai authored and tekton-robot committed Jan 25, 2024
1 parent 97ffba2 commit 378c61e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"sort"
"strings"

"github.com/google/cel-go/cel"
"github.com/tektoncd/pipeline/pkg/apis/config"
Expand Down Expand Up @@ -702,6 +703,15 @@ func getNewRunNames(ptName, prName string, numberOfRuns int) []string {
// For a matrix we append i to then end of the fanned out TaskRuns "matrixed-pr-taskrun-0"
for i := 0; i < numberOfRuns; i++ {
taskRunName := kmeta.ChildName(prName, fmt.Sprintf("-%s-%d", ptName, i))
// check if the taskRun name ends with a matrix instance count
if !strings.HasSuffix(taskRunName, fmt.Sprintf("-%d", i)) {
taskRunName = kmeta.ChildName(prName, fmt.Sprintf("-%s", ptName))
// kmeta.ChildName limits the size of a name to max of 63 characters based on k8s guidelines
// truncate the name such that "-<matrix-id>" can be appended to the taskRun name
longest := 63 - len(fmt.Sprintf("-%d", numberOfRuns))
taskRunName = taskRunName[0:longest]
taskRunName = fmt.Sprintf("%s-%d", taskRunName, i)
}
taskRunNames = append(taskRunNames, taskRunName)
}
return taskRunNames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3372,8 +3372,8 @@ func TestGetNamesOfTaskRuns(t *testing.T) {
name: "new pipelinetask with long names",
ptName: "longtask-0123456789-0123456789-0123456789-0123456789-0123456789",
wantTrNames: []string{
"mypipelinerun09c563f6b29a3a2c16b98e6dc95979c5-longtask-01234567",
"mypipelinerunab643c1924b632f050e5a07fe482fc25-longtask-01234567",
"mypipelineruna56c4ee0aab148ee219d40b21dfe935a-longtask-012345-0",
"mypipelineruna56c4ee0aab148ee219d40b21dfe935a-longtask-012345-1",
},
}, {
name: "new taskruns, pipelinerun with long name",
Expand All @@ -3388,8 +3388,8 @@ func TestGetNamesOfTaskRuns(t *testing.T) {
ptName: "task2-0123456789-0123456789-0123456789-0123456789-0123456789",
prName: "pipeline-run-0123456789-0123456789-0123456789-0123456789",
wantTrNames: []string{
"pipeline-run-0123456789-01234563c0313c59d28c85a2c2b3fd3b17a9514",
"pipeline-run-0123456789-01234569d54677e88e96776942290e00b578ca5",
"pipeline-run-0123456789-012345607ad8c7aac5873cdfabe472a68996b-0",
"pipeline-run-0123456789-012345607ad8c7aac5873cdfabe472a68996b-1",
},
}} {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -3435,8 +3435,8 @@ func TestGetNamesOfRuns(t *testing.T) {
name: "new pipelinetask with long names",
ptName: "longtask-0123456789-0123456789-0123456789-0123456789-0123456789",
wantRunNames: []string{
"mypipelinerun09c563f6b29a3a2c16b98e6dc95979c5-longtask-01234567",
"mypipelinerunab643c1924b632f050e5a07fe482fc25-longtask-01234567",
"mypipelineruna56c4ee0aab148ee219d40b21dfe935a-longtask-012345-0",
"mypipelineruna56c4ee0aab148ee219d40b21dfe935a-longtask-012345-1",
},
}, {
name: "new runs, pipelinerun with long name",
Expand All @@ -3451,8 +3451,8 @@ func TestGetNamesOfRuns(t *testing.T) {
ptName: "task2-0123456789-0123456789-0123456789-0123456789-0123456789",
prName: "pipeline-run-0123456789-0123456789-0123456789-0123456789",
wantRunNames: []string{
"pipeline-run-0123456789-01234563c0313c59d28c85a2c2b3fd3b17a9514",
"pipeline-run-0123456789-01234569d54677e88e96776942290e00b578ca5",
"pipeline-run-0123456789-012345607ad8c7aac5873cdfabe472a68996b-0",
"pipeline-run-0123456789-012345607ad8c7aac5873cdfabe472a68996b-1",
},
}} {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 378c61e

Please sign in to comment.