-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -782,7 +782,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { | |
}{{ | ||
name: "combinations count is zero", | ||
matrix: &v1.Matrix{ | ||
Params: v1.Params{{}}}, | ||
Params: v1.Params{}}, | ||
want: 0, | ||
}, { | ||
name: "combinations count is one from one parameter", | ||
|
@@ -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[*])"}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
} | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8942,8 +8942,14 @@ spec: | |
script: | | ||
echo "$(params.platform)" | ||
- name: b-task | ||
taskRef: | ||
name: mytask | ||
taskSpec: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid returning early due to the |
||
params: | ||
- name: platform | ||
steps: | ||
- name: echo | ||
image: alpine | ||
script: | | ||
echo "$(params.platform)" | ||
matrix: | ||
params: | ||
- name: platform | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}} { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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(` | ||
|
@@ -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) | ||
} | ||
|
@@ -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: | ||
|
@@ -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[*]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(` | ||
|
@@ -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"}, | ||
}}, | ||
}, | ||
}, | ||
}, { | ||
|
@@ -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"}, | ||
}}, | ||
}, | ||
}, | ||
}, { | ||
|
@@ -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"}, | ||
}}, | ||
}, | ||
}, | ||
}, { | ||
|
@@ -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"}, | ||
}}, | ||
}, | ||
}, | ||
}, { | ||
|
@@ -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{}, | ||
}, | ||
|
There was a problem hiding this comment.
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.