From ae9c0537d149d3f11c42079f9cf965772394c265 Mon Sep 17 00:00:00 2001 From: Yongxuan Zhang Date: Tue, 2 May 2023 20:27:33 +0000 Subject: [PATCH] check beta feature flag for v1 TaskSpec's ValidateParamArrayIndex This commit closes #6607. V1 TaskSpec's member function ValidateParamArrayIndex checks alpha feature flag, but array indexing is promoted to beta feature and we should check beta flag instead. And for v1beta1 the beta is on by default so we don't check the beta flag. This commit fixes this issue and also update doc. Signed-off-by: Yongxuan Zhang yongxuanzhang@google.com --- docs/additional-configs.md | 2 +- pkg/apis/pipeline/v1/task_validation.go | 3 +-- pkg/apis/pipeline/v1/task_validation_test.go | 2 +- pkg/apis/pipeline/v1beta1/pipeline_validation.go | 4 ---- pkg/apis/pipeline/v1beta1/pipeline_validation_test.go | 3 --- pkg/apis/pipeline/v1beta1/task_validation.go | 5 ----- pkg/apis/pipeline/v1beta1/task_validation_test.go | 3 +-- 7 files changed, 4 insertions(+), 18 deletions(-) diff --git a/docs/additional-configs.md b/docs/additional-configs.md index f0f3021d3e7..bb34e08e5e4 100644 --- a/docs/additional-configs.md +++ b/docs/additional-configs.md @@ -301,7 +301,7 @@ Features currently in "beta" are: | Feature | Proposal | Alpha Release | Beta Release | Individual Flag | |:-------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------|:---------------------------------------------------------------------|:----------------| -| [Array Results](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) | | +| [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) | | ## Enabling larger results using sidecar logs diff --git a/pkg/apis/pipeline/v1/task_validation.go b/pkg/apis/pipeline/v1/task_validation.go index 5848053bf6b..ccfd0f63158 100644 --- a/pkg/apis/pipeline/v1/task_validation.go +++ b/pkg/apis/pipeline/v1/task_validation.go @@ -609,8 +609,7 @@ func isParamRefs(s string) bool { // - `trParams` are params from taskrun. // - `taskSpec` contains params declarations. func (ts *TaskSpec) ValidateParamArrayIndex(ctx context.Context, params Params) error { - cfg := config.FromContextOrDefaults(ctx) - if cfg.FeatureFlags.EnableAPIFields != config.AlphaAPIFields { + if !config.CheckAlphaOrBetaAPIFields(ctx) { return nil } diff --git a/pkg/apis/pipeline/v1/task_validation_test.go b/pkg/apis/pipeline/v1/task_validation_test.go index 6c9a6de521d..b0c834d73d3 100644 --- a/pkg/apis/pipeline/v1/task_validation_test.go +++ b/pkg/apis/pipeline/v1/task_validation_test.go @@ -1917,7 +1917,7 @@ func TestValidateParamArrayIndex(t *testing.T) { } for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - ctx := config.ToContext(context.Background(), &config.Config{FeatureFlags: &config.FeatureFlags{EnableAPIFields: "alpha"}}) + ctx := config.ToContext(context.Background(), &config.Config{FeatureFlags: &config.FeatureFlags{EnableAPIFields: "beta"}}) err := tc.taskspec.ValidateParamArrayIndex(ctx, tc.params) if d := cmp.Diff(tc.expectedError.Error(), err.Error()); d != "" { t.Errorf("validateParamArrayIndex() errors diff %s", diff.PrintWantGot(d)) diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation.go b/pkg/apis/pipeline/v1beta1/pipeline_validation.go index 80bb7c6d175..becf465a1bb 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation.go @@ -714,10 +714,6 @@ func validateResultsFromMatrixedPipelineTasksNotConsumed(tasks []PipelineTask, f // error is returned when the array indexing reference is out of bound of the array param // e.g. if a param reference of $(params.array-param[2]) and the array param is of length 2. func (ps *PipelineSpec) ValidateParamArrayIndex(ctx context.Context, params Params) error { - if !config.CheckAlphaOrBetaAPIFields(ctx) { - return nil - } - // Collect all array params lengths arrayParamsLengths := ps.Params.extractParamArrayLengths() for k, v := range params.extractParamArrayLengths() { diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go index 04b366fa8f0..929cec14f40 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go @@ -3524,9 +3524,6 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { func TestValidateParamArrayIndex_invalid(t *testing.T) { ctx := context.Background() - cfg := config.FromContextOrDefaults(ctx) - cfg.FeatureFlags.EnableAPIFields = config.BetaAPIFields - ctx = config.ToContext(ctx, cfg) for _, tt := range []struct { name string original PipelineSpec diff --git a/pkg/apis/pipeline/v1beta1/task_validation.go b/pkg/apis/pipeline/v1beta1/task_validation.go index e76f342121f..e803aa21575 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation.go +++ b/pkg/apis/pipeline/v1beta1/task_validation.go @@ -612,11 +612,6 @@ func isParamRefs(s string) bool { // - `trParams` are params from taskrun. // - `taskSpec` contains params declarations. func (ts *TaskSpec) ValidateParamArrayIndex(ctx context.Context, params Params) error { - cfg := config.FromContextOrDefaults(ctx) - if cfg.FeatureFlags.EnableAPIFields != config.AlphaAPIFields { - return nil - } - // Collect all array params lengths arrayParamsLengths := ts.Params.extractParamArrayLengths() for k, v := range params.extractParamArrayLengths() { diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index dda5ac70285..5e7b0716cad 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -1929,8 +1929,7 @@ func TestValidateParamArrayIndex(t *testing.T) { } for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - ctx := config.ToContext(context.Background(), &config.Config{FeatureFlags: &config.FeatureFlags{EnableAPIFields: "alpha"}}) - err := tc.taskspec.ValidateParamArrayIndex(ctx, tc.params) + err := tc.taskspec.ValidateParamArrayIndex(context.Background(), tc.params) if d := cmp.Diff(tc.expectedError.Error(), err.Error()); d != "" { t.Errorf("validateParamArrayIndex() errors diff %s", diff.PrintWantGot(d)) }