Skip to content

Commit

Permalink
TEP-0090: Indicate Resolved PipelineRunTask is Matrixed
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 this change, we add support for resolving a `PipelineTask` to
indicate that it is matrixed. This is useful for processing the
`ResolvedPipelineRunTask`.

[tep-0090]: https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md
  • Loading branch information
jerop committed Jun 8, 2022
1 parent 9d60d0a commit 8dae5f3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type ResolvedPipelineRunTask struct {
PipelineTask *v1beta1.PipelineTask
ResolvedTaskResources *resources.ResolvedTaskResources
// ConditionChecks ~~TaskRuns but for evaling conditions

}

// IsDone returns true only if the task is skipped, succeeded or failed
Expand All @@ -93,6 +94,11 @@ func (t ResolvedPipelineRunTask) IsCustomTask() bool {
return t.CustomTask
}

// IsMatrixed return true if the PipelineTask has a Matrix.
func (t ResolvedPipelineRunTask) IsMatrixed() bool {
return len(t.PipelineTask.Matrix) > 0
}

// IsSuccessful returns true only if the run has completed successfully
func (t ResolvedPipelineRunTask) IsSuccessful() bool {
if t.IsCustomTask() {
Expand Down
79 changes: 79 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2705,3 +2705,82 @@ func TestGetRunName(t *testing.T) {
})
}
}

func TestIsMatrixed(t *testing.T) {
pr := v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinerun",
},
}
getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, error) { return task, nil }
getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return &trs[0], nil }
getRun := func(name string) (*v1alpha1.Run, error) { return &runs[0], nil }

for _, tc := range []struct {
name string
pt v1beta1.PipelineTask
want bool
}{{
name: "custom task with matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Sample",
},
Matrix: []v1beta1.Param{{
Name: "platform",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}},
}},
},
want: true,
}, {
name: "custom task without matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Sample",
},
},
want: false,
}, {
name: "task with matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
Matrix: []v1beta1.Param{{
Name: "platform",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}},
}},
},
want: true,
}, {
name: "task without matrix",
pt: v1beta1.PipelineTask{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
},
want: false,
}} {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
cfg := config.NewStore(logtesting.TestLogger(t))
cfg.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName()},
Data: map[string]string{
"enable-api-fields": "alpha",
},
})
ctx = cfg.ToContext(ctx)
rprt, err := ResolvePipelineRunTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt, nil)
if err != nil {
t.Fatalf("Did not expect error when resolving PipelineRun: %v", err)
}
got := rprt.IsMatrixed()
if d := cmp.Diff(tc.want, got); d != "" {
t.Errorf("IsMatrixed: %s", diff.PrintWantGot(d))
}
})
}
}

0 comments on commit 8dae5f3

Please sign in to comment.