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

fix: avoid fan out matrix task failed due to result ref #8487

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion pkg/apis/pipeline/v1/matrix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ func (m *Matrix) countGeneratedCombinationsFromParams() int {
}
count := 1
for _, param := range m.Params {
count *= len(param.Value.ArrayVal)
if len(param.Value.ArrayVal) > 0 {
count *= len(param.Value.ArrayVal)
}
}
return count
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/apis/pipeline/v1/matrix_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) {
}{{
name: "combinations count is zero",
matrix: &v1.Matrix{
Params: v1.Params{{}}},
Params: v1.Params{}},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is different between having no param and having a param with an empty value.

want: 0,
}, {
name: "combinations count is one from one parameter",
Expand Down Expand Up @@ -915,11 +915,20 @@ func TestPipelineTask_CountCombinations(t *testing.T) {
}},
}},
want: 7,
}, {
name: "matrix params with string value containing variable reference",
matrix: &v1.Matrix{
Params: v1.Params{{
Name: "GOARCH", Value: v1.ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}},
}, {
Name: "version", Value: v1.ParamValue{StringVal: "$(tasks.platforms.results.str[*])"}},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem to be solved this time involves referencing an array parameter within a string value.

}},
want: 3,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if d := cmp.Diff(tt.want, tt.matrix.CountCombinations()); d != "" {
t.Errorf("Matrix.CountCombinations() errors diff %s", diff.PrintWantGot(d))
t.Errorf("%s Matrix.CountCombinations() errors diff %s", tt.name, diff.PrintWantGot(d))
}
})
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8942,8 +8942,14 @@ spec:
script: |
echo "$(params.platform)"
- name: b-task
taskRef:
name: mytask
taskSpec:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid returning early due to the PipelineRunReasonCouldntGetTask error.

params:
- name: platform
steps:
- name: echo
image: alpine
script: |
echo "$(params.platform)"
matrix:
params:
- name: platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3801,10 +3801,10 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) {
name: "task with matrix - whole array results",
pt: pts[2],
want: &ResolvedPipelineTask{
TaskRunNames: nil,
TaskRunNames: []string{"pipelinerun-pipelinetask-with-whole-array-results"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior will return a definition of TaskSpec, facilitating subsequent verification.

TaskRuns: nil,
PipelineTask: &pts[2],
ResolvedTask: nil,
ResolvedTask: rtr,
},
pst: pipelineRunState,
}} {
Expand Down
182 changes: 181 additions & 1 deletion test/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/test/diff"
"github.com/tektoncd/pipeline/test/parse"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
Expand Down Expand Up @@ -68,11 +69,14 @@ spec:
default: ""
- name: package
default: ""
results:
- name: str
type: string
steps:
- name: echo
image: mirror.gcr.io/alpine
script: |
echo "$(params.GOARCH) and $(params.version)"
echo -n "$(params.GOARCH) and $(params.version)" | tee $(results.str.path)
`, namespace))

task1withresults := parse.MustParseV1Task(t, fmt.Sprintf(`
Expand Down Expand Up @@ -107,6 +111,22 @@ spec:
echo -n "[\"go1.17\",\"go1.18.1\"]" | tee $(results.versions.path)
`, namespace))

task3printer := parse.MustParseV1Task(t, fmt.Sprintf(`
metadata:
name: printer
namespace: %s
spec:
params:
- name: platform
value: "default-platform"
steps:
- name: produce-a-list-of-versions
image: mirror.gcr.io/bash
script: |
#!/usr/bin/env bash
echo "platform: $(params.platform)"
`, namespace))

if _, err := c.V1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task.Name, err)
}
Expand All @@ -116,6 +136,9 @@ spec:
if _, err := c.V1TaskClient.Create(ctx, task2withresults, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task2withresults.Name, err)
}
if _, err := c.V1TaskClient.Create(ctx, task3printer, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task3printer.Name, err)
}

pipeline := parse.MustParseV1Pipeline(t, fmt.Sprintf(`
metadata:
Expand Down Expand Up @@ -157,6 +180,13 @@ spec:
params:
- name: GOARCH
value: I-do-not-exist
- name: printer-matrix
taskRef:
name: printer
matrix:
params:
- name: platform
value: $(tasks.matrix-include.results.str[*])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a usage that is supported this time.

`, helpers.ObjectNameForTest(t), namespace))

pipelineRun := parse.MustParseV1PipelineRun(t, fmt.Sprintf(`
Expand Down Expand Up @@ -208,6 +238,11 @@ spec:
}}},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
Results: []v1.TaskRunResult{{
Name: "str",
Type: v1.ResultsTypeString,
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.17"},
}},
},
},
}, {
Expand Down Expand Up @@ -240,6 +275,11 @@ spec:
}}},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
Results: []v1.TaskRunResult{{
Name: "str",
Type: v1.ResultsTypeString,
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.17"},
}},
},
},
}, {
Expand Down Expand Up @@ -269,6 +309,11 @@ spec:
}}},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
Results: []v1.TaskRunResult{{
Name: "str",
Type: v1.ResultsTypeString,
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.18.1"},
}},
},
},
}, {
Expand Down Expand Up @@ -298,6 +343,11 @@ spec:
}}},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
Results: []v1.TaskRunResult{{
Name: "str",
Type: v1.ResultsTypeString,
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.18.1"},
}},
},
},
}, {
Expand All @@ -319,6 +369,136 @@ spec:
Reason: "Succeeded",
Message: "All Steps have completed executing",
}}},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
Results: []v1.TaskRunResult{{
Name: "str",
Type: v1.ResultsTypeString,
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist and "},
}},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "pr-printer-matrix-0",
},
Spec: v1.TaskRunSpec{
Params: v1.Params{{
Name: "platform",
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.17"},
}},
ServiceAccountName: "default",
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
},
Status: v1.TaskRunStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: "Succeeded",
Message: "All Steps have completed executing",
}},
},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "pr-printer-matrix-1",
},
Spec: v1.TaskRunSpec{
Params: v1.Params{{
Name: "platform",
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.17"},
}},
ServiceAccountName: "default",
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
},
Status: v1.TaskRunStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: "Succeeded",
Message: "All Steps have completed executing",
}},
},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "pr-printer-matrix-2",
},
Spec: v1.TaskRunSpec{
Params: v1.Params{{
Name: "platform",
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/amd64 and go1.18.1"},
}},
ServiceAccountName: "default",
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
},
Status: v1.TaskRunStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: "Succeeded",
Message: "All Steps have completed executing",
}},
},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "pr-printer-matrix-3",
},
Spec: v1.TaskRunSpec{
Params: v1.Params{{
Name: "platform",
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "linux/ppc64le and go1.18.1"},
}},
ServiceAccountName: "default",
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
},
Status: v1.TaskRunStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: "Succeeded",
Message: "All Steps have completed executing",
}},
},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "pr-printer-matrix-4",
},
Spec: v1.TaskRunSpec{
Params: v1.Params{{
Name: "platform",
Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "I-do-not-exist and "},
}},
ServiceAccountName: "default",
TaskRef: &v1.TaskRef{Name: "printer", Kind: v1.NamespacedTaskKind},
},
Status: v1.TaskRunStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: "Succeeded",
Message: "All Steps have completed executing",
}},
},
TaskRunStatusFields: v1.TaskRunStatusFields{
Artifacts: &v1.Artifacts{},
},
Expand Down
Loading