-
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
Allow declaring and passing resources to conditions #1151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,12 @@ tasks: | |
name: build-push | ||
conditions: | ||
- conditionRef: my-condition | ||
params: | ||
- name: my-param | ||
value: my-value | ||
resources: | ||
- name: workspace | ||
resource: source-repo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm something just occurred to me - can conditions use the e.g. a Task has a git output (assuming a world where a git output creates a new commit), another Task gets the git resource |
||
``` | ||
|
||
In this example, `my-condition` refers to a [Condition](#conditions) custom resource. The `build-push` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,9 @@ type PipelineTaskCondition struct { | |
// Params declare parameters passed to this Condition | ||
// +optional | ||
Params []Param `json:"params,omitempty"` | ||
|
||
// Resources declare the resources provided to this Condition as input | ||
Resources []PipelineConditionResource `json:"resources,omitempty"` | ||
} | ||
|
||
// PipelineDeclaredResource is used by a Pipeline to declare the types of the | ||
|
@@ -135,6 +138,15 @@ type PipelineDeclaredResource struct { | |
Type PipelineResourceType `json:"type"` | ||
} | ||
|
||
// PipelineConditionResource allows a Pipeline to declare how its DeclaredPipelineResources | ||
// should be provided to a Condition as its inputs. | ||
type PipelineConditionResource struct { | ||
// Name is the name of the PipelineResource as declared by the Condition. | ||
Name string `json:"name"` | ||
// Resource is the name of the DeclaredPipelineResource to use. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm this is kinda odd but also really minor - these comments refer to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Maybe this is |
||
Resource string `json:"resource"` | ||
} | ||
|
||
// PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources | ||
// should be provided to a Task as its inputs and outputs. | ||
type PipelineTaskResources struct { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2019 The Tekton Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import "path/filepath" | ||
|
||
// InputResourcePath returns the path where the given input resource | ||
// will get mounted in a Pod | ||
func InputResourcePath(r ResourceDeclaration) string { | ||
return path("/workspace", r) | ||
} | ||
|
||
// OutputResourcePath returns the path to the output resouce in a Pod | ||
func OutputResourcePath(r ResourceDeclaration) string { | ||
return path("/workspace/output", r) | ||
} | ||
|
||
func path(root string, r ResourceDeclaration) string { | ||
if r.TargetPath != "" { | ||
return filepath.Join("/workspace", r.TargetPath) | ||
} | ||
return filepath.Join(root, r.Name) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2019 The Tekton Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
) | ||
|
||
func TestInputResourcePath(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
resource v1alpha1.ResourceDeclaration | ||
expected string | ||
}{{ | ||
name: "default_path", | ||
resource: v1alpha1.ResourceDeclaration{ | ||
Name: "foo", | ||
}, | ||
expected: "/workspace/foo", | ||
}, { | ||
name: "with target path", | ||
resource: v1alpha1.ResourceDeclaration{ | ||
Name: "foo", | ||
TargetPath: "bar", | ||
}, | ||
expected: "/workspace/bar", | ||
}} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if actual := v1alpha1.InputResourcePath(tc.resource); actual != tc.expected { | ||
t.Errorf("Unexpected input resource path: %s", actual) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOutputResourcePath(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
resource v1alpha1.ResourceDeclaration | ||
expected string | ||
}{{ | ||
name: "default_path", | ||
resource: v1alpha1.ResourceDeclaration{ | ||
Name: "foo", | ||
}, | ||
expected: "/workspace/output/foo", | ||
}, { | ||
name: "with target path", | ||
resource: v1alpha1.ResourceDeclaration{ | ||
Name: "foo", | ||
TargetPath: "bar", | ||
}, | ||
expected: "/workspace/bar", | ||
}} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if actual := v1alpha1.OutputResourcePath(tc.resource); actual != tc.expected { | ||
t.Errorf("Unexpected output resource path: %s", actual) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be helpful to included the expected path in the error message as well |
||
} | ||
}) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha yeessssss i love the super focused test coverage XD |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,17 +117,7 @@ type Inputs struct { | |
// path to the volume mounted containing this Resource as an input (e.g. | ||
// an input Resource named `workspace` will be mounted at `/workspace`). | ||
type TaskResource struct { | ||
// Name declares the name by which a resource is referenced in the Task's | ||
// definition. Resources may be referenced by name in the definition of a | ||
// Task's steps. | ||
Name string `json:"name"` | ||
// Type is the type of this resource; | ||
Type PipelineResourceType `json:"type"` | ||
// TargetPath is the path in workspace directory where the task resource | ||
// will be copied. | ||
// +optional | ||
TargetPath string `json:"targetPath,omitempty"` | ||
// Path to the index.json file for output container images. | ||
ResourceDeclaration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 😇 |
||
// +optional | ||
OutputImageDir string `json:"outputImageDir,omitempty"` | ||
} | ||
|
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 I'm thinking that we should create a separate section in the
resources.md
docs for how the paths work - the docs are a bit spread out, e.g.https://github.com/tektoncd/pipeline/blob/master/docs/tasks.md#controlling-where-resources-are-mounted
and
https://github.com/tektoncd/pipeline/blob/master/docs/taskruns.md#overriding-where-resources-are-copied-from
And even the path templating (like you said!)
https://github.com/tektoncd/pipeline/blob/master/docs/tasks.md#templating
But I think/hope that both of those docs would apply to this use of resources as well? In which case it'd be good if we can put all those docs in one place and link to them from here and from the other places
🙏
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.
Yeah, the thing is since things like
targetPath
are part ofTaskResource
, they are in the tasks doc. Now with conditions, there is some duplication. I'll add a section in the resource doc on how to use resources in conditions and tasks. That section will link to both the Task and Condition resource docs and contain the common bits e.g. targetPaths, the path variable substitution.I'm thinking of doing this in a follow-up PR.