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

TEP-0075: Validate Pipeline object variables in value, matrix and when #4902

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

chuangw6
Copy link
Member

@chuangw6 chuangw6 commented May 24, 2022

Changes

Besides task steps, parameter variables can be used as the value of
another param, matrix or when expression.

  • Allowed referencing the whole object value but added validation to make sure it can only be used when providing values
    for other object param. example:
 	params:
 	- name: arg
           value: $(params.myObject[*])
  • In all other cases (string/array val, matrix and when expression), only individual object attributes can be referenced i.e. $(params.myobject.key1).

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

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 24, 2022
@tekton-robot tekton-robot requested review from jerop and vdemeester May 24, 2022 00:52
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 24, 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/param_types.go 96.9% 95.2% -1.7

@chuangw6 chuangw6 force-pushed the param-variable-validation branch from 099f6ac to ec33611 Compare May 24, 2022 01: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/param_types.go 96.9% 97.4% 0.6

@chuangw6 chuangw6 marked this pull request as draft May 24, 2022 01:33
@chuangw6 chuangw6 force-pushed the param-variable-validation branch from ec33611 to 1fb40aa Compare May 24, 2022 02: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/apis/pipeline/v1beta1/param_types.go 96.9% 97.4% 0.6

@chuangw6 chuangw6 force-pushed the param-variable-validation branch from 1fb40aa to d667c5c Compare June 15, 2022 19:25
@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 97.4% 97.8% 0.4

@chuangw6 chuangw6 force-pushed the param-variable-validation branch 2 times, most recently from d47bf45 to 46f5e8c Compare June 16, 2022 20:42
@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 97.4% 97.8% 0.4

@chuangw6 chuangw6 marked this pull request as ready for review June 21, 2022 15:02
@chuangw6
Copy link
Member Author

/assign @ywluogg
/assign @dibyom

@tekton-robot
Copy link
Collaborator

@chuangw6: GitHub didn't allow me to assign the following users: ywluogg.

Note that only tektoncd members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @ywluogg
/assign @dibyom

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.

@ywluogg
Copy link
Contributor

ywluogg commented Jul 6, 2022

#4723

Copy link
Contributor

@ywluogg ywluogg left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, can you explain a bit for matrix that webhook validation works for referencing object / params as a whole, but they are actually not supported

@ywluogg
Copy link
Contributor

ywluogg commented Jul 7, 2022

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2022
@chuangw6
Copy link
Member Author

chuangw6 commented Jul 8, 2022

/kind misc

@tekton-robot tekton-robot added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Jul 8, 2022
@chuangw6
Copy link
Member Author

chuangw6 commented Jul 8, 2022

Mostly LGTM, can you explain a bit for matrix that webhook validation works for referencing object / params as a whole, but they are actually not supported

Chatted with @ywluogg offline.
It is implemented in this pr. If an individual element of an array param uses a reference to object param, it is invalid and will be checked by the validateArrayVariable here.

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.

Could you please update your commit message to make it more clear what is changing as a result of your PR? e.g. "Add validation for usage of parameter variables in Pipeline parameters, matrixes, and when expressions. Valid usage includes.... Invalid usage includes...."

pkg/apis/pipeline/v1beta1/param_types.go Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/param_types.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/param_types.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/param_types.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/pipeline_validation_test.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/param_types.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/param_types.go Outdated Show resolved Hide resolved
@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 97.9% 97.3% -0.5

@chuangw6 chuangw6 force-pushed the param-variable-validation branch from 5f31d26 to a630923 Compare July 11, 2022 19:27
@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 97.9% 97.3% -0.5

@chuangw6 chuangw6 force-pushed the param-variable-validation branch from a630923 to 83bccd0 Compare July 11, 2022 19:44
@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 97.9% 97.3% -0.5

pkg/apis/pipeline/v1beta1/param_types.go Show resolved Hide resolved
parameterSubstitution = `.*?(\[\*\])?`

// BraceMatchingRegex is a regex for parameter references including dot notation, bracket notation with single and double quotes.
BraceMatchingRegex = "(\\$(\\(%s(\\.(?P<var1>%s)|\\[\"(?P<var2>%s)\"\\]|\\['(?P<var3>%s)'\\])\\)))"
Copy link
Member

Choose a reason for hiding this comment

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

could you avoid exporting this, and instead create an exported helper function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

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 purpose of this package is to validate and parse parameters (it's hard to tell haha-- substitution is a bit messy), so the reason I suggest writing a helper function is to think about what validation and parsing can be abstracted away. The functions exported by a package form a sort of API that other packages can use. Imagine if you encountered an API with this getter function-- I think it would be confusing. This is where a package just for params would be really helpful! Since we don't have that, could you try to write a helper function that's consistent with what the substitution package is designed for? I am hoping to avoid the use of regexes in many places in the codebase because they are very hard to understand.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you @lbernick for the explanation. That makes sense to me! Done.

@chuangw6 chuangw6 force-pushed the param-variable-validation branch from 83bccd0 to 7277716 Compare July 11, 2022 21:46
@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 97.9% 97.3% -0.5
pkg/substitution/substitution.go 64.9% 64.3% -0.6

@chuangw6
Copy link
Member Author

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

@chuangw6 chuangw6 force-pushed the param-variable-validation branch 2 times, most recently from deebc5b to 229ee8b Compare July 11, 2022 23:30
Besides task steps, Parameter variables can be used as the value of
a param, matrix or when expression.

Those validations regarding object type are added:
- The whole object value can only be used when providing values
for other object param. example:
```
params:
- name: arg
  value: $(params.myObject[*])
```
- Individual object attributes should be used in all other cases
(string/array val, matrix and when expression).
@chuangw6 chuangw6 force-pushed the param-variable-validation branch from 229ee8b to 4525854 Compare July 11, 2022 23:31
@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 97.9% 98.2% 0.3
pkg/substitution/substitution.go 64.9% 60.7% -4.3

@lbernick
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2022
@chuangw6
Copy link
Member Author

/test pull-tekton-pipeline-build-tests

@chuangw6 chuangw6 closed this Jul 12, 2022
@chuangw6 chuangw6 reopened this Jul 12, 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/param_types.go 97.9% 98.2% 0.3
pkg/substitution/substitution.go 64.9% 60.7% -4.3

@chuangw6
Copy link
Member Author

/test pull-pipeline-kind-k8s-v1-21-e2e

@tekton-robot
Copy link
Collaborator

@chuangw6: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-tekton-pipeline-alpha-integration-tests
  • /test pull-tekton-pipeline-build-tests
  • /test pull-tekton-pipeline-integration-tests
  • /test tekton-pipeline-unit-tests

The following commands are available to trigger optional jobs:

  • /test pull-tekton-pipeline-go-coverage
  • /test pull-tekton-pipeline-kind-alpha-integration-tests
  • /test pull-tekton-pipeline-kind-alpha-yaml-tests
  • /test pull-tekton-pipeline-kind-integration-tests
  • /test pull-tekton-pipeline-kind-yaml-tests

Use /test all to run the following jobs that were automatically triggered:

  • pull-tekton-pipeline-alpha-integration-tests
  • pull-tekton-pipeline-build-tests
  • pull-tekton-pipeline-go-coverage
  • pull-tekton-pipeline-integration-tests
  • pull-tekton-pipeline-unit-tests

In response to this:

/test pull-pipeline-kind-k8s-v1-21-e2e

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 chuangw6 closed this Jul 12, 2022
@chuangw6 chuangw6 reopened this Jul 12, 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/param_types.go 97.9% 98.2% 0.3
pkg/substitution/substitution.go 64.9% 60.7% -4.3

@chuangw6
Copy link
Member Author

/test pull-pipeline-kind-k8s-v1-21-e2e

@tekton-robot
Copy link
Collaborator

@chuangw6: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-tekton-pipeline-alpha-integration-tests
  • /test pull-tekton-pipeline-build-tests
  • /test pull-tekton-pipeline-integration-tests
  • /test tekton-pipeline-unit-tests

The following commands are available to trigger optional jobs:

  • /test pull-tekton-pipeline-go-coverage
  • /test pull-tekton-pipeline-kind-alpha-integration-tests
  • /test pull-tekton-pipeline-kind-alpha-yaml-tests
  • /test pull-tekton-pipeline-kind-integration-tests
  • /test pull-tekton-pipeline-kind-yaml-tests

Use /test all to run the following jobs that were automatically triggered:

  • pull-tekton-pipeline-alpha-integration-tests
  • pull-tekton-pipeline-build-tests
  • pull-tekton-pipeline-go-coverage
  • pull-tekton-pipeline-integration-tests
  • pull-tekton-pipeline-unit-tests

In response to this:

/test pull-pipeline-kind-k8s-v1-21-e2e

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.

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants