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

fix(pipeline): correct warning path for duplicate param name in pipeline tasks #7651

Merged
merged 1 commit into from
Feb 12, 2024
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
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func validatePipelineTaskParameterUsage(tasks []PipelineTask, params ParamSpecs)
}
errs = errs.Also(validatePipelineParametersVariables(tasks, "params", allParamNames, arrayParamNames, objectParameterNameKeys))
for i, task := range tasks {
errs = errs.Also(task.Params.validateDuplicateParameters().ViaFieldIndex("params", i))
errs = errs.Also(task.Params.validateDuplicateParameters().ViaField("params").ViaIndex(i))
Copy link
Contributor Author

@l-qing l-qing Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference:

func ValidatePipelineParameterVariables(ctx context.Context, tasks []PipelineTask, params ParamSpecs) (errs *apis.FieldError) {
// validates all the types within a slice of ParamSpecs
errs = errs.Also(ValidateParameterTypes(ctx, params).ViaField("params"))
errs = errs.Also(params.ValidateNoDuplicateNames())
errs = errs.Also(params.validateParamEnums(ctx).ViaField("params"))
for i, task := range tasks {
errs = errs.Also(task.Params.validateDuplicateParameters().ViaField("params").ViaIndex(i))
}

}
return errs
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/apis/pipeline/v1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,52 @@ func TestPipeline_Validate_Failure(t *testing.T) {
Message: `non-existent variable in "$(params.doesnotexist)"`,
Paths: []string{"spec.finally[0].steps[0].script"},
},
}, {
name: "invalid duplicate parameter in pipeline task",
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "pipeline"},
Spec: PipelineSpec{
Tasks: []PipelineTask{{
Name: "pipeline-task",
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "some-step",
Image: "some-image",
Command: []string{"cmd"},
}},
}},
}},
Finally: []PipelineTask{{
Name: "invalid-pipeline-task",
Params: Params{
{
Name: "name",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "",
},
},
{
Name: "name",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "",
},
},
},
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "some-step",
Image: "some-image",
}},
}},
}},
},
},
expectedError: apis.FieldError{
Message: `parameter names must be unique, the parameter "name" is also defined at`,
Paths: []string{"spec.finally[0].params[1].name"},
},
}, {
name: "invalid task with pipelineRef and pipelineSpec",
wc: cfgtesting.EnableAlphaAPIFields,
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func validatePipelineTaskParameterUsage(tasks []PipelineTask, params ParamSpecs)
}
errs = errs.Also(validatePipelineParametersVariables(tasks, "params", allParamNames, arrayParamNames, objectParameterNameKeys))
for i, task := range tasks {
errs = errs.Also(task.Params.validateDuplicateParameters().ViaFieldIndex("params", i))
errs = errs.Also(task.Params.validateDuplicateParameters().ViaField("params").ViaIndex(i))
}
return errs
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,52 @@ func TestPipeline_Validate_Failure(t *testing.T) {
Message: `non-existent variable in "$(params.doesnotexist)"`,
Paths: []string{"spec.finally[0].steps[0].script"},
},
}, {
name: "invalid duplicate parameter in pipeline task",
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "pipeline"},
Spec: PipelineSpec{
Tasks: []PipelineTask{{
Name: "pipeline-task",
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "some-step",
Image: "some-image",
Command: []string{"cmd"},
}},
}},
}},
Finally: []PipelineTask{{
Name: "invalid-pipeline-task",
Params: Params{
{
Name: "name",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "",
},
},
{
Name: "name",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "",
},
},
},
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "some-step",
Image: "some-image",
}},
}},
}},
},
},
expectedError: apis.FieldError{
Message: `parameter names must be unique, the parameter "name" is also defined at`,
Paths: []string{"spec.finally[0].params[1].name"},
},
}, {
name: "invalid task with pipelineRef and pipelineSpec",
wc: cfgtesting.EnableAlphaAPIFields,
Expand Down