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

Add validation for duplicated param names in TaskSpec #4806

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
8 changes: 6 additions & 2 deletions pkg/apis/pipeline/v1beta1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,12 @@ func ValidateParameterVariables(steps []Step, params []ParamSpec) *apis.FieldErr
parameterNames := sets.NewString()
arrayParameterNames := sets.NewString()
objectParamSpecs := []ParamSpec{}

var errs *apis.FieldError
for _, p := range params {
// validate no duplicate names
if parameterNames.Has(p.Name) {
errs = errs.Also(apis.ErrGeneric("parameter appears more than once", "").ViaFieldKey("params", p.Name))
}
parameterNames.Insert(p.Name)
if p.Type == ParamTypeArray {
arrayParameterNames.Insert(p.Name)
Expand All @@ -332,7 +336,7 @@ func ValidateParameterVariables(steps []Step, params []ParamSpec) *apis.FieldErr
}
}

errs := validateVariables(steps, "params", parameterNames)
errs = errs.Also(validateVariables(steps, "params", parameterNames))
errs = errs.Also(validateArrayUsage(steps, "params", arrayParameterNames))
return errs.Also(validateObjectUsage(steps, objectParamSpecs))
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/pipeline/v1beta1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,26 @@ func TestTaskSpecValidateError(t *testing.T) {
Paths: []string{"params"},
Details: "Names: \nMust only contain alphanumeric characters, hyphens (-), underscores (_), and dots (.)\nMust begin with a letter or an underscore (_)",
},
}, {
name: "duplicated param names",
fields: fields{
Params: []v1beta1.ParamSpec{{
Name: "foo",
Type: v1beta1.ParamTypeString,
Description: "parameter",
Default: v1beta1.NewArrayOrString("value1"),
}, {
Name: "foo",
Type: v1beta1.ParamTypeString,
Description: "parameter",
Default: v1beta1.NewArrayOrString("value2"),
}},
Steps: validSteps,
},
expectedError: apis.FieldError{
Message: `parameter appears more than once`,
Paths: []string{"params[foo]"},
},
}, {
name: "invalid param type",
fields: fields{
Expand Down