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

Adding pipeline results #2042

Merged
merged 1 commit into from
Mar 2, 2020
Merged

Conversation

othomann
Copy link
Contributor

@othomann othomann commented Feb 13, 2020

Changes

Adding the ability to reuse task results into other tasks within the same pipeline

Fixes #1978

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

Reviewer Notes

Release Notes

Add pipeline results. This makes it possible to a user to use results from another task as parameters to a task within the same pipeline.

@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Feb 13, 2020
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 13, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@vdemeester
Copy link
Member

/area api
/kind api-change
/assign

@tekton-robot tekton-robot added area/api Indicates an issue or PR that deals with the API. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Feb 13, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@othomann
Copy link
Contributor Author

/retest

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@othomann othomann requested a review from a user February 13, 2020 18:15
@ghost
Copy link

ghost commented Feb 13, 2020

Something that occurs to me reading through this: It looks like we allow the user to only use a single isolated variable substitution in a given parameter. In other words they can't do something like:

params:
- name: ephemeral-env-name
  value: "ci-$(tasks.git-push.results.short-commit-sha)-ephemeral"

Where the expected value here would end up looking something like "ci-991f807-ephemeral" and in this example would be the name of an ephemeral namespace or something that is deployed to when a PR is being tested.

I need to check what variable substitution looks like with other fields. I have a hunch that this kind of thing is supported with others and we'd probably want the same kind of support here as well. Will look into it and update this PR with a comment.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looks good so far! I've left some comments from an initial read-through and I want to get your feedback before I comment on the code any more.

pkg/apis/pipeline/v1alpha2/param_types.go Outdated Show resolved Hide resolved
pkg/reconciler/pipelinerun/pipelinerun.go Outdated Show resolved Hide resolved
@eddie4941
Copy link
Contributor

params:

  • name: ephemeral-env-name
    value: "ci-$(tasks.git-push.results.short-commit-sha)-ephemeral"
    Where the expected value here would end up looking something like "ci-991f807-ephemeral" and > in this example would be the name of an ephemeral namespace or something that is deployed to > when a PR is being tested.

Oh yeah. Didn't think about that. I don't think it would be too hard to implement that behavior. though theres something to think about that is the desired behavior.

Since results are taken verbatim form the contents of the result file that the task lays on disk, we might run into a bunch of issues with newlines when performing the substitutions in embedded cases like the one you mentioned.

In that example, if the task laid down the SHA like so (newline at the end):

f3af3eddd5047d2e7eb795affac54cb6952d22b9\n
"ci-$(tasks.git-push.results.short-commit-sha)-ephemeral"

would turn into

ci-f3af3eddd5047d2e7eb795affac54cb6952d22b9\n-ephemeral

We could strip newline to prevent this, but that might be a bad idea as we likely don't want to alter the users output.

@skaegi
Copy link
Contributor

skaegi commented Feb 13, 2020

@sbwsg I'm trying to rework all the variable substitution right now to use the jsonpath.Expand func from PR #1951 everywhere so that kind of logic isn't reimplemented a zillion times. I just hadn't realized it was such a huge job. @eddie4941 we're so close to the beta that if it's easy to implement in the current way it would be good even if we re-implement a little bit later.
fwiw -- I believe Expand would output...

ci-f3af3eddd5047d2e7eb795affac54cb6952d22b9\n-ephemeral

...as the value of the JSON string which I believe is what we want. Meaning the new line lives on when it's extracted to a regular string. Going the other way that means you don't have to encode the new-line as it is a legitimate String character (DM me if that's confusing as hell)

@ghost
Copy link

ghost commented Feb 14, 2020

I need to check what variable substitution looks like with other fields. I have a hunch that this kind of thing is supported with others

OK, I've run a test this morning to see what happens if you wrap a pipeline's param into a larger string being passed into a Task's param and it looks like it operates as mentioned. The pipeline's param is interpolated into the rest of the string contents. [1]

we might run into a bunch of issues with newlines when performing the substitutions in embedded cases like the one you mentioned.

Great point. I had not thought about newlines being included here. My feeling is we should clearly document the behaviour initially and start considering changes such as trimming the whitespace only if users really struggle with it. My guess right now is that so long as we are passing the result values around verbatim that users will quickly learn to remove extra whitespace from the result values they emit from their tasks. This also sounds like a good thing to watch out for when we start updating tasks in the Catalog to emit their results.

[1] Here's the quick example pipeline I wrote up to check the params behaviour:

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: print-message
spec:
  inputs:
    params:
    - name: message
      type: string
      description: "The message to print"
      default: "hello world"
  steps:
  - name: print
    image: ubuntu
    script: |
      #!/usr/bin/env bash
      echo "$(inputs.params.message)"
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
  name: add-octopus-arms
spec:
  params:
  - name: message
    value: "o.O"
  pipelineSpec:
    params:
    - name: message
      type: string
      description: "The figure to wrap in octopus arms"
    tasks:
    - name: add-octopus-arms
      taskRef:
        name: print-message
      params:
      - name: message
        value: "~~$(params.message)~~"

@ghost
Copy link

ghost commented Feb 14, 2020

This also sounds like a good thing to watch out for when we start updating tasks in the Catalog to emit their results.

Example from a catalog entry of trimming newline when storing to a result here: https://github.com/tektoncd/catalog/pull/182/files#diff-1239eb0a6238e01666691e444b6367b7R55

It would be cool if this were handled for the user but it's not a huuuuge headache as it stands. Just echo -n $FOO > $(results.foo.path)

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.1% -3.6
test/builder/task.go 81.1% 80.4% -0.7

@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 20, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/param_types.go 94.7% 91.3% -3.4
test/builder/task.go 81.1% 80.4% -0.7

@othomann
Copy link
Contributor Author

othomann commented Mar 2, 2020

I am doing a rebase on top of the v1beta1 change. This will require a lgtmtag again once I am done.

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@ghost ghost removed this from the Pipelines 0.11 🐱 milestone Mar 2, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@othomann
Copy link
Contributor Author

othomann commented Mar 2, 2020

/retest

@ghost ghost added this to the Pipelines 0.11 🐱 milestone Mar 2, 2020
@othomann
Copy link
Contributor Author

othomann commented Mar 2, 2020

/test tekton-pipeline-unit-tests

@othomann
Copy link
Contributor Author

othomann commented Mar 2, 2020

unit tests are passing locally, but they fail when run as automated tests. Investigating.

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@othomann
Copy link
Contributor Author

othomann commented Mar 2, 2020

Since the move to v1beta1, the test github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun.TestReconcileWithTaskResults no longer works when run as part of the automated tests, but works perfectly fine locally. If someone has any clue how to debug that, please let me know.

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_types.go 82.4% 76.2% -6.2
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 95.9% 96.2% 0.2
pkg/apis/pipeline/v1beta1/param_types.go 94.7% 34.0% -60.8
test/builder/task.go 70.2% 69.7% -0.5

@othomann
Copy link
Contributor Author

othomann commented Mar 2, 2020

ok problem came from the validation of names. Fix pushed.

@ghost
Copy link

ghost commented Mar 2, 2020

re-adding the earlier lgtm

/lgtm

🤞

@tekton-robot tekton-robot assigned ghost Mar 2, 2020
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 2, 2020
@tekton-robot tekton-robot merged commit c317d64 into tektoncd:master Mar 2, 2020
@ghost
Copy link

ghost commented Mar 2, 2020

🎉

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. area/api Indicates an issue or PR that deals with the API. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged. 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.

Support referencing task results from task params in a pipeline
9 participants