Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongxuanzhang committed Feb 8, 2023
1 parent 1594422 commit 09cc73b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions pkg/reconciler/taskrun/validate_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func validateParamArrayIndex(ctx context.Context, params []v1beta1.Param, spec *
}

// FindInvalidParamArrayReference checks if the alpha feature gate is enabled when array
// indexing is used. And also find out out of bound params
// indexing is used. And also find out of bound params
func FindInvalidParamArrayReference(ctx context.Context, paramReference string, arrayParams map[string]int, outofBoundParams *sets.String) error {
list := substitution.ExtractParamsExpressions(paramReference)
for _, val := range list {
Expand All @@ -464,9 +464,12 @@ func FindInvalidParamArrayReference(ctx context.Context, paramReference string,

func validateStepsParamArrayIndexing(ctx context.Context, steps []v1beta1.Step, arrayParams map[string]int, outofBoundParams *sets.String) error {
for _, step := range steps {
FindInvalidParamArrayReference(ctx, step.Script, arrayParams, outofBoundParams)
err := FindInvalidParamArrayReference(ctx, step.Script, arrayParams, outofBoundParams)
if err != nil {
return err
}
container := step.ToK8sContainer()
err := validateContainerParamArrayIndexing(ctx, container, arrayParams, outofBoundParams)
err = validateContainerParamArrayIndexing(ctx, container, arrayParams, outofBoundParams)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/taskrun/validate_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,15 +1137,15 @@ func TestValidateParamArrayIndex(t *testing.T) {
},
},
},
apifields: "stable",
expectedError: fmt.Errorf(`indexing into an array param %s requires "enable-api-fields" feature gate to be "alpha"`, "$(params.array-params[3])"),
apifields: "stable",
expectedError: fmt.Errorf(`indexing into array param %s requires "enable-api-fields" feature gate to be "alpha"`, "$(params.array-params[3])"),
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
if tc.apifields != "stable" {
ctx = config.ToContext(context.Background(), &config.Config{FeatureFlags: &config.FeatureFlags{EnableAPIFields: "alpha"}})
ctx:= context.Background()
if tc.apifields!="stable"{
ctx = config.ToContext(ctx, &config.Config{FeatureFlags: &config.FeatureFlags{EnableAPIFields: "alpha"}})
}
err := validateParamArrayIndex(ctx, tc.params, tc.taskspec)
if d := cmp.Diff(tc.expectedError.Error(), err.Error()); d != "" {
Expand Down

0 comments on commit 09cc73b

Please sign in to comment.