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 matrix support for using references to entire PipelineRun array parameters #6516

Merged

Conversation

EmmaMunley
Copy link
Contributor

@EmmaMunley EmmaMunley commented Apr 10, 2023

Changes

This PR adds support for using whole array PipelineRun parameters as matrix parameter values by moving the validation for checking matrix parameter types to after parameter substitution. This is necessary for allowing whole array substitutions using the syntax $(params.foo[*]), rather than an explicit YAML array, to be used as a matrix parameter. Prior to this, validation fails because a string referencing an array type was considered a string type and this was done before the applying array replacements.

Note: Whole array replacements for matrix results has not yet been implemented and will be added in a subsequent PR.

This issue is described in more detail here: #6056 (comment)

Thanks to @abayer for investigating and co-authoring this PR: #6056 😄

/kind feature

Submitter Checklist

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

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • 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

NONE

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 10, 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 99.1% 98.7% -0.4
pkg/apis/pipeline/v1beta1/param_types.go 99.1% 98.6% -0.4

@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 99.1% 98.7% -0.4
pkg/apis/pipeline/v1beta1/param_types.go 99.1% 98.6% -0.4

@EmmaMunley
Copy link
Contributor Author

/assign @jerop @lbernick

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 4c342f5 to 1aa7a91 Compare April 11, 2023 15:51
@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/pipelinerun.go 89.4% 89.0% -0.4

@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/pipelinerun.go 89.4% 89.0% -0.4

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 1aa7a91 to 2d869cc Compare April 11, 2023 16:05
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 11, 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/pipelinerun.go 89.4% 89.0% -0.4

@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/pipelinerun.go 89.4% 89.0% -0.4

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 2d869cc to 3028b72 Compare April 11, 2023 16: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/reconciler/pipelinerun/pipelinerun.go 89.4% 89.0% -0.4

@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/pipelinerun.go 89.4% 89.0% -0.4

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 3028b72 to 4086e94 Compare April 13, 2023 15:29
@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/pipelinerun.go 89.3% 88.9% -0.4

@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/pipelinerun.go 89.3% 88.9% -0.4

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 4086e94 to 7dedfc6 Compare April 13, 2023 16:00
@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/pipelinerun.go 89.3% 88.9% -0.4

@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/pipelinerun.go 89.3% 88.9% -0.4

@EmmaMunley
Copy link
Contributor Author

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

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from c8b2634 to 2be3808 Compare April 28, 2023 14:42
@EmmaMunley EmmaMunley changed the title Add support for using PipelineRun parameters as matrix parameter values Add matrix support for using references to entire PipelineRun array parameters Apr 28, 2023
@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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.1

@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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.1

@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 2be3808 to 3c25384 Compare April 28, 2023 14:56
@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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.1

pkg/apis/pipeline/v1/pipeline_types_test.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1/pipeline_types_test.go Outdated Show resolved Hide resolved
echo "$(params.platform) and $(params.browser)"
`)

expectedTaskRuns := []*v1beta1.TaskRun{
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could use for loop to create the expectedTaskRuns to reduce the size of the test code? The difference between each case seem to be the params, we could use %s in the mustParseTaskRunWithObjectMeta to pass the params?
e.g.

expectedTaskRun := mustParseTaskRunWithObjectMeta(t,

Copy link
Member

Choose a reason for hiding this comment

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

We could ignore this comment in this PR, I just feel like it would be helpful if we could clean up it.
The suggestion in my mind is something like:

 data := []struct {
        name     string
        browser  string
        platform string
    }{{
        name:     "pr-platforms-and-browsers-0",
        browser:  "chrome",
        platform: "linux",
    }, {
        name:     "pr-platforms-and-browsers-1",
        browser:  "chrome",
        platform: "mac",
    }}
    expectedTaskRuns := []*v1beta1.TaskRun{}
    for _, d := range data {
        expectedTaskRuns1 = append(expectedTaskRuns,

            mustParseTaskRunWithObjectMeta(t,
                taskRunObjectMeta(d.name, "foo",
                    "pr", "p-dag", "platforms-and-browsers", false),
                fmt.Sprintf(`
            spec:
            params:
            - name: browser
                value: %s
            - name: platform
                value: %s
            serviceAccountName: test-sa
            taskRef:
                name: mytask
                kind: Task
            labels:
                tekton.dev/memberOf: tasks
                tekton.dev/pipeline: p-dag
            `, d.browser, d.platform)),
        )
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @Yongxuanzhang. I updated this here and think in the future we could refactor all of the tests to use this and perhaps make a createExpectedTaskRuns() function that can abstract some of this even more from a mapping of parameter names and values.

I also think there's opportunity to create more variables (pr name, namespace, pipelineTaskName, etc that can be passed between the specs to avoid some of the manual errors and pain points around formatting the yaml syntax.

cc: @jerop @lbernick

…arameters

This commit adds support for using whole array PipelineRun parameters as matrix parameter values by moving the validation for checking matrix parameter types to after parameter substitution. This is necessary for allowing whole array substitutions using the syntax $(params.foo[*]), rather than an explicit YAML array, to be used as a matrix parameter. Prior to this, validation fails because a string referencing an array type was considered a string type and this was done before the applying array replacements.
Note: Whole array replacements for matrix results has not yet been implemented and will be added in a subsequent PR.
This issue is described in more detail here: tektoncd#6056
@EmmaMunley EmmaMunley force-pushed the validation-matrix-pipeline-parameters branch from 3c25384 to e555157 Compare April 28, 2023 16:44
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 28, 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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.1

Copy link
Member

@Yongxuanzhang Yongxuanzhang 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 Apr 28, 2023
@EmmaMunley
Copy link
Contributor Author

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

@lbernick
Copy link
Member

This is a known flake: #4567

@EmmaMunley
Copy link
Contributor Author

/test pull-tekton-pipeline-go-coverage-df

@tekton-robot
Copy link
Collaborator

@EmmaMunley: 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-beta-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

Use /test all to run all jobs.

In response to this:

/test pull-tekton-pipeline-go-coverage-df

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.

@EmmaMunley
Copy link
Contributor Author

/test pull-tekton-pipeline-go-coverage

@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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 89.1% 89.2% 0.1

@tekton-robot tekton-robot merged commit 3d6ec63 into tektoncd:main Apr 28, 2023
@EmmaMunley EmmaMunley deleted the validation-matrix-pipeline-parameters branch April 28, 2023 19:12
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/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants