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

Conversation

chitrangpatel
Copy link
Contributor

@chitrangpatel chitrangpatel commented Apr 27, 2022

Prior to this, when duplicated names for parameters were assigned in
taskSpec, the param value would be overwritten by the last value.

Changes

To avoid this, a validation check was added to ensure that no param name
is duplicated in TaskSpec. This PR address issue #4798.

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in
    (if there are no user facing changes, use release note "NONE")

Release Notes

Add validation for duplicated param names in TaskSpec.

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 27, 2022
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 27, 2022
@tekton-robot
Copy link
Collaborator

Hi @chitrangpatel. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 27, 2022
@chuangw6
Copy link
Member

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 27, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.1% 97.2% 0.1

@chitrangpatel chitrangpatel force-pushed the Issue-4798-Missing-validation-against-duplicated-parameter-names branch from d22579e to 09a0bc2 Compare April 28, 2022 12:28
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.1% 97.2% 0.1

@abayer
Copy link
Contributor

abayer commented Apr 28, 2022

/retest

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.1% 97.2% 0.1

@dibyom
Copy link
Member

dibyom commented Apr 29, 2022

/test pull-tekton-pipeline-alpha-integration-tests

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.1% 97.2% 0.1

@chitrangpatel
Copy link
Contributor Author

/test pull-tekton-pipeline-alpha-integration-tests

Comment on lines 65 to 66
errs = errs.Also(validateParameterNames(ts.Params).ViaField("params"))
errs = errs.Also(ValidateParameterTypes(ts.Params).ViaField("params"))
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could have a ValidateParamSpecs function that does both of those at the same time. Probably an opmitization at that point of time though.

@chitrangpatel
Copy link
Contributor Author

/retest

@chitrangpatel chitrangpatel force-pushed the Issue-4798-Missing-validation-against-duplicated-parameter-names branch from f09d585 to 09e8c44 Compare May 9, 2022 17:15
@chitrangpatel chitrangpatel changed the title Issue #4798 missing validation against duplicated parameter names Add validation for duplicated param names in TaskSpec May 9, 2022
@chitrangpatel chitrangpatel force-pushed the Issue-4798-Missing-validation-against-duplicated-parameter-names branch from 09e8c44 to d4f8711 Compare May 9, 2022 17:39
@chitrangpatel
Copy link
Contributor Author

/retest

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.0% 97.1% 0.1

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 11, 2022
@chitrangpatel
Copy link
Contributor Author

/assign @vdemeester

Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

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

Thanks Chitrang for fixing this issue!

@@ -244,6 +244,17 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi
return errs
}

// ValidateParameterSpecs validates that there are no duplicate names in the TaskSpec and all the types within a slice of ParamSpecs.
func validateParameterSpecs(params []ParamSpec) (errs *apis.FieldError) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it might make more sense to add this validation to the function ValidateParameterVariables, and likewise in ValidatePipelineParameterVariables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! I made the necessary changes.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like the changes were applied to ValidatePipelineParameterVariables?

Also, no need to make any changes to v1alpha1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validatePipelineParameterVariables was already checking for duplicated param names and param types so no changed needed to be made there. It was only missing at the task validation stage.

Yes, now that I moved the function call to validateParamTypes back to where it was, ctx was no longer required by ValidateParameterVariables and so the change to v1alpha1 was also undone.

@chitrangpatel chitrangpatel force-pushed the Issue-4798-Missing-validation-against-duplicated-parameter-names branch 2 times, most recently from 05aa6fe to b30f933 Compare May 17, 2022 21:05
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 17, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% 0.0

func ValidateParameterVariables(steps []Step, params []ParamSpec) *apis.FieldError {
func ValidateParameterVariables(ctx context.Context, steps []Step, params []ParamSpec) *apis.FieldError {
// Validate Parameter Types
errs := ValidateParameterTypes(ctx, params).ViaField("params")
Copy link
Member

Choose a reason for hiding this comment

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

I think the call to this function is OK to stay where it was

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. That will simplify things since I don't need to pass in the context which is why I also had to make changes to v1alpha1.

Prior to this, when duplicated names for parameters were assigned in `taskSpec`, the param value would be overwritten by the last value.

To avoid this, a validation check was added to ensure that no param name is duplicated in TaskSpec.
@chitrangpatel chitrangpatel force-pushed the Issue-4798-Missing-validation-against-duplicated-parameter-names branch from b30f933 to 1d67120 Compare May 18, 2022 12:44
@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 18, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% 0.0

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 18, 2022
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 20, 2022
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick, vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot merged commit 3a305a0 into tektoncd:main May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants