Skip to content

Commit fe42e6b

Browse files
JeromeJutekton-robot
authored andcommitted
Add Per-feature Flag Struct for New Features
This commit adds the per-feature flag struct and documentations for new features in TektonCD pipeline. part of: TEP-0138
1 parent af5d62b commit fe42e6b

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

api_compatibility_policy.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,22 @@ For more information on support windows, see the [deprecations table](./docs/dep
9090

9191
## Feature Gates
9292

93-
Stability levels of feature gates are independent from CRD apiVersions. Features enabled by API fields at different levels of stability can be enabled using the flag `enable-api-fields`:
93+
Stability levels of feature gates are independent from CRD apiVersions.
94+
95+
[TEP0138](https://github.com/tektoncd/community/blob/main/teps/0138-decouple-api-and-feature-versioning.md) has introduced per-feature flags for new API-driven features and the migration plan for `enable-api-fields`. Please refer to the table below for the API-driven features validation transition:
96+
97+
| Releases | Global flag `enable-api-fields` | Per-feature flag |
98+
| ---------------------- | -------------------------------- | ---------------------------------- |
99+
| Prior to v0.53.0 | All alpha/beta API-driven features | |
100+
| After v0.53.0 | [Existing alpha/beta API-driven features](https://github.com/tektoncd/community/blob/02418c0d39578a6a42f9d2d30caea8060dd89385/teps/0138-decouple-api-and-feature-versioning.md#sunset-enable-api-fields-after-existing-features-stabilize) prior to v0.53.0 | New alpha/beta API-driven features introduced after v0.53.0 |
101+
| All [alpha/beta API-driven features in v0.53.0](https://github.com/tektoncd/community/blob/02418c0d39578a6a42f9d2d30caea8060dd89385/teps/0138-decouple-api-and-feature-versioning.md#sunset-enable-api-fields-after-existing-features-stabilize) become stable or are removed | Sunset ~~`enable-api-fields`~~ | All alpha/beta API-driven features |
102+
103+
104+
_Note that behavioural(non-API-driven) flags will retain their original usage._
105+
106+
With per-feature flags, cluster operators are able to enable a single new feature with their dedicated feature flags. For instructions on how to add a per-feature flag, please check the [developer feature versioning guide](./docs/developers/feature-versioning.md#per-feature-flag).
107+
108+
Note that the `enable-api-fields` feature flag will continue to validate all features that were[beta](https://github.com/tektoncd/pipeline/blob/release-v0.52.x/docs/additional-configs.md#beta-features) and [alpha](https://github.com/tektoncd/pipeline/blob/release-v0.52.x/docs/additional-configs.md#alpha-features) prior to [v0.53.0](https://github.com/tektoncd/pipeline/tree/release-v0.53.x):
94109

95110
* `stable` - This value indicates that only fields of the highest stability level are enabled; i.e. `alpha` and `beta` fields are not enabled.
96111

docs/developers/feature-versioning.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
11
# Feature Versioning
22

3-
The stability levels of features (feature versioning) are independent of CRD API versions (API versioning).
3+
The stability levels of features (feature versioning) are independent of CRD [API versioning](./api-versioning.md).
44

55
## Adding feature gates for API-driven features
6-
API-driven features are features that are enabled via a specific field in pipeline API. They comply to the [feature gates](../../api_compatibility_policy.md#feature-gates) and the [feature graduation process](../../api_compatibility_policy.md#feature-graduation-process) specified in the [API compatibility policy](../../api_compatibility_policy.md). For example, [remote tasks](https://github.com/tektoncd/pipeline/blob/454bfd340d102f16f4f2838cf4487198537e3cfa/docs/taskruns.md#remote-tasks) is an API-driven feature.
6+
API-driven features are features that are accessed via a specific field in pipeline API. They comply to the [feature gates](../../api_compatibility_policy.md#feature-gates) and the [feature graduation process](../../api_compatibility_policy.md#feature-graduation-process) specified in the [API compatibility policy](../../api_compatibility_policy.md). For example, [remote tasks](https://github.com/tektoncd/pipeline/blob/454bfd340d102f16f4f2838cf4487198537e3cfa/docs/taskruns.md#remote-tasks) is an API-driven feature.
7+
8+
## Adding feature gated API fields for API-driven features
9+
### Per-feature flag
10+
11+
All new features added after [v0.53.0](https://github.com/tektoncd/pipeline/releases/tag/v0.53.0) will be enabled by their dedicated feature flags. To introduce a new per-feature flag, we will proceed as follows:
12+
- Add default values to the new per-feature flag for the new API-driven feature following the `PerFeatureFlag` struct in [feature_flags.go](./../../pkg/apis/config/feature_flags.go).
13+
- Write unit tests to verify the new feature flag and update all test cases that require the configMap setting, such as those related to provenance propagation.
14+
- To add integration tests:
15+
- First, add the tests to `pull-tekton-pipeline-alpha-integration-test` by enabling the newly-introduced per-feature flag at [alpha test Prow environment](./../../test/e2e-tests-kind-prow-alpha.env).
16+
- When the flag is promoted to `beta` stability level, change the test to use [beta Prow environment setup](./../../test/e2e-tests-kind-prow-beta.env).
17+
- To add additional CI tests for combinations of feature flags, add tests for all alpha feature flags being turned on, with one alpha feature turned off at a time.
18+
- Add the tested new per-feature flag key value to the [the pipeline configMap](./../../config/config-feature-flags.yaml).
19+
- Update documentations for the new alpha feature at [alpha-stability-level](./../additional-configs.md#alpha-features).
20+
21+
#### Example of adding a new Per-feature flag
22+
1. Add the default value following the Per-Feature flag struct
23+
```golang
24+
const enableExampleNewFeatureKey = 'example-new-feature'
25+
26+
var DefaultExampleNewFeatre = PerFeatureFlag {
27+
Name: enableExampleNewFeatureKey,
28+
Stability: AlphaAPIFields,
29+
Enabled: DefaultAlphaFeatureEnabled,
30+
}
31+
```
32+
2. Add unit tests with the newly-introduced yamls `feature-flags-example-new-feature` and `feature-flags-invalid-example-new-feature` according to the existing testing framework.
33+
34+
3. For integration tests, add `example-new-feature: true` to [alpha test Prow environment](./../../test/e2e-tests-kind-prow-alpha.env).
35+
36+
4. Add `example-new-feature: false` to [the pipeline configMap](./../../config/config-feature-flags.yaml) with a release note.
37+
38+
5. Update documentations for the new alpha feature at [alpha-stability-level](./../additional-configs.md#alpha-features).
39+
740
### `enable-api-fields`
841

9-
We've introduced a feature-flag called `enable-api-fields` to the
42+
Prior to [v0.53.0](https://github.com/tektoncd/pipeline/tree/release-v0.53.x), we have had the global feature flag `enable-api-fields` in
1043
[config-feature-flags.yaml file](../../config/config-feature-flags.yaml)
1144
deployed as part of our releases.
1245

46+
_Note that the `enable-api-fields` flag will has been deprecated since [v0.53.0](https://github.com/tektoncd/pipeline/tree/release-v0.53.x) and we will transition to use [Per-feature flags](#per-feature-flag) instead._
47+
1348
This field can be configured either to be `alpha`, `beta`, or `stable`. This field is
1449
documented as part of our
1550
[install docs](../install.md#customizing-the-pipelines-controller-behavior).

pkg/apis/config/feature_flags.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ import (
2727
)
2828

2929
const (
30-
// StableAPIFields is the value used for "enable-api-fields" when only stable APIs should be usable.
30+
// StableAPIFields is the value used for API-driven features of stable stability level.
3131
StableAPIFields = "stable"
32-
// AlphaAPIFields is the value used for "enable-api-fields" when alpha APIs should be usable as well.
32+
// AlphaAPIFields is the value used for API-driven features of alpha stability level.
3333
AlphaAPIFields = "alpha"
34-
// BetaAPIFields is the value used for "enable-api-fields" when beta APIs should be usable as well.
34+
// BetaAPIFields is the value used for API-driven features of beta stability level.
3535
BetaAPIFields = "beta"
36+
// Features of "alpha" stability level are disabled by default
37+
DefaultAlphaFeatureEnabled = false
38+
// Features of "beta" stability level are disabled by default
39+
DefaultBetaFeatureEnabled = false
40+
// Features of "stable" stability level are enabled by default
41+
DefaultStableFeatureEnabled = true
3642
// FailNoMatchPolicy is the value used for "trusted-resources-verification-no-match-policy" to fail TaskRun or PipelineRun
3743
// when no matching policies are found
3844
FailNoMatchPolicy = "fail"
@@ -366,3 +372,18 @@ func GetVerificationNoMatchPolicy(ctx context.Context) string {
366372
func IsSpireEnabled(ctx context.Context) bool {
367373
return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire
368374
}
375+
376+
// TODO(#7285): Patch the default values of new features that were added after
377+
// `enable-api-fields` was no longer used.
378+
type PerFeatureFlag struct {
379+
// Name of the feature flag
380+
Name string
381+
// Stability level of the feature, one of StableAPIFields, BetaAPIFields or AlphaAPIFields
382+
Stability string
383+
// Enabled is whether the feature is turned on
384+
Enabled bool
385+
// Deprecated indicates whether the feature is deprecated
386+
// +optional
387+
//nolint:gocritic
388+
Deprecated bool
389+
}

0 commit comments

Comments
 (0)