-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
@@ -752,38 +745,6 @@ func TestStorageInputResource(t *testing.T) { | |||
}, | |||
}, | |||
wantErr: true, | |||
}, { | |||
desc: "inputs with both resource spec and resource ref", | |||
task: &v1alpha1.Task{ |
There was a problem hiding this comment.
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
8e3f4e7
to
521dd59
Compare
There was a problem hiding this 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
if s.TargetPath != "" { | ||
dPath = s.TargetPath | ||
} else { | ||
dPath = s.Name |
There was a problem hiding this comment.
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 😅 )
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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 =
🤔
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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. |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 😇 )
[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 |
>.> /test pull-tekton-pipeline-integration-tests |
Missed the memo on squashing up the commits 😞 Next time! |
whoops, and i forgot to look! next time :) |
@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"
@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"
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
PipelineResourceInterface
each time.Marking this as a WIP until I:
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