Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matrix taskRun name updated to end with the instance count #7563

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -701,6 +702,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
Loading