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 variable substitution for resource paths #877

Merged
merged 6 commits into from
May 29, 2019

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented May 17, 2019

Changes

This PR adds the ability to substitute resource paths on disk using template variables e.g. ${inputs/outputs.resources.myresource.path}. Prior to this, users would have to hardcode the paths
(e.g. /workspace/myresource).

In order to add this feature, we had to do some refactoring in order to reuse PipelineResourceInterface s when creating pods. Each resource processing step (e.g. adding input/output resources,
applying templating) would create its own PipelineResourceInterface. This is a problem since the interface uses a setter(SetDestinationDirectory) that would not always be called. The destination directory is required to be set in order to facilitate variable substitution for resource paths.

The first commit refactors the resource initialization process by creating a binding between the named resource and the interface implementation and passing it around instead of creating new PipelineResourceInterfaceeach time.

Marking this as a WIP until I:

  • Add tests for output resources
  • Update the docs and examples

This PR is part of #626

Submitter Checklist

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

See the contribution guide
for more details.

Release Notes

Task authors can use template variables to refer to using `path`:

${inputs.resources.someresource.path} 
${outputs.resources.someresource.path}

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 17, 2019
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label May 17, 2019
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 17, 2019
@@ -752,38 +745,6 @@ func TestStorageInputResource(t *testing.T) {
},
},
wantErr: true,
}, {
desc: "inputs with both resource spec and resource ref",
task: &v1alpha1.Task{
Copy link
Member Author

Choose a reason for hiding this comment

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

These errors cases are no longer present here since the resource instantiation happens upstream in the calling code

@dibyom dibyom force-pushed the 626 branch 2 times, most recently from 8e3f4e7 to 521dd59 Compare May 20, 2019 18:10
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

I started reviewing this and then realized it was a WIP - hope you don't mind some early feedback! :D

pkg/reconciler/v1alpha1/taskrun/resources/apply.go Outdated Show resolved Hide resolved
if s.TargetPath != "" {
dPath = s.TargetPath
} else {
dPath = s.Name
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, is it okay that we no longer default to s.Name? (i think maybe when we were pairing we found that s.Name was actually a bug? i can't quite remember 😅 )

Copy link
Member Author

@dibyom dibyom May 21, 2019

Choose a reason for hiding this comment

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

I think we should be defaulting to the resource name (I'll validate!) but the destination directory (or TargetPath as it is called in the git resource) is set by the SetDestinationDirectory instead of in NewGitResource or GetDownloadContainerSpec.

SetDestinationDirectory itself is called in AddInputResources and the value of the path is set in destinationPath which defaults to the name.

This flow is confusing though. I think we should set the destinationDirectory when we create the object instead of the setter in a future PR

i = inputResourceInterfaces[name]
resolved[r.Name] = i
} else if r.ResourceSpec != nil {
i, _ =v1alpha1.ResourceFromType(&v1alpha1.PipelineResource{
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think some of your auto-formatting settings might be a bit off here cuz I would expect to see a after the = 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Ran gofmt!!

@@ -74,22 +73,22 @@ func AddInputResource(
for _, input := range taskSpec.Inputs.Resources {
boundResource, err := getBoundResource(input.Name, taskRun.Spec.Inputs.Resources)
if err != nil {
return nil, fmt.Errorf("Failed to get bound resource: %s", err)
return nil, fmt.Errorf("failed to get bound resource: %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@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 May 21, 2019
Each resource processing step (e.g. adding input/output resources,
applying templating) would create its own `PipelineResourceInterface`.
This is a problem since the interface uses a setter
(`SetDestinationDirectory`) that would not always be called. The
destination directory is required to be set in order to facilitate
variable substitution for resource paths.

This commit refactors the resource initialization process by creating a
binding between the named resource and the interface implementation and
passing it around instead of creating new `PipelineResourceInterface`
each time.
This commits adds the ability to substitute resource paths on disk
using template variables e.g. ${inputs/outputs.resources.myresource.path}.
Prior to this, users would have to hardcode the paths
(e.g. /workspace/myresource).
@dibyom dibyom changed the title WIP Add variable substitution for resource paths Add variable substitution for resource paths May 22, 2019
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 22, 2019
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Looks great!! I'm excited to have this functionality, thanks @dibyom ! ❤️

image

/lgtm
/approve

@@ -211,7 +211,8 @@ Input resources, like source code (git) or artifacts, are dumped at path
`/workspace/task_resource_name` within a mounted
[volume](https://kubernetes.io/docs/concepts/storage/volumes/) and is available
to all [`steps`](#steps) of your `Task`. The path that the resources are mounted
at can be overridden with the `targetPath` value.
at can be overridden with the `targetPath` value. Steps can use the `path`
[template](#Templating) key to refer to the local path to the mounted resource.
Copy link
Collaborator

Choose a reason for hiding this comment

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

😎

@@ -35,7 +35,7 @@ spec:
- '-v'
- '-count=1'
- './...'
workingDir: "/workspace/go/src/github.com/tektoncd/pipeline"
workingDir: "${inputs.resources.gitspace.path}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

niiiice i like how you updated the examples too!


err := resources.AddOutputImageDigestExporter(tr, ts, c.resourceLister.PipelineResources(tr.Namespace).Get)
// createPod creates a Pod based on the Task's configuration, with pvcName as a volumeMount
// TODO(dibyom): Refactor resource setup/templating logic to its own function in the resources package
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

the only thing I'd say here is to only commit a TODO like this if you definitely mean to get back to it ;)

outputResources, err := resourceImplBinding(rtr.Outputs)
if err != nil {
c.Logger.Errorf("Failed to initialize output resources: %v", err)
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we usually lean toward a pattern where we wrap the error with more context and return it - and only in the reconciler loop where the return value of createPod is handled would we log

i'm happy to leave this as-is for now tho and we can improve it later :D (esp. if you are already planning to refactor 😇 )

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 29, 2019
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bobcatfish, dibyom

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 May 29, 2019
@bobcatfish
Copy link
Collaborator

bobcatfish commented May 29, 2019

I0529 18:34:28.024] ERROR: (gcloud.beta.container.clusters.create) Operation [<Operation
I0529 18:34:28.025]  clusterConditions: [<StatusCondition
I0529 18:34:28.025]  code: CodeValueValuesEnum(GCE_STOCKOUT, 1)
I0529 18:34:28.025]  message: u'Try a different location, or try again later: Google Compute Engine does not have enough resources available to fulfill request: us-central1-c.'>]
I0529 18:34:28.025]  detail: u'Try a different location, or try again later: Google Compute Engine does not have enough resources available to fulfill request: us-central1-c.'

>.>
<.<

/test pull-tekton-pipeline-integration-tests

@tekton-robot tekton-robot merged commit 4aac2b6 into tektoncd:master May 29, 2019
@dibyom
Copy link
Member Author

dibyom commented May 29, 2019

Missed the memo on squashing up the commits 😞 Next time!

@dibyom dibyom deleted the 626 branch May 29, 2019 19:30
@bobcatfish
Copy link
Collaborator

Missed the memo on squashing up the commits disappointed Next time!

whoops, and i forgot to look! next time :)

bobcatfish added a commit to bobcatfish/pipeline that referenced this pull request Jul 30, 2019
@dibyom has been contributing significant work including variable path
resource substitution tektoncd#877 and
his continued work on one of our oldest and most sought after features:
conditional execution (tektoncd#27)!

He has also reviewed 44+ PRs in the Pipelines repo:
https://tekton.devstats.cd.foundation/d/46/pr-reviews-by-contributor?orgId=1&var-period=d&var-repo_name=tektoncd%2Fpipeline&var-reviewers="dibyom"
@bobcatfish bobcatfish mentioned this pull request Jul 30, 2019
1 task
tekton-robot pushed a commit that referenced this pull request Aug 5, 2019
@dibyom has been contributing significant work including variable path
resource substitution #877 and
his continued work on one of our oldest and most sought after features:
conditional execution (#27)!

He has also reviewed 44+ PRs in the Pipelines repo:
https://tekton.devstats.cd.foundation/d/46/pr-reviews-by-contributor?orgId=1&var-period=d&var-repo_name=tektoncd%2Fpipeline&var-reviewers="dibyom"
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. 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