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 support to enable resourceSpec #1324

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ spec:
name: skaffold-image-leeroy-app
```

Or you can embed the spec of the `Resource` directly in the `PipelineRun`:


```yaml
spec:
resources:
- name: source-repo
resourceSpec:
type: git
params:
- name: revision
value: v0.32.0
- name: url
value: https://github.com/GoogleContainerTools/skaffold
- name: web-image
resourceSpec:
type: image
params:
- name: url
value: gcr.io/christiewilson-catfactory/leeroy-web
- name: app-image
resourceSpec:
type: image
params:
- name: url
value: gcr.io/christiewilson-catfactory/leeroy-app
```

### Service Account

Specifies the `name` of a `ServiceAccount` resource object. Use the
Expand Down Expand Up @@ -121,7 +149,6 @@ spec:
- name: build-task
taskRef:
name: build-push
tasks:
- name: test-task
taskRef:
name: test
Expand Down Expand Up @@ -174,7 +201,7 @@ spec:
tasks:
- name: task1
taskRef:
name: myTask
name: myTask
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
Expand Down
98 changes: 98 additions & 0 deletions examples/pipelineruns/pipelinerun-with-resourcespec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: task-to-list-files
spec:
inputs:
resources:
- name: pipeline-git
type: git
outputs:
resources:
- name: pipeline-git
type: git
steps:
- name: list
image: ubuntu
command:
- bash
args:
- -c
- |
ls -al $(inputs.resources.pipeline-git.path)
---

apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
name: always-true-sample-condition
spec:
resources:
- name: pipeline-git
type: git
check:
image: ubuntu
command:
- bash
args:
- -c
- |
echo "Hello from Tekton Pipeline!"
---

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: pipeline-to-list-files
spec:
resources:
- name: pipeline-git
type: git
params:
- name: "path"
default: "README.md"
tasks:
- name: list-files
taskRef:
name: task-to-list-files
resources:
inputs:
- name: pipeline-git
resource: pipeline-git
outputs:
- name: pipeline-git
resource: pipeline-git
- name: conditional-list-files
taskRef:
name: task-to-list-files
conditions:
- conditionRef: always-true-sample-condition
resources:
- name: pipeline-git
resource: pipeline-git
resources:
inputs:
- name: pipeline-git
resource: pipeline-git
outputs:
- name: pipeline-git
resource: pipeline-git
---

apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
name: demo-pipelinerun-with-resourcespec
spec:
pipelineRef:
name: pipeline-to-list-files
serviceAccount: 'default'
resources:
- name: pipeline-git
resourceSpec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/tektoncd/pipeline
Copy link
Collaborator

Choose a reason for hiding this comment

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

great example!

10 changes: 5 additions & 5 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func TestPipelineRun_Invalidate(t *testing.T) {
},
}

for _, ts := range tests {
t.Run(ts.name, func(t *testing.T) {
err := ts.pr.Validate(context.Background())
if d := cmp.Diff(err.Error(), ts.want.Error()); d != "" {
t.Errorf("PipelineRun.Validate/%s (-want, +got) = %v", ts.name, d)
for _, ps := range tests {
t.Run(ps.name, func(t *testing.T) {
err := ps.pr.Validate(context.Background())
if d := cmp.Diff(err.Error(), ps.want.Error()); d != "" {
t.Errorf("PipelineRun.Validate/%s (-want, +got) = %v", ps.name, d)
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ type PipelineResourceBinding struct {
// ResourceRef is a reference to the instance of the actual PipelineResource
// that should be used
ResourceRef PipelineResourceRef `json:"resourceRef,omitempty"`
// +optional
// ResourceSpec is specification of a resource that should be created and
// consumed by the task
ResourceSpec *PipelineResourceSpec `json:"resourceSpec,omitempty"`
}

// PipelineResourceResult used to export the image name and digest as json
Expand Down
9 changes: 8 additions & 1 deletion pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ func TestReconcile(t *testing.T) {
tb.TaskRunInputsParam("foo", "somethingfun"),
tb.TaskRunInputsParam("bar", "somethingmorefun"),
tb.TaskRunInputsParam("templatedparam", "$(inputs.workspace.revision)"),
tb.TaskRunInputsResource("workspace", tb.TaskResourceBindingRef("some-repo")),
tb.TaskRunInputsResource("workspace", tb.TaskResourceBindingResourceSpec(&rs[0].Spec)),
),
tb.TaskRunOutputs(
tb.TaskRunOutputsResource("image-to-use", tb.TaskResourceBindingRef("some-image"),
tb.TaskRunOutputsResource("image-to-use", tb.TaskResourceBindingResourceSpec(&rs[1].Spec),
tb.TaskResourceBindingPaths("/pvc/unit-test-1/image-to-use"),
),
tb.TaskRunOutputsResource("workspace", tb.TaskResourceBindingRef("some-repo"),
tb.TaskRunOutputsResource("workspace", tb.TaskResourceBindingResourceSpec(&rs[0].Spec),
tb.TaskResourceBindingPaths("/pvc/unit-test-1/workspace"),
),
),
Expand Down
17 changes: 13 additions & 4 deletions pkg/reconciler/pipelinerun/resources/conditionresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,22 @@ func (rcc *ResolvedConditionCheck) ToTaskResourceBindings() []v1alpha1.TaskResou
var trb []v1alpha1.TaskResourceBinding

for name, r := range rcc.ResolvedResources {
trb = append(trb, v1alpha1.TaskResourceBinding{
tr := v1alpha1.TaskResourceBinding{
Name: name,
ResourceRef: v1alpha1.PipelineResourceRef{
}
if r.SelfLink != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hey @pritidesai, somehow I didn't notice this when I looked before: what's the significance of selfLink here? it seems like its being used to decide if a resource should be embedded or not? 🤔

Copy link
Member Author

@pritidesai pritidesai Sep 26, 2019

Choose a reason for hiding this comment

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

hey @pritidesai, somehow I didn't notice this when I looked before: what's the significance of selfLink here? it seems like its being used to decide if a resource should be embedded or not? 🤔

Hey @bobcatfish yes selfLink is the deciding factor here and most reliable, if resource is specified through reference (resourceRef), selfLink will never be empty and set to something like /apis/tekton.dev/pipelineresources/my-git-resource since my-git-resource is already created and can be referred to through this link. This was the best choice, as in inputs being type of map[string]*v1alpha1.PipelineResource in input_output_steps.go line 56 always had name set to the resource name and PipelineResource.name set to the same name as resource name even when a resource specification were given (using resourceSpec). Hope this helps.

tr.ResourceRef = v1alpha1.PipelineResourceRef{
Name: r.Name,
APIVersion: r.APIVersion,
},
})
}
} else if r.Spec.Type != "" {
tr.ResourceSpec = &v1alpha1.PipelineResourceSpec{
Type: r.Spec.Type,
Params: r.Spec.Params,
SecretParams: r.Spec.SecretParams,
}
}
trb = append(trb, tr)
}

return trb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ func TestResolvedConditionCheck_ToTaskResourceBindings(t *testing.T) {

expected := []v1alpha1.TaskResourceBinding{{
Name: "git-resource",
ResourceRef: v1alpha1.PipelineResourceRef{
Copy link
Member

Choose a reason for hiding this comment

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

Why was this deleted?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sometimes you want to have a ResourceBinding without a Ref (e.g. if you're using a spec!). So in the tests for embedded TaskRun Resource specs, this was being set even tho it shouldn't be

(The other function actually doesn't set this)

(Might be worth adding this to the commit message if it isn't there already @pritidesai !)

Name: "some-repo",
},
}}

if d := cmp.Diff(expected, rcc.ToTaskResourceBindings()); d != "" {
Expand Down
33 changes: 25 additions & 8 deletions pkg/reconciler/pipelinerun/resources/input_output_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ func GetOutputSteps(outputs map[string]*v1alpha1.PipelineResource, taskName, sto
var taskOutputResources []v1alpha1.TaskResourceBinding

for name, outputResource := range outputs {
taskOutputResources = append(taskOutputResources, v1alpha1.TaskResourceBinding{
Name: name,
ResourceRef: v1alpha1.PipelineResourceRef{
taskOutputResource := v1alpha1.TaskResourceBinding{
Name: name,
Paths: []string{filepath.Join(storageBasePath, taskName, name)},
}
if outputResource.SelfLink != "" {
taskOutputResource.ResourceRef = v1alpha1.PipelineResourceRef{
Name: outputResource.Name,
APIVersion: outputResource.APIVersion,
},
Paths: []string{filepath.Join(storageBasePath, taskName, name)},
})
}
} else if outputResource.Spec.Type != "" {
taskOutputResource.ResourceSpec = &v1alpha1.PipelineResourceSpec{
Type: outputResource.Spec.Type,
Params: outputResource.Spec.Params,
SecretParams: outputResource.Spec.SecretParams,
}
}
taskOutputResources = append(taskOutputResources, taskOutputResource)
}
return taskOutputResources
}
Expand All @@ -47,10 +56,18 @@ func GetInputSteps(inputs map[string]*v1alpha1.PipelineResource, pt *v1alpha1.Pi
for name, inputResource := range inputs {
taskInputResource := v1alpha1.TaskResourceBinding{
Name: name,
ResourceRef: v1alpha1.PipelineResourceRef{
}
if inputResource.SelfLink != "" {
taskInputResource.ResourceRef = v1alpha1.PipelineResourceRef{
Name: inputResource.Name,
APIVersion: inputResource.APIVersion,
},
}
} else if inputResource.Spec.Type != "" {
taskInputResource.ResourceSpec = &v1alpha1.PipelineResourceSpec{
Type: inputResource.Spec.Type,
Params: inputResource.Spec.Params,
SecretParams: inputResource.Spec.SecretParams,
}
}

var stepSourceNames []string
Expand Down
Loading