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 duplicate code for validating params types and defaults #4872

Merged
merged 1 commit into from
Jun 2, 2022

Conversation

chuangw6
Copy link
Member

@chuangw6 chuangw6 commented May 13, 2022

Changes

Prior to this commit, PipelineSpec's ParamSpec type validation
was re-implemented in pipeline_validation.go, which actually has
been implemented in task_validation.go for the ParamSpec's type
validation.

So in this commit, we replace the duplicate code with existing function.

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

NONE

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 13, 2022
@chuangw6
Copy link
Member Author

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

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 Chuang! I think it could make sense to move parameter validation out of task_validation.go and pipeline_validation.go into a new param_validation.go file since a lot of the param code seems to be duplicated between pipeline and task validation.

pkg/apis/pipeline/v1beta1/pipeline_validation.go Outdated Show resolved Hide resolved
@chuangw6
Copy link
Member Author

chuangw6 commented May 18, 2022

Thanks Chuang! I think it could make sense to move parameter validation out of task_validation.go and pipeline_validation.go into a new param_validation.go file since a lot of the param code seems to be duplicated between pipeline and task validation.

Hi @lbernick ,
Great point!! I totally agree. I find that duplicate code regarding param validation exists not only here in validation webhook but also in the reconciler level i.e. those two are doing same thing as the code here. But it's a bit tricky for the reconciler level since they are living in different packages i.e. taskrun, pipelinerun.

Would you recommend we also refactor reconciler level to extract a dedicated file? If so, I am happy to do that after finishing the refactor of this validation webhook level.

@chuangw6
Copy link
Member Author

Thanks Chuang! I think it could make sense to move parameter validation out of task_validation.go and pipeline_validation.go into a new param_validation.go file since a lot of the param code seems to be duplicated between pipeline and task validation.

Just thinking that moving param validation related functions to a new file will be a big change for other existing PRs like #4867 #4861 since they are modifying the param validation functions in the original file.
How about we move them to the new file after they get merged? @lbernick

Prior to this commit, PipelineSpec's ParamSpec type validation
was reimplemented in pipeline_validation.go, which actually has
been implemented in task_validation.go for the ParamSpec's type
validation.

So in this commit, we replace the duplicate code with existing function.
@chuangw6 chuangw6 force-pushed the 75-pipeline-level-validation branch from 60cb8f7 to 2f3fd4a Compare May 18, 2022 04:42
@chuangw6
Copy link
Member Author

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

@lbernick
Copy link
Member

Great point!! I totally agree. I find that duplicate code regarding param validation exists not only here in validation webhook but also in the reconciler level i.e. those two are doing same thing as the code here. But it's a bit tricky for the reconciler level since they are living in different packages i.e. taskrun, pipelinerun.

Would you recommend we also refactor reconciler level to extract a dedicated file? If so, I am happy to do that after finishing the refactor of this validation webhook level.

That could definitely make sense! We have something similar for workspaces I think. Agree that it should be a separate PR.

Just thinking that moving param validation related functions to a new file will be a big change for other existing PRs like #4867 #4861 since they are modifying the param validation functions in the original file. How about we move them to the new file after they get merged?

Up to you! I think if you are going to the trouble of making a cleanup PR it's worth putting these functions in the place that makes the most sense (right now this PR is having the pipeline validation use a function defined in task validation which feels a bit strange to me). Rebasing and resolving merge conflicts is sort of a fact of life :) but if you'd prefer to wait that's OK too.

@ywluogg
Copy link
Contributor

ywluogg commented May 26, 2022

/assign ywluogg

@ywluogg
Copy link
Contributor

ywluogg commented May 26, 2022

Up to you! I think if you are going to the trouble of making a cleanup PR it's worth putting these functions in the place that makes the most sense (right now this PR is having the pipeline validation use a function defined in task validation which feels a bit strange to me). Rebasing and resolving merge conflicts is sort of a fact of life :) but if you'd prefer to wait that's OK too.

@chuangw6 maybe change the PR naming to be specifically to "remove duplicate code for validating params types and defaults" to narrow down the cleanup scope. You can create a separate PR for workspaces

@ywluogg
Copy link
Contributor

ywluogg commented May 26, 2022

/lgtm

@tekton-robot
Copy link
Collaborator

@ywluogg: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@chuangw6
Copy link
Member Author

@chuangw6 maybe change the PR naming to be specifically to "remove duplicate code for validating params types and defaults" to narrow down the cleanup scope. You can create a separate PR for workspaces

great point! Done!

@chuangw6 chuangw6 changed the title Replace duplicate code with existing function Remove duplicate code for validating params types and defaults May 26, 2022
@chuangw6 chuangw6 requested a review from lbernick May 27, 2022 17:01
@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 27, 2022
@ywluogg
Copy link
Contributor

ywluogg commented May 31, 2022

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

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

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

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 Jun 2, 2022
@tekton-robot tekton-robot merged commit 6c05f44 into tektoncd:main Jun 2, 2022
@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Jun 21, 2022
@tekton-robot tekton-robot removed the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 21, 2022
@afrittoli
Copy link
Member

/kind misc

@tekton-robot tekton-robot added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Jun 21, 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. kind/misc Categorizes issue or PR as a miscellaneuous one. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants