Skip to content

Commit

Permalink
Matrix Promotion to Beta
Browse files Browse the repository at this point in the history
Matrix was introduced in Tekton Pipelines 0.38. We have introduced a lot of
testing around matrix feature including unit/e2e/integration tests.

Matrix unblocks variety of use cases for systems migrating from travis/jenkins.

This is a very crucial feature for many end-users while allowing to maintain
clean, concise, and flexible catalog of pipelines.

Part of tektoncd#5265 and tektoncd#6110

Signed-off-by: Priti Desai <[email protected]>
  • Loading branch information
pritidesai committed Sep 29, 2023
1 parent f5578a8 commit 4919dba
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 172 deletions.
16 changes: 8 additions & 8 deletions docs/additional-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ Features currently in "alpha" are:
| [Windows Scripts](./tasks.md#windows-scripts) | [TEP-0057](https://github.com/tektoncd/community/blob/main/teps/0057-windows-support.md) | [v0.28.0](https://github.com/tektoncd/pipeline/releases/tag/v0.28.0) | |
| [Debug](./debug.md) | [TEP-0042](https://github.com/tektoncd/community/blob/main/teps/0042-taskrun-breakpoint-on-failure.md) | [v0.26.0](https://github.com/tektoncd/pipeline/releases/tag/v0.26.0) | |
| [Step and Sidecar Overrides](./taskruns.md#overriding-task-steps-and-sidecars) | [TEP-0094](https://github.com/tektoncd/community/blob/main/teps/0094-specifying-resource-requirements-at-runtime.md) | [v0.34.0](https://github.com/tektoncd/pipeline/releases/tag/v0.34.0) | |
| [Matrix](./matrix.md) | [TEP-0090](https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md) | [v0.38.0](https://github.com/tektoncd/pipeline/releases/tag/v0.38.0) | |
| [Task-level Resource Requirements](compute-resources.md#task-level-compute-resources-configuration) | [TEP-0104](https://github.com/tektoncd/community/blob/main/teps/0104-tasklevel-resource-requirements.md) | [v0.39.0](https://github.com/tektoncd/pipeline/releases/tag/v0.39.0) | |
| [Trusted Resources](./trusted-resources.md) | [TEP-0091](https://github.com/tektoncd/community/blob/main/teps/0091-trusted-resources.md) | N/A | `trusted-resources-verification-no-match-policy` |
| [Larger Results via Sidecar Logs](#enabling-larger-results-using-sidecar-logs) | [TEP-0127](https://github.com/tektoncd/community/blob/main/teps/0127-larger-results-via-sidecar-logs.md) | [v0.43.0](https://github.com/tektoncd/pipeline/releases/tag/v0.43.0) | `results-from` |
Expand All @@ -331,13 +330,14 @@ except where otherwise noted.

Features currently in "beta" are:

| Feature | Proposal | Alpha Release | Beta Release | Individual Flag | `enable-api-fields=beta` required for `v1beta1` |
|:-------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------|:---------------------------------------------------------------------|:----------------|:---|
| [Array Results and Array Indexing](pipelineruns.md#specifying-parameters) | [TEP-0076](https://github.com/tektoncd/community/blob/main/teps/0076-array-result-types.md) | [v0.38.0](https://github.com/tektoncd/pipeline/releases/tag/v0.38.0) | [v0.45.0](https://github.com/tektoncd/pipeline/releases/tag/v0.45.0) | | No |
| [Object Parameters and Results](pipelineruns.md#specifying-parameters) | [TEP-0075](https://github.com/tektoncd/community/blob/main/teps/0075-object-param-and-result-types.md) | | [v0.46.0](https://github.com/tektoncd/pipeline/releases/tag/v0.46.0) | | No |
| [Remote Tasks](./taskruns.md#remote-tasks) and [Remote Pipelines](./pipelineruns.md#remote-pipelines) | [TEP-0060](https://github.com/tektoncd/community/blob/main/teps/0060-remote-resolution.md) | | [v0.41.0](https://github.com/tektoncd/pipeline/releases/tag/v0.41.0) | | No |
| [`Provenance` field in Status](pipeline-api.md#provenance)| [issue#5550](https://github.com/tektoncd/pipeline/issues/5550)| [v0.41.0](https://github.com/tektoncd/pipeline/releases/tag/v0.41.0)| [v0.48.0](https://github.com/tektoncd/pipeline/releases/tag/v0.48.0) | `enable-provenance-in-status`| No |
| [Isolated `Step` & `Sidecar` `Workspaces`](./workspaces.md#isolated-workspaces) | [TEP-0029](https://github.com/tektoncd/community/blob/main/teps/0029-step-workspaces.md) | [v0.24.0](https://github.com/tektoncd/pipeline/releases/tag/v0.24.0) | [v0.50.0](https://github.com/tektoncd/pipeline/releases/tag/v0.50.0) | | Yes |
| Feature | Proposal | Alpha Release | Beta Release | Individual Flag | `enable-api-fields=beta` required for `v1beta1` |
|:-------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------|:---------------------------------------------------------------------|:---------------------------------------------------------------------|:------------------------------------------------|
| [Array Results and Array Indexing](pipelineruns.md#specifying-parameters) | [TEP-0076](https://github.com/tektoncd/community/blob/main/teps/0076-array-result-types.md) | [v0.38.0](https://github.com/tektoncd/pipeline/releases/tag/v0.38.0) | [v0.45.0](https://github.com/tektoncd/pipeline/releases/tag/v0.45.0) | | No |
| [Object Parameters and Results](pipelineruns.md#specifying-parameters) | [TEP-0075](https://github.com/tektoncd/community/blob/main/teps/0075-object-param-and-result-types.md) | | [v0.46.0](https://github.com/tektoncd/pipeline/releases/tag/v0.46.0) | | No |
| [Remote Tasks](./taskruns.md#remote-tasks) and [Remote Pipelines](./pipelineruns.md#remote-pipelines) | [TEP-0060](https://github.com/tektoncd/community/blob/main/teps/0060-remote-resolution.md) | | [v0.41.0](https://github.com/tektoncd/pipeline/releases/tag/v0.41.0) | | No |
| [`Provenance` field in Status](pipeline-api.md#provenance)| [issue#5550](https://github.com/tektoncd/pipeline/issues/5550)| [v0.41.0](https://github.com/tektoncd/pipeline/releases/tag/v0.41.0)| [v0.48.0](https://github.com/tektoncd/pipeline/releases/tag/v0.48.0) | `enable-provenance-in-status` | No |
| [Isolated `Step` & `Sidecar` `Workspaces`](./workspaces.md#isolated-workspaces) | [TEP-0029](https://github.com/tektoncd/community/blob/main/teps/0029-step-workspaces.md) | [v0.24.0](https://github.com/tektoncd/pipeline/releases/tag/v0.24.0) | [v0.50.0](https://github.com/tektoncd/pipeline/releases/tag/v0.50.0) | | Yes |
| [Matrix](./matrix.md) | [TEP-0090](https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md) | [v0.38.0](https://github.com/tektoncd/pipeline/releases/tag/v0.38.0) | | [v0.53.0](https://github.com/tektoncd/pipeline/releases/tag/v0.53.0) | No |

## Enabling larger results using sidecar logs

Expand Down
8 changes: 4 additions & 4 deletions docs/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Documentation for specifying `Matrix` in a `Pipeline`:
- [Specifying `Matrix` in `Finally Tasks`](pipelines.md#specifying-matrix-in-finally-tasks)
- [Specifying `Matrix` in `Custom Tasks`](pipelines.md#specifying-matrix)

> :seedling: **`Matrix` is an [alpha](additional-configs.md#alpha-features) feature.**
> The `enable-api-fields` feature flag must be set to `"alpha"` to specify `Matrix` in a `PipelineTask`.
> :seedling: **`Matrix` is an [beta](additional-configs.md#beta-features) feature.**
> The `enable-api-fields` feature flag can be set to `"beta"` to specify `Matrix` in a `PipelineTask`.
## Configuring a Matrix

Expand Down Expand Up @@ -849,6 +849,6 @@ status:
```

[cel]: https://github.com/tektoncd/experimental/tree/1609827ea81d05c8d00f8933c5c9d6150cd36989/cel
[pr-with-matrix]: ../examples/v1/pipelineruns/alpha/pipelinerun-with-matrix.yaml
[pr-with-matrix-and-results]: ../examples/v1/pipelineruns/alpha/pipelinerun-with-matrix-and-results.yaml
[pr-with-matrix]: ../examples/v1/pipelineruns/beta/pipelinerun-with-matrix.yaml
[pr-with-matrix-and-results]: ../examples/v1/pipelineruns/beta/pipelinerun-with-matrix-and-results.yaml
[retries]: pipelines.md#using-the-retries-field
8 changes: 4 additions & 4 deletions docs/pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ spec:

### Specifying `Matrix` in `PipelineTasks`

> :seedling: **`Matrix` is an [alpha](additional-configs.md#alpha-features) feature.**
> The `enable-api-fields` feature flag must be set to `"alpha"` to specify `Matrix` in a `PipelineTask`.
> :seedling: **`Matrix` is an [beta](additional-configs.md#beta-features) feature.**
> The `enable-api-fields` feature flag can be set to `"beta"` to specify `Matrix` in a `PipelineTask`.
You can also provide [`Parameters`](tasks.md#specifying-parameters) through the `matrix` field:

Expand Down Expand Up @@ -1249,8 +1249,8 @@ spec:

### Specifying `matrix` in `finally` tasks

> :seedling: **`Matrix` is an [alpha](additional-configs.md#alpha-features) feature.**
> The `enable-api-fields` feature flag must be set to `"alpha"` to specify `Matrix` in a `PipelineTask`.
> :seedling: **`Matrix` is an [beta](additional-configs.md#beta-features) feature.**
> The `enable-api-fields` feature flag can be set to `"beta"` to specify `Matrix` in a `PipelineTask`.

Similar to `tasks`, you can also provide [`Parameters`](tasks.md#specifying-parameters) through `matrix`
in `finally` tasks:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/pipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func TestPipelineTask_ValidateMatrix(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": "alpha",
"enable-api-fields": "beta",
})
defaults := &config.Defaults{
DefaultMaxMatrixCombinationsCount: 4,
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func (pt PipelineTask) Validate(ctx context.Context) (errs *apis.FieldError) {

func (pt *PipelineTask) validateMatrix(ctx context.Context) (errs *apis.FieldError) {
if pt.IsMatrixed() {
// This is an alpha feature and will fail validation if it's used in a pipeline spec
// when the enable-api-fields feature gate is anything but "alpha".
errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "matrix", config.AlphaAPIFields))
// This is a beta feature and will fail validation if it's used in a pipeline spec
// when the enable-api-fields feature gate is set to "stable".
errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "matrix", config.BetaAPIFields))
errs = errs.Also(pt.Matrix.validateCombinationsCount(ctx))
errs = errs.Also(pt.Matrix.validateUniqueParams())
}
Expand Down
109 changes: 47 additions & 62 deletions pkg/apis/pipeline/v1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1

import (
"context"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -3502,72 +3501,58 @@ func TestPipelineTasksExecutionStatus(t *testing.T) {
// TestMatrixIncompatibleAPIVersions exercises validation of matrix
// that requires alpha feature gate version in order to work.
func TestMatrixIncompatibleAPIVersions(t *testing.T) {
task := PipelineTask{
Name: "a-task",
TaskRef: &TaskRef{Name: "a-task"},
Matrix: &Matrix{
Params: Params{{
Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}}},
}
tests := []struct {
name string
requiredVersion string
spec PipelineSpec
name string
pt PipelineTask
version string
wantErr *apis.FieldError
}{{
name: "matrix requires alpha - check tasks",
requiredVersion: "alpha",
spec: PipelineSpec{
Tasks: PipelineTaskList{{
Name: "a-task",
TaskRef: &TaskRef{Name: "a-task"},
Matrix: &Matrix{
Params: Params{{
Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}}},
}},
},
}, {
name: "matrix requires alpha - check finally tasks",
requiredVersion: "alpha",
spec: PipelineSpec{
Tasks: PipelineTaskList{{
Name: "a-task",
TaskRef: &TaskRef{Name: "a-task"},
}},
Finally: PipelineTaskList{{
Name: "b-task",
TaskRef: &TaskRef{Name: "b-task"},
Matrix: &Matrix{
Params: Params{{
Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}}},
}},
},
name: "matrix can work with alpha",
pt: task,
version: config.AlphaAPIFields,
}, {
name: "matrix requires beta",
pt: task,
version: config.BetaAPIFields,
}, {
name: "matrix not allowed with stable version",
pt: task,
version: config.StableAPIFields,
wantErr: apis.ErrGeneric("matrix requires \"enable-api-fields\" feature gate to be \"alpha\" or \"beta\" but it is \"stable\""),
}}
versions := []string{"alpha", "stable"}
for _, tt := range tests {
for _, version := range versions {
testName := fmt.Sprintf("(using %s) %s", version, tt.name)
t.Run(testName, func(t *testing.T) {
ps := tt.spec
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": version,
})
defaults := &config.Defaults{
DefaultMaxMatrixCombinationsCount: 4,
}
cfg := &config.Config{
FeatureFlags: featureFlags,
Defaults: defaults,
}

ctx := config.ToContext(context.Background(), cfg)

ps.SetDefaults(ctx)
err := ps.Validate(ctx)

if tt.requiredVersion != version && err == nil {
t.Fatalf("no error received even though version required is %q while feature gate is %q", tt.requiredVersion, version)
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
defaults := &config.Defaults{
DefaultMaxMatrixCombinationsCount: 4,
}
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": test.version,
})
cfg := &config.Config{
Defaults: defaults,
FeatureFlags: featureFlags,
}
ctx := config.ToContext(context.Background(), cfg)
err := test.pt.validateMatrix(ctx)
if test.wantErr != nil {
if d := cmp.Diff(test.wantErr.Error(), err.Error()); d != "" {
t.Error(diff.PrintWantGot(d))
}

if tt.requiredVersion == version && err != nil {
t.Fatalf("error received despite required version and feature gate matching %q: %v", version, err)
} else {
if err != nil {
t.Fatalf("PipelineTask.Validate() error = %v", err)
}
})
}
}
})
}
}

Expand Down Expand Up @@ -3634,7 +3619,7 @@ func Test_validateMatrix(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": "alpha",
"enable-api-fields": "beta",
})
defaults := &config.Defaults{
DefaultMaxMatrixCombinationsCount: 4,
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/pipeline/v1beta1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ func (pt PipelineTask) Validate(ctx context.Context) (errs *apis.FieldError) {

func (pt *PipelineTask) validateMatrix(ctx context.Context) (errs *apis.FieldError) {
if pt.IsMatrixed() {
// This is an alpha feature and will fail validation if it's used in a pipeline spec
// when the enable-api-fields feature gate is anything but "alpha".
errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "matrix", config.AlphaAPIFields))
errs = errs.Also(pt.Matrix.validateCombinationsCount(ctx))
errs = errs.Also(pt.Matrix.validateUniqueParams())
}
Expand Down
75 changes: 1 addition & 74 deletions pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1beta1

import (
"context"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -3542,78 +3541,6 @@ func TestPipelineTasksExecutionStatus(t *testing.T) {
}
}

// TestMatrixIncompatibleAPIVersions exercises validation of matrix
// that requires alpha feature gate version in order to work.
func TestMatrixIncompatibleAPIVersions(t *testing.T) {
tests := []struct {
name string
requiredVersion string
spec PipelineSpec
}{{
name: "matrix requires alpha - check tasks",
requiredVersion: "alpha",
spec: PipelineSpec{
Tasks: PipelineTaskList{{
Name: "a-task",
TaskRef: &TaskRef{Name: "a-task"},
Matrix: &Matrix{
Params: Params{{
Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}}},
}},
},
}, {
name: "matrix requires alpha - check finally tasks",
requiredVersion: "alpha",
spec: PipelineSpec{
Tasks: PipelineTaskList{{
Name: "a-task",
TaskRef: &TaskRef{Name: "a-task"},
}},
Finally: PipelineTaskList{{
Name: "b-task",
TaskRef: &TaskRef{Name: "b-task"},
Matrix: &Matrix{
Params: Params{{
Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}}},
}},
},
}}
versions := []string{"alpha", "stable"}
for _, tt := range tests {
for _, version := range versions {
testName := fmt.Sprintf("(using %s) %s", version, tt.name)
t.Run(testName, func(t *testing.T) {
ps := tt.spec
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": version,
})
defaults := &config.Defaults{
DefaultMaxMatrixCombinationsCount: 4,
}
cfg := &config.Config{
FeatureFlags: featureFlags,
Defaults: defaults,
}

ctx := config.ToContext(context.Background(), cfg)

ps.SetDefaults(ctx)
err := ps.Validate(ctx)

if tt.requiredVersion != version && err == nil {
t.Fatalf("no error received even though version required is %q while feature gate is %q", tt.requiredVersion, version)
}

if tt.requiredVersion == version && err != nil {
t.Fatalf("error received despite required version and feature gate matching %q: %v", version, err)
}
})
}
}
}

func Test_validateMatrix(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -3677,7 +3604,7 @@ func Test_validateMatrix(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": "alpha",
"enable-api-fields": "beta",
})
defaults := &config.Defaults{
DefaultMaxMatrixCombinationsCount: 4,
Expand Down
Loading

0 comments on commit 4919dba

Please sign in to comment.