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

Implement implicit parameter resolution. #4127

Merged
merged 1 commit into from
Sep 15, 2021

Conversation

wlynch
Copy link
Member

@wlynch wlynch commented Jul 29, 2021

Changes

This is the implementation of
TEP-0023.

This adds information to the defaulting context to allow parameters to
be passed down the stack during evaluation. This functionality is gated
behind the alpha feature flag.

Additionally, Tasks are now allowed to accept more params than are
actually used. This should generally be safe, since extra params that
are provided should not affect the behavior of the Task itself.

/kind feature

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 or deleted (only if no user facing changes)

Release Notes

- Tasks can now accept more parameters than are actually used.
- Parameters can now be implicitly propagated to inlined specs (alpha feature flag must be enabled) -
  e.g. an inlined Task can access parameters of its parent PipelineRun without
  needing to explicitly define each param.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Jul 29, 2021
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 29, 2021
@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/v1alpha1/param_context.go Do not exist 85.2%
pkg/apis/pipeline/v1alpha1/pipeline_defaults.go 0.0% 69.2% 69.2
pkg/apis/pipeline/v1alpha1/pipelinerun_defaults.go 91.7% 100.0% 8.3
pkg/apis/pipeline/v1alpha1/task_defaults.go 53.8% 60.0% 6.2
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.3% -1.7

@wlynch
Copy link
Member Author

wlynch commented Jul 29, 2021

/hold

Looks like I missed some tests

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 29, 2021
@wlynch wlynch force-pushed the default-params-v1alpha1 branch from ab7c870 to 2edf64f Compare July 29, 2021 19: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/v1alpha1/param_context.go Do not exist 85.2%
pkg/apis/pipeline/v1alpha1/pipeline_defaults.go 0.0% 69.2% 69.2
pkg/apis/pipeline/v1alpha1/pipelinerun_defaults.go 91.7% 100.0% 8.3
pkg/apis/pipeline/v1alpha1/task_defaults.go 53.8% 60.0% 6.2
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.3% -1.7

@wlynch
Copy link
Member Author

wlynch commented Jul 29, 2021

/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 Jul 29, 2021
@vdemeester
Copy link
Member

/assign

available to any inlined specs without needing to be explicitly defined.

```yaml
apiVersion: tekton.dev/v1alpha1
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like this functionality is being marked alpha by adding it only to the alpha type - thats a different approach than we've taken via TEP-0033 - the approach we're favoring is to us enable-api-fields: alpha to gate functionality like this - this is a controller setting though so if this is implemented in the webhook, maybe we need to either port that flag over to the webhook, or let the webhook read that value from the same configmap as the controller? probably doesnt make sense to need to configure it twice... TEP-0033 could use an update to include the webhook, though it does say:

Since the API fields will exist in the CRD with or without the flags, this will be enforced at runtime by the webhook admission controller: if the flag is not enabled and a user tries to use an alpha field, the webhook will not allow the CRD to be stored and will return an actionable error. (Same for beta.)

which feels like it implies that the webhook should be aware of this configuration

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm - the TEP also says:

Use of alpha CRDs would not require enable-api-fields to be set, neither would beta, i.e. enable-api-fields only gates access to fields within CRDs, not to CRDs themselves.

It feels strange to require enabled-api-fields: alpha if you're already explicitly using the v1alpha1 API, though I think it does make sense to require this for any alpha fields in the v1beta that we can't easily separate out. I'm trying to avoid v1beta1 to avoid any deprecation policy concerns while we're trying this out. wdyt?

It makes sense to gate the loosened param constraints in the reconciler behind this flag though - I'll add this!

@pritidesai pritidesai added this to the Pipelines v0.28 milestone Aug 11, 2021
@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/v1alpha1/param_context.go Do not exist 85.2%
pkg/apis/pipeline/v1alpha1/pipeline_defaults.go 0.0% 69.2% 69.2
pkg/apis/pipeline/v1alpha1/pipelinerun_defaults.go 91.7% 100.0% 8.3
pkg/apis/pipeline/v1alpha1/task_defaults.go 53.8% 60.0% 6.2
pkg/reconciler/taskrun/validate_resources.go 95.1% 95.3% 0.2

@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/v1alpha1/param_context.go Do not exist 85.2%
pkg/apis/pipeline/v1alpha1/pipeline_defaults.go 0.0% 69.2% 69.2
pkg/apis/pipeline/v1alpha1/pipelinerun_defaults.go 91.7% 100.0% 8.3
pkg/apis/pipeline/v1alpha1/task_defaults.go 53.8% 60.0% 6.2
pkg/reconciler/taskrun/validate_resources.go 95.1% 95.3% 0.2

@wlynch
Copy link
Member Author

wlynch commented Aug 11, 2021

/test pull-tekton-pipeline-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/v1alpha1/param_context.go Do not exist 85.2%
pkg/apis/pipeline/v1alpha1/pipeline_defaults.go 0.0% 69.2% 69.2
pkg/apis/pipeline/v1alpha1/pipelinerun_defaults.go 91.7% 100.0% 8.3
pkg/apis/pipeline/v1alpha1/task_defaults.go 53.8% 60.0% 6.2
pkg/reconciler/taskrun/validate_resources.go 95.1% 95.3% 0.2

@wlynch
Copy link
Member Author

wlynch commented Aug 11, 2021

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

@wlynch
Copy link
Member Author

wlynch commented Aug 11, 2021

/hold

Talked a bit off thread about this - seems like this should have been added to v1beta1 instead, relying on the alpha flag to enable the functionality. Will update.

@tekton-robot tekton-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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 Aug 11, 2021
@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_context.go Do not exist 69.0%
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch wlynch force-pushed the default-params-v1alpha1 branch from bb79f3b to a3d8230 Compare August 12, 2021 18: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_context.go Do not exist 69.0%
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@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_context.go Do not exist 69.0%
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch wlynch force-pushed the default-params-v1alpha1 branch from c391337 to c5ae153 Compare August 12, 2021 19:19
@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_context.go Do not exist 98.3%
pkg/apis/pipeline/v1beta1/pipeline_defaults.go 100.0% 92.3% -7.7
pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go 92.3% 93.3% 1.0
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch
Copy link
Member Author

wlynch commented Aug 31, 2021

/test pull-tekton-pipeline-integration-tests

docs/pipelineruns.md Outdated Show resolved Hide resolved
docs/taskruns.md Outdated Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 31, 2021
@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_context.go Do not exist 98.3%
pkg/apis/pipeline/v1beta1/pipeline_defaults.go 100.0% 92.3% -7.7
pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go 92.3% 93.3% 1.0
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch
Copy link
Member Author

wlynch commented Sep 13, 2021

ping for review!

@pritidesai
Copy link
Member

thanks @wlynch for this, looking forward to this feature 😍 This will simplify the resource definitions a whole lot.

I have started to review this PR. In meanwhile, can you please update the PR description and release notes to exclude v1alpha1 API and include the feature flag enable-api-alpha set to alpha. Also will be great if you squash all the commits 🙏

@wlynch wlynch force-pushed the default-params-v1alpha1 branch from 4fd0098 to ec97e05 Compare September 14, 2021 17:47
@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_context.go Do not exist 98.3%
pkg/apis/pipeline/v1beta1/pipeline_defaults.go 100.0% 92.3% -7.7
pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go 92.3% 93.3% 1.0
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch
Copy link
Member Author

wlynch commented Sep 14, 2021

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

@pritidesai
Copy link
Member

pritidesai commented Sep 14, 2021

I ran a pipeline with one parameter GREETINGS. And the pipeline has one pipelineTask with one parameter MESSAGE. The parameter in the pipelineTask is explicitly mapped to the parameter in the pipeline:

       params:
          - name: MESSAGE
            value: $(params.GREETINGS)

Without these changes, the resolved pipelineSpec includes this mapping in the pipelineTask:

spec:
  pipelineSpec:
    params:
    - default: Hello World!
      description: Greetings, default is Hello World!
      name: GREETINGS
      type: string
    tasks:
    - name: echo-greetings
      params:
      - name: MESSAGE
        value: $(params.GREETINGS)
      taskSpec:

With these changes, in addition to the explicit mapping, the resolved spec includes an additional implicit mapping along with the pipeline parameter listed as pipelineTask and task parameter. GREETINGS was not listed as the parameter of any task.

spec:
  pipelineSpec:
    params:
    - default: Hello World!
      description: Greetings, default is Hello World!
      name: GREETINGS
      type: string
    tasks:
    - name: echo-greetings
      params:
      - name: MESSAGE
        value: $(params.GREETINGS)
      - name: GREETINGS
        value: $(params.GREETINGS)
      taskSpec:

I am not sure if this can cause any conflicts but I think we can atleast document this behavior. Wdyt? I have the entire pipelineRun and resolved specification documented here for your reference..

EDIT: This could potentially explode the list of parameters in each pipelineTask and task. I am sure there must be a way to avoid this, looking into it.

@wlynch wlynch force-pushed the default-params-v1alpha1 branch from ec97e05 to 78969ca Compare September 15, 2021 16: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/apis/pipeline/v1beta1/param_context.go Do not exist 98.3%
pkg/apis/pipeline/v1beta1/pipeline_defaults.go 100.0% 92.3% -7.7
pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go 92.3% 93.3% 1.0
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch
Copy link
Member Author

wlynch commented Sep 15, 2021

I ran a pipeline with one parameter GREETINGS. And the pipeline has one pipelineTask with one parameter MESSAGE. The parameter in the pipelineTask is explicitly mapped to the parameter in the pipeline:

I am not sure if this can cause any conflicts but I think we can atleast document this behavior. Wdyt? I have the entire pipelineRun and resolved specification documented here for your reference..

EDIT: This could potentially explode the list of parameters in each pipelineTask and task. I am sure there must be a way to avoid this, looking into it.

Copying my respond from Slack here (with minor edits) - I think this is WAI (at least for now). you would need it to cover weird edge cases like this:

apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  generateName: echo-
spec:
  params:
    - name: MESSAGE1
      value: "Good Morning!" 
  pipelineSpec:
    params:
    - name: MESSAGE2
      default: Hello World!
    tasks:
      - name: echo-message
        params:
          - name: MESSAGE3
            value: $(params.MESSAGE2)
        taskSpec:
          steps:
            - name: echo
              image: ubuntu
              script: |
                #!/usr/bin/env bash
                echo "$(params.MESSAGE1)" "$(params.MESSAGE2)" "$(params.MESSAGE3)"

This behavior seems to be most consistent with what we're trying to go for. e.g. if I was to write something similar in Go it would look like -

a := "Good Morning!"
func() {
  b := "Hello World!"
  func(c string) {
    fmt.Println(a, b, c)
  }(b)
}()

The params available always needs to be a union of the other parameters in the context, since we don't know which will be used. The verboseness of the output config is a consequence of us returning the fully resolved parameter context so it's clear which params reached the Task. It shouldn't cause conflicts - params defined lower in the stack should always take precedence, and unused parameters shouldn't modify behavior since they aren't used. I suppose there is a small concern around complex pipelines hitting etcd limits, but the work around there would be to stop inlining everything and break things into discrete Tasks.

Alternatives I can think of:

  • do some more complex matching (e.g. only set things that are used) - but this is tricky because we don’t actually know the params that are used until we evaluate them (which happens post-webhook on reconcile). This would require either more complex param validation upfront, or we accept the implicit config as-is and handle the resolution later.
  • we remove the mutating defaulting behavior and store the implicit configs as-is. The configs will look more concise to users, and the parameter context mucking would only be visible to the reconciler. I wasn’t sure what impact this would have on current webhook validation, so I avoided this for the time being.

The alternatives make me think a reasonable next step would be to look into accepting the implicit configs as-is, and see what impact this would have on the current parameter validation (and also get feedback if not including the fully resolved spec would make debugging harder). My preference would be to tackle this in another change/PR.

Let me know what you think!

This is the implementation of
[TEP-0023](https://github.com/tektoncd/community/blob/main/teps/0023-implicit-mapping.md).

This adds information to the defaulting context to allow parameters to
be passed down the stack during evaluation. This functionality is gated
behind the alpha feature flag.

Additionally, Tasks are now allowed to accept more params than are
actually used. This should generally be safe, since extra params that
are provided should not affect the behavior of the Task itself.
@wlynch wlynch force-pushed the default-params-v1alpha1 branch from 78969ca to eeebe24 Compare September 15, 2021 17:10
@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_context.go Do not exist 98.3%
pkg/apis/pipeline/v1beta1/pipeline_defaults.go 100.0% 92.3% -7.7
pkg/apis/pipeline/v1beta1/pipelinerun_defaults.go 92.3% 93.3% 1.0
pkg/apis/pipeline/v1beta1/task_defaults.go 66.7% 83.3% 16.7
pkg/reconciler/taskrun/validate_resources.go 95.1% 93.8% -1.3

@wlynch
Copy link
Member Author

wlynch commented Sep 15, 2021

/test pull-tekton-pipeline-integration-tests

Note that all implicit Parameters will be passed through to inlined resources
(i.e. PipelineRun -> Pipeline -> Tasks) even if they are not used.
Extra parameters passed this way should generally be safe (since they aren't
actually used), but may result in more verbose specs being returned by the API.
Copy link
Member

Choose a reason for hiding this comment

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

thanks a bunch @wlynch for adding this note 🙏

@pritidesai
Copy link
Member

pritidesai commented Sep 15, 2021

thanks a bunch @wlynch

The alternatives make me think a reasonable next step would be to look into accepting the implicit configs as-is, and see what impact this would have on the current parameter validation (and also get feedback if not including the fully resolved spec would make debugging harder). My preference would be to tackle this in another change/PR.

Let me know what you think!

Yup, we can certainly tackle this in a follow up PR. My major concern is exploding the size of the pipelineRun status, especially for complex pipelines with a huge number of tasks and each task having a huge number of parameters.

/lgtm

🤞 for the integration tests

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 15, 2021
@wlynch
Copy link
Member Author

wlynch commented Sep 15, 2021

/test pull-tekton-pipeline-integration-tests

@wlynch
Copy link
Member Author

wlynch commented Sep 15, 2021

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

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 Denotes a PR that will be considered when it comes time to generate release notes. 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