Skip to content

Commit

Permalink
TEP-0090: Support both matrix and params in a PipelineTask
Browse files Browse the repository at this point in the history
[TEP-0090: Matrix][tep-0090] proposed executing a `PipelineTask` in
parallel `TaskRuns` and `Runs` with substitutions from combinations
of `Parameters` in a `Matrix`.

This change implements the fan out of `PipelineTasks` that have both
`matrix` and `params` specified. The `matrix` is used to fan out the
`PipelineTask` and the `params` are the same in all the `TaskRuns`.

[tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
  • Loading branch information
jerop authored and tekton-robot committed Jun 29, 2022
1 parent 0cee557 commit df074f2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
33 changes: 33 additions & 0 deletions docs/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ weight: 11
- [Configuring a Matrix](#configuring-a-matrix)
- [Concurrency Control](#concurrency-control)
- [Parameters](#parameters)
- [Specifying both `params` and `matrix` in a `PipelineTask`](#specifying-both-params-and-matrix-in-a-pipelinetask)
- [Context Variables](#context-variables)
- [Results](#results)
- [Specifying Results in a Matrix](#specifying-results-in-a-matrix)
Expand Down Expand Up @@ -113,6 +114,38 @@ A `Parameter` can be passed to either the `matrix` or `params` field, not both.
For further details on specifying `Parameters` in the `Pipeline` and passing them to
`PipelineTasks`, see [documentation](pipelines.md#specifying-parameters).

#### Specifying both `params` and `matrix` in a `PipelineTask`

In the example below, the *test* `Task` takes *browser* and *platform* `Parameters` of type
`"string"`. A `Pipeline` used to run the `Task` on three browsers (using `matrix`) and one
platform (using `params`) would be specified as such and execute three `TaskRuns`:

```yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: platform-browser-tests
spec:
tasks:
- name: fetch-repository
taskRef:
name: git-clone
...
- name: test
matrix:
- name: browser
value:
- chrome
- safari
- firefox
params:
- name: platform
value: linux
taskRef:
name: browser-test
...
```

### Context Variables

Similarly to the `Parameters` in the `Params` field, the `Parameters` in the `Matrix` field will accept
Expand Down
12 changes: 12 additions & 0 deletions examples/v1beta1/pipelineruns/alpha/pipelinerun-with-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ spec:
- firefox
taskRef:
name: platform-browsers
- name: matrix-and-params
matrix:
- name: platform
value:
- linux
- mac
- windows
params:
- name: browser
value: chrome
taskRef:
name: platform-browsers
4 changes: 1 addition & 3 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,7 @@ func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, para

rpt.PipelineTask = resources.ApplyPipelineTaskContexts(rpt.PipelineTask)
taskRunSpec := pr.GetTaskRunSpec(rpt.PipelineTask.Name)
if len(params) == 0 {
params = rpt.PipelineTask.Params
}
params = append(params, rpt.PipelineTask.Params...)
tr = &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: taskRunName,
Expand Down
39 changes: 38 additions & 1 deletion pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7513,11 +7513,12 @@ spec:
params:
- name: platform
- name: browser
- name: version
steps:
- name: echo
image: alpine
script: |
echo "$(params.platform) and $(params.browser)"
echo "$(params.platform) and $(params.browser) and $(params.version)"
`)

expectedTaskRuns := []*v1beta1.TaskRun{
Expand All @@ -7531,6 +7532,8 @@ spec:
value: linux
- name: browser
value: chrome
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7547,6 +7550,8 @@ spec:
value: mac
- name: browser
value: chrome
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7563,6 +7568,8 @@ spec:
value: windows
- name: browser
value: chrome
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7579,6 +7586,8 @@ spec:
value: linux
- name: browser
value: safari
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7595,6 +7604,8 @@ spec:
value: mac
- name: browser
value: safari
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7611,6 +7622,8 @@ spec:
value: windows
- name: browser
value: safari
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7627,6 +7640,8 @@ spec:
value: linux
- name: browser
value: firefox
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7643,6 +7658,8 @@ spec:
value: mac
- name: browser
value: firefox
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7659,6 +7676,8 @@ spec:
value: windows
- name: browser
value: firefox
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand Down Expand Up @@ -7698,6 +7717,9 @@ spec:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
`, "p-dag")),
expectedPipelineRun: parse.MustParsePipelineRun(t, `
metadata:
Expand Down Expand Up @@ -7727,6 +7749,9 @@ status:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
conditions:
- type: Succeeded
status: "Unknown"
Expand Down Expand Up @@ -7787,6 +7812,8 @@ spec:
value: linux
- name: browser
value: chrome
- name: version
value: v0.22.0
taskRef:
name: mytask
finally:
Expand All @@ -7804,6 +7831,9 @@ spec:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
`, "p-finally")),
tr: mustParseTaskRunWithObjectMeta(t,
taskRunObjectMeta("pr-unmatrixed-pt", "foo",
Expand All @@ -7815,6 +7845,8 @@ spec:
value: linux
- name: browser
value: chrome
- name: version
value: v0.22.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand Down Expand Up @@ -7847,6 +7879,8 @@ status:
value: linux
- name: browser
value: chrome
- name: version
value: v0.22.0
taskRef:
name: mytask
finally:
Expand All @@ -7864,6 +7898,9 @@ status:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
conditions:
- type: Succeeded
status: "Unknown"
Expand Down

0 comments on commit df074f2

Please sign in to comment.