Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove enable-api-fields validation for array index replacements #6646

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"strconv"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/config"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
"github.com/tektoncd/pipeline/pkg/substitution"
Expand Down Expand Up @@ -63,11 +61,8 @@ func ApplyParameters(ctx context.Context, p *v1beta1.PipelineSpec, pr *v1beta1.P
switch p.Default.Type {
case v1beta1.ParamTypeArray:
for _, pattern := range paramPatterns {
// array indexing for param is beta feature - the feature flag can be either set to alpha or beta
if config.CheckAlphaOrBetaAPIFields(ctx) {
for i := 0; i < len(p.Default.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Default.ArrayVal[i]
}
for i := 0; i < len(p.Default.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Default.ArrayVal[i]
}
arrayReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.ArrayVal
}
Expand Down Expand Up @@ -114,11 +109,8 @@ func paramsFromPipelineRun(ctx context.Context, pr *v1beta1.PipelineRun) (map[st
switch p.Value.Type {
case v1beta1.ParamTypeArray:
for _, pattern := range paramPatterns {
// array indexing for param is beta feature - the feature flag can be either set to alpha ot beta
if config.CheckAlphaOrBetaAPIFields(ctx) {
for i := 0; i < len(p.Value.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Value.ArrayVal[i]
}
for i := 0; i < len(p.Value.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Value.ArrayVal[i]
}
arrayReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.ArrayVal
}
Expand Down
12 changes: 2 additions & 10 deletions pkg/reconciler/pipelinerun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1727,10 +1727,6 @@ func TestApplyParameters(t *testing.T) {
}

func TestApplyParameters_ArrayIndexing(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 v1beta1.PipelineSpec
Expand Down Expand Up @@ -2027,7 +2023,7 @@ func TestApplyParameters_ArrayIndexing(t *testing.T) {
Params: tt.params,
},
}
got := resources.ApplyParameters(ctx, &tt.original, run)
got := resources.ApplyParameters(context.Background(), &tt.original, run)
if d := cmp.Diff(&tt.expected, got); d != "" {
t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d))
}
Expand All @@ -2036,10 +2032,6 @@ func TestApplyParameters_ArrayIndexing(t *testing.T) {
}

func TestApplyReplacementsMatrix(t *testing.T) {
ctx := context.Background()
cfg := config.FromContextOrDefaults(ctx)
cfg.FeatureFlags.EnableAPIFields = config.AlphaAPIFields
ctx = config.ToContext(ctx, cfg)
for _, tt := range []struct {
name string
original v1beta1.PipelineSpec
Expand Down Expand Up @@ -2283,7 +2275,7 @@ func TestApplyReplacementsMatrix(t *testing.T) {
Params: tt.params,
},
}
got := resources.ApplyParameters(ctx, &tt.original, run)
got := resources.ApplyParameters(context.Background(), &tt.original, run)
if d := cmp.Diff(&tt.expected, got); d != "" {
t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d))
}
Expand Down
14 changes: 4 additions & 10 deletions pkg/reconciler/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ func ApplyParameters(ctx context.Context, spec *v1beta1.TaskSpec, tr *v1beta1.Ta
switch p.Default.Type {
case v1beta1.ParamTypeArray:
for _, pattern := range paramPatterns {
// array indexing for param is beta feature
if config.CheckAlphaOrBetaAPIFields(ctx) {
for i := 0; i < len(p.Default.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Default.ArrayVal[i]
}
for i := 0; i < len(p.Default.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Default.ArrayVal[i]
}
arrayReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.ArrayVal
}
Expand Down Expand Up @@ -105,11 +102,8 @@ func paramsFromTaskRun(ctx context.Context, tr *v1beta1.TaskRun) (map[string]str
switch p.Value.Type {
case v1beta1.ParamTypeArray:
for _, pattern := range paramPatterns {
// array indexing for param is beta feature
if config.CheckAlphaOrBetaAPIFields(ctx) {
for i := 0; i < len(p.Value.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Value.ArrayVal[i]
}
for i := 0; i < len(p.Value.ArrayVal); i++ {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Value.ArrayVal[i]
}
arrayReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.ArrayVal
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/reconciler/taskrun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,7 @@ func TestApplyParameters_ArrayIndexing(t *testing.T) {
spec.Sidecars[0].Image = "bar"
spec.Sidecars[0].Env[0].Value = "world"
})
ctx := context.Background()
cfg := config.FromContextOrDefaults(ctx)
cfg.FeatureFlags.EnableAPIFields = config.BetaAPIFields
ctx = config.ToContext(ctx, cfg)
got := resources.ApplyParameters(ctx, simpleTaskSpecArrayIndexing, tr, dp...)
got := resources.ApplyParameters(context.Background(), simpleTaskSpecArrayIndexing, tr, dp...)
if d := cmp.Diff(want, got); d != "" {
t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d))
}
Expand Down