Skip to content

Commit

Permalink
Test reconciled PipelineRun from Pipeline with Matrix
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`.

In tektoncd#4990, we implemented
fanning out of `TaskRuns`, but they were not embedded in `PipelineRun`
status. Now that the minimal status are embedded through `ChildReferences`,
this change validates that the reconciled `PipelineRun` has the expected
`ChildReferences`.

[tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
  • Loading branch information
jerop committed Jun 23, 2022
1 parent 071b48a commit ff9ba5a
Showing 1 changed file with 174 additions and 5 deletions.
179 changes: 174 additions & 5 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ var (

ignoreResourceVersion = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion")
ignoreTypeMeta = cmpopts.IgnoreFields(metav1.TypeMeta{}, "Kind", "APIVersion")
ignoreLastTransitionTime = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time")
ignoreStartTime = cmpopts.IgnoreFields(v1beta1.PipelineRunStatusFields{}, "StartTime")
trueb = true
simpleHelloWorldTask = &v1beta1.Task{ObjectMeta: baseObjectMeta("hello-world", "foo")}
simpleSomeTask = &v1beta1.Task{ObjectMeta: baseObjectMeta("some-task", "foo")}
Expand Down Expand Up @@ -7613,15 +7615,15 @@ spec:
timeout: 1h0m0s
`),
}

cms := []*corev1.ConfigMap{withEmbeddedStatus(withEnabledAlphaAPIFields(newFeatureFlagsConfigMap()), config.MinimalEmbeddedStatus)}
cms = append(cms, withMaxMatrixCombinationsCount(newDefaultsConfigMap(), 10))

tests := []struct {
name string
memberOf string
p *v1beta1.Pipeline
tr *v1beta1.TaskRun
name string
memberOf string
p *v1beta1.Pipeline
tr *v1beta1.TaskRun
expectedPipelineRun *v1beta1.PipelineRun
}{{
name: "p-dag",
memberOf: "tasks",
Expand All @@ -7646,6 +7648,79 @@ spec:
- safari
- firefox
`, "p-dag")),
expectedPipelineRun: parse.MustParsePipelineRun(t, `
metadata:
name: pr
namespace: foo
annotations: {}
labels:
tekton.dev/pipeline: p-dag
spec:
serviceAccountName: test-sa
pipelineRef:
name: p-dag
status:
pipelineSpec:
tasks:
- name: platforms-and-browsers
taskRef:
name: mytask
matrix:
- name: platform
value:
- linux
- mac
- windows
- name: browser
value:
- chrome
- safari
- firefox
conditions:
- type: Succeeded
status: "Unknown"
reason: "Running"
message: "Tasks Completed: 0 (Failed: 0, Cancelled 0), Incomplete: 1, Skipped: 0"
childReferences:
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-0
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-1
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-2
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-3
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-4
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-5
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-6
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-7
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-8
pipelineTaskName: platforms-and-browsers
taskRuns: {}
runs: {}
`),
}, {
name: "p-finally",
memberOf: "finally",
Expand Down Expand Up @@ -7700,6 +7775,92 @@ status:
status: "True"
reason: Succeeded
message: All Tasks have completed executing
`),
expectedPipelineRun: parse.MustParsePipelineRun(t, `
metadata:
name: pr
namespace: foo
annotations: {}
labels:
tekton.dev/pipeline: p-finally
spec:
serviceAccountName: test-sa
pipelineRef:
name: p-finally
status:
pipelineSpec:
tasks:
- name: unmatrixed-pt
params:
- name: platform
value: linux
- name: browser
value: chrome
taskRef:
name: mytask
finally:
- name: platforms-and-browsers
taskRef:
name: mytask
matrix:
- name: platform
value:
- linux
- mac
- windows
- name: browser
value:
- chrome
- safari
- firefox
conditions:
- type: Succeeded
status: "Unknown"
reason: "Running"
message: "Tasks Completed: 1 (Failed: 0, Cancelled 0), Incomplete: 1, Skipped: 0"
childReferences:
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-unmatrixed-pt
pipelineTaskName: unmatrixed-pt
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-0
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-1
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-2
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-3
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-4
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-5
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-6
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-7
pipelineTaskName: platforms-and-browsers
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
name: pr-platforms-and-browsers-8
pipelineTaskName: platforms-and-browsers
taskRuns: {}
runs: {}
`),
}}
for _, tt := range tests {
Expand Down Expand Up @@ -7746,6 +7907,14 @@ spec:
t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRuns[i].Name, diff.PrintWantGot(d))
}
}

pipelineRun, err := clients.Pipeline.TektonV1beta1().PipelineRuns("foo").Get(prt.TestAssets.Ctx, "pr", metav1.GetOptions{})
if err != nil {
t.Fatalf("Got an error getting reconciled run out of fake client: %s", err)
}
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime); d != "" {
t.Errorf("expected PipelineRun was not created. Diff %s", diff.PrintWantGot(d))
}
})
}
}
Expand Down

0 comments on commit ff9ba5a

Please sign in to comment.