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

change param array indexing validation functions to member functions #6180

Merged

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Feb 16, 2023

Changes

This commit refactors param array indexing validation to extract all
references first, then validate if references are out of bound.
Previously we traverse all references and collect invalid references
there. The benefit of this refactoring is that it would be convenient
for other validation to reuse these references.
This commit also moves validation functions into api and change them to
member functions.

/kind misc

Signed-off-by: Yongxuan Zhang [email protected]

Submitter Checklist

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

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Make ValidateParamArrayIndex as member functions for TaskSpec and PipelineSpec
Change []ParamSpec to ParamSpecs and []Param to Params 

@tekton-robot tekton-robot added kind/misc Categorizes issue or PR as a miscellaneuous one. release-note-none Denotes a PR that doesnt merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 16, 2023
@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/reconciler/pipelinerun/resources/validate_params.go 96.2% 94.4% -1.7
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 94.4% -1.7
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from 47dda5e to e838c52 Compare February 16, 2023 03:36
@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/reconciler/pipelinerun/resources/validate_params.go 96.2% 94.4% -1.7
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from e838c52 to b2de238 Compare February 16, 2023 03:43
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 94.4% -1.7
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@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/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 16, 2023
@XinruZhang
Copy link
Member

/assign

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 16, 2023
Copy link
Member

@XinruZhang XinruZhang left a comment

Choose a reason for hiding this comment

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

Thank you for splitting the PR into pieces, I'm trying to rename those funcs to make them easier to read. Please take a look.

Please note: arrayParamLength seems useless for all funcs retrieving the indexing param references.

I tried to remove them all but I never run the code I modified so please double check :)


Learning how to make multi-lines suggestions 🙃

As a workaround, please refer to https://github.com/tektoncd/pipeline/compare/main...XinruZhang:pipeline:refactor-suggestion?expand=1

@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from b2de238 to d03fc5e Compare February 16, 2023 18:41
@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/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@Yongxuanzhang
Copy link
Member Author

Thank you for splitting the PR into pieces, I'm trying to rename those funcs to make them easier to read. Please take a look.

Please note: arrayParamLength seems useless for all funcs retrieving the indexing param references.

I tried to remove them all but I never run the code I modified so please double check :)

Learning how to make multi-lines suggestions 🙃

As a workaround, please refer to https://github.com/tektoncd/pipeline/compare/main...XinruZhang:pipeline:refactor-suggestion?expand=1

Thanks a lot! Really helpful!

return nil
}

func extractParamIndex(paramReference string, arrayParams map[string]int, outofBoundParams *sets.String) {
// ExtractArrayIndexingParamRefs extract the array indexing references
func ExtractArrayIndexingParamRefs(paramReference string, arrayParams map[string]int, arrayIndexingParams *[]string) {
Copy link
Member

@XinruZhang XinruZhang Feb 16, 2023

Choose a reason for hiding this comment

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

"arrayParams" is not used in this function right? as well as other extractArrayIndexingRefs*()

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I missed this one. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it from all the functions used

Copy link
Member

Choose a reason for hiding this comment

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

Thank you! @Yongxuanzhang

@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from d03fc5e to 51cf8fb Compare February 16, 2023 20:09

// ValidateOutofBoundArrayParams validates if the array indexing params are out of bound
func ValidateOutofBoundArrayParams(arrayIndexingParams []string, arrayParams map[string]int) error {
Copy link
Member

Choose a reason for hiding this comment

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

I'm nitpicking but changing arrayParams to arrayParamsLengths can be clearer.

@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/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from 51cf8fb to 214c202 Compare February 16, 2023 20:16
@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/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 98.1% 2.0
pkg/reconciler/taskrun/validate_resources.go 98.5% 98.6% 0.0

@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 2, 2023
@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/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 98.5% -1.1
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.1% -0.2

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 98.5% -1.1
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.1% -0.2

@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from 8ee5a41 to 978c017 Compare March 2, 2023 17:39
@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/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 98.5% -1.1
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.1% -0.2
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 100.0% 3.8
pkg/reconciler/taskrun/validate_resources.go 98.2% 97.0% -1.1

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 98.5% -1.1
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.1% -0.2
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 100.0% 3.8
pkg/reconciler/taskrun/validate_resources.go 98.2% 97.0% -1.1

This commit refactors param array indexing validation to extract all
references first, then validate if references are out of bound.
Previously we traverse all references and collect invalid references
there. The benefit of this refactoring is that it would be convenient
for other validation to reuse these references.
This commit also moves validation functions into api and change them to
member functions.

Signed-off-by: Yongxuan Zhang [email protected]
@Yongxuanzhang Yongxuanzhang force-pushed the refactor-array-indexing-validation branch from 978c017 to 47343d4 Compare March 2, 2023 18:48
@Yongxuanzhang Yongxuanzhang changed the title refactor param array indexing validation change param array indexing validation functions to member functions Mar 2, 2023
@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/v1/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1/pipeline_validation.go 99.5% 98.1% -1.4
pkg/apis/pipeline/v1/task_validation.go 97.1% 96.9% -0.2
pkg/apis/pipeline/v1beta1/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 98.5% -1.1
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.1% -0.2
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 100.0% 3.8
pkg/reconciler/taskrun/validate_resources.go 98.2% 97.0% -1.1

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1/pipeline_validation.go 99.5% 98.1% -1.4
pkg/apis/pipeline/v1/task_validation.go 97.1% 96.9% -0.2
pkg/apis/pipeline/v1beta1/param_types.go 98.3% 99.1% 0.8
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 98.5% -1.1
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.1% -0.2
pkg/reconciler/pipelinerun/resources/validate_params.go 96.2% 100.0% 3.8
pkg/reconciler/taskrun/validate_resources.go 98.2% 97.0% -1.1

@Yongxuanzhang
Copy link
Member Author

Yongxuanzhang commented Mar 2, 2023

Note that the coverage drop of pipeline_validation.go and task_validation.go is due to previous uncovered cases. We should add them in a separate PR.
The drop of validate_resources.go is because we move the functions into api, the lines of code is reduced

arrayParamsLengths := ts.Params.extractParamArrayLengths()
for k, v := range params.extractParamArrayLengths() {
arrayParamsLengths[k] = v
}
Copy link
Member

Choose a reason for hiding this comment

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

NIT: much cleaner with maps.Copy(dest, source) 😄

https://pkg.go.dev/golang.org/x/exp/maps#Copy

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I didn't use it because we don't import that in the code base and I try to avoid changes like that

@pritidesai
Copy link
Member

Note that the coverage drop of pipeline_validation.go and task_validation.go is due to previous uncovered cases. We should add them in a separate PR. The drop of validate_resources.go is because we move the functions into api, the lines of code is reduced

Thank you @Yongxuanzhang, do you mind tracking it in a issue so that its not forgotten?

/lgtm

/cancel hold

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 2, 2023
@pritidesai
Copy link
Member

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 2, 2023
@tekton-robot tekton-robot merged commit 67abc4a into tektoncd:main Mar 2, 2023
@Yongxuanzhang
Copy link
Member Author

Note that the coverage drop of pipeline_validation.go and task_validation.go is due to previous uncovered cases. We should add them in a separate PR. The drop of validate_resources.go is because we move the functions into api, the lines of code is reduced

Thank you @Yongxuanzhang, do you mind tracking it in a issue so that its not forgotten?

/lgtm

/cancel hold

Sure! Just opened one and will open a PR soon!
#6278

@pritidesai
Copy link
Member

@Yongxuanzhang please update release notes to include the type change []ParamSpec to ParamSpecs and []Param to Params, thanks!

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesnt merit a release note. labels Mar 2, 2023
@Yongxuanzhang
Copy link
Member Author

@Yongxuanzhang please update release notes to include the type change []ParamSpec to ParamSpecs and []Param to Params, thanks!

Oh thanks! I thought I have updated it but I didn't 😞 .

EmmaMunley added a commit to EmmaMunley/pipeline that referenced this pull request Mar 29, 2023
This commit updates []Param to the new Params type everywhere in the code base. This is a follow up to PR tektoncd#6180 where the type type Params []Param was introduced to allow member functions.
EmmaMunley added a commit to EmmaMunley/pipeline that referenced this pull request Mar 29, 2023
This commit updates []Param to the new Params type everywhere in the code base. This is a follow up to PR tektoncd#6180 where the type type Params []Param was introduced to allow member functions.
This change will make it easier to make changes related to the type.
tekton-robot pushed a commit that referenced this pull request Mar 30, 2023
This commit updates []Param to the new Params type everywhere in the code base. This is a follow up to PR #6180 where the type type Params []Param was introduced to allow member functions.
This change will make it easier to make changes related to the type.
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 Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants