Skip to content

Commit

Permalink
Remove version from TaskRun resource binding
Browse files Browse the repository at this point in the history
We had been hoping to use `version` to cover two cases:
1. To allow a user to override the version of the Resource they are using
   (e.g. for a particular git resource, use a different revision)
2.  For the case where a Task modifies a resource then provides it to the
   next Task, we wanted to express the modification in the version

In the previous commit, we made it so that a user can change a Resource
by creating a new one and specifying the new one in teh PipelineRun,
and they can do the same thing via a TaskRun.

For the second case, in #124 @shashwathi is designing how the output of
one task will be passed to the next, and it is likely going to be via
PVCs and will not need the version field.

Fixes #200
  • Loading branch information
bobcatfish committed Nov 21, 2018
1 parent 61e9729 commit 1963376
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 242 deletions.
92 changes: 20 additions & 72 deletions docs/using.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,84 +192,32 @@ See [the example TaskRun](../examples/invocations/run-kritis-test.yaml).

### Git Resource

Git resource represents a [git](https://git-scm.com/) repository, that containes
Git resource represents a [git](https://git-scm.com/) repository, that contains
the source code to be built by the pipeline. Adding the git resource as an input
to a task will clone this repository and allow the task to perform the required
actions on the contents of the repo.

Use the following example to understand the syntax and strucutre of a Git Resource
To create a git resource using the `PipelineResource` CRD:

1. Create a git resource using the `PipelineResource` CRD
```yaml
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: wizzbang-git
namespace: default
spec:
type: git
params:
- name: url
value: https://github.com/wizzbangcorp/wizzbang.git
- name: Revision
value: master
```

```yaml
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: wizzbang-git
namespace: default
spec:
type: git
params:
- name: url
value: https://github.com/wizzbangcorp/wizzbang.git
- name: Revision
value: master
```

Params that can be added are the following:

1. URL: represents the location of the git repository
1. Revision: Git [revision](https://git-scm.com/docs/gitrevisions#_specifying_revisions ) (branch, tag, commit SHA or ref) to clone. If no revision is specified, the resource will default to `latest` from `master`

2. Use the defined git resource in a `Task` definition:

```yaml
apiVersion: pipeline.knative.dev/v1alpha1
kind: Task
metadata:
name: build-push-task
namespace: default
spec:
inputs:
resources:
- name: wizzbang-git
type: git
params:
- name: pathToDockerfile
outputs:
resources:
- name: builtImage
type: image
steps:
- name: build-and-push
image: gcr.io/my-repo/my-imageg
args:
- --repo=${inputs.resources.wizzbang-git.url}
```

3. And finally set the version in the `TaskRun` definition:

```yaml
apiVersion: pipeline.knative.dev/v1alpha1
kind: TaskRun
metadata:
name: build-push-task-run
namespace: default
spec:
taskRef:
name: build-push-task
inputs:
resourcesVersion:
- resourceRef:
name: wizzbang-git
apiVersion: HEAD
outputs:
resources:
- name: builtImage
type: image
# Optional, indicate a serviceAccount for authentication.
serviceAccount: build-bot
```
Params that can be added are the following:

1. URL: represents the location of the git repository
1. Revision: Git [revision](https://git-scm.com/docs/gitrevisions#_specifying_revisions ) (branch, tag, commit SHA or ref) to clone. If no revision is specified, the resource will default to `latest` from `master`

### Cluster Resource

Expand Down
7 changes: 3 additions & 4 deletions examples/invocations/run-kritis-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ spec:
type: PipelineRun
name: kritis-pipeline-run-12321312984
inputs:
resourcesVersion:
- resourceRef:
resources:
- name: workspace
resourceRef:
name: kritis-resources-git
version: 4da79b91e8e37ea441cfe4972565e2184c1a127f
name: workspace
params:
- name: 'makeTarget'
value: 'test'
5 changes: 0 additions & 5 deletions pkg/apis/pipeline/v1alpha1/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ func (s ClusterResource) GetType() PipelineResourceType {
return PipelineResourceTypeCluster
}

// GetVersion returns the revision of the resource
func (s ClusterResource) GetVersion() string {
return s.Revision
}

// GetURL returns the url to be used with this resource
func (s *ClusterResource) GetURL() string {
return s.URL
Expand Down
7 changes: 0 additions & 7 deletions pkg/apis/pipeline/v1alpha1/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ func (s GitResource) GetType() PipelineResourceType {
return PipelineResourceTypeGit
}

// GetVersion returns the revision of the resource, See
// https://git-scm.com/docs/gitrevisions#_specifying_revisions for
// more details what the revison in github is
func (s GitResource) GetVersion() string {
return s.Revision
}

// GetURL returns the url to be used with this resource
func (s *GitResource) GetURL() string {
return s.URL
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/pipeline/v1alpha1/image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ func (s ImageResource) GetType() PipelineResourceType {
return PipelineResourceTypeImage
}

// GetVersion returns the version of the resource
func (s ImageResource) GetVersion() string {
return s.Digest
}

// GetParams returns the resoruce params
func (s ImageResource) GetParams() []Param { return []Param{} }

Expand Down
7 changes: 3 additions & 4 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const (
PipelineResourceTypeCluster PipelineResourceType = "cluster"
)

// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeGCS, PipelineResourceTypeImage, PipelineResourceTypeCluster}

// PipelineResourceInterface interface to be implemented by different PipelineResource types
type PipelineResourceInterface interface {
GetName() string
GetType() PipelineResourceType
GetParams() []Param
GetVersion() string
Replacements() map[string]string
}

Expand Down Expand Up @@ -113,12 +113,11 @@ type PipelineResource struct {
Status PipelineResourceStatus `json:"status,omitempty"`
}

// TaskRunResourceVersion defines the version of the PipelineResource that
// TaskRunResource points to the PipelineResource that
// will be used for the Task input or output called Name.
type TaskRunResourceVersion struct {
type TaskRunResource struct {
Name string `json:"name"`
ResourceRef PipelineResourceRef `json:"resourceRef"`
Version string `json:"version"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ type TaskRunSpec struct {
// TaskRunInputs holds the input values that this task was invoked with.
type TaskRunInputs struct {
// +optional
Resources []TaskRunResourceVersion `json:"resourcesVersion,omitempty"`
Resources []TaskRunResource `json:"resources,omitempty"`
// +optional
Params []Param `json:"params,omitempty"`
}

// TaskRunOutputs holds the output values that this task was invoked with.
type TaskRunOutputs struct {
// +optional
Resources []TaskRunResourceVersion `json:"resourcesVersion,omitempty"`
Resources []TaskRunResource `json:"resources,omitempty"`
// +optional
Params []Param `json:"params,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r ResultTarget) Validate(path string) *apis.FieldError {
return nil
}

func checkForPipelineResourceDuplicates(resources []TaskRunResourceVersion, path string) *apis.FieldError {
func checkForPipelineResourceDuplicates(resources []TaskRunResource, path string) *apis.FieldError {
encountered := map[string]struct{}{}
for _, r := range resources {
// We should provide only one binding for each resource required by the Task.
Expand Down
17 changes: 5 additions & 12 deletions pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ func TestInput_Validate(t *testing.T) {
Name: "name",
Value: "value",
}},
Resources: []TaskRunResourceVersion{{
Version: "testv1",
Resources: []TaskRunResource{{
ResourceRef: PipelineResourceRef{
Name: "testresource",
},
Expand All @@ -205,14 +204,12 @@ func TestInput_Invalidate(t *testing.T) {
{
name: "duplicate task inputs",
inputs: TaskRunInputs{
Resources: []TaskRunResourceVersion{{
Version: "testv1",
Resources: []TaskRunResource{{
ResourceRef: PipelineResourceRef{
Name: "testresource1",
},
Name: "workspace",
}, {
Version: "testv1",
ResourceRef: PipelineResourceRef{
Name: "testresource2",
},
Expand All @@ -224,8 +221,7 @@ func TestInput_Invalidate(t *testing.T) {
{
name: "invalid task input params",
inputs: TaskRunInputs{
Resources: []TaskRunResourceVersion{{
Version: "testv1",
Resources: []TaskRunResource{{
ResourceRef: PipelineResourceRef{
Name: "testresource",
},
Expand Down Expand Up @@ -336,8 +332,7 @@ func TestResultTarget_Validate(t *testing.T) {

func TestOutput_Validate(t *testing.T) {
i := TaskRunOutputs{
Resources: []TaskRunResourceVersion{{
Version: "testv1",
Resources: []TaskRunResource{{
ResourceRef: PipelineResourceRef{
Name: "testresource",
},
Expand All @@ -357,14 +352,12 @@ func TestOutput_Invalidate(t *testing.T) {
{
name: "duplicated task outputs",
outputs: TaskRunOutputs{
Resources: []TaskRunResourceVersion{{
Version: "testv1",
Resources: []TaskRunResource{{
ResourceRef: PipelineResourceRef{
Name: "testresource1",
},
Name: "workspace",
}, {
Version: "testv1",
ResourceRef: PipelineResourceRef{
Name: "testresource2",
},
Expand Down
12 changes: 6 additions & 6 deletions 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.

4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ func (c *Reconciler) createTaskRun(t *v1alpha1.Task, trName string, pr *v1alpha1
}
}
for _, isb := range resources.Inputs {
tr.Spec.Inputs.Resources = append(tr.Spec.Inputs.Resources, v1alpha1.TaskRunResourceVersion{
tr.Spec.Inputs.Resources = append(tr.Spec.Inputs.Resources, v1alpha1.TaskRunResource{
ResourceRef: isb.ResourceRef,
Name: isb.Name,
})
}
for _, osb := range resources.Outputs {
tr.Spec.Outputs.Resources = append(tr.Spec.Outputs.Resources, v1alpha1.TaskRunResourceVersion{
tr.Spec.Outputs.Resources = append(tr.Spec.Outputs.Resources, v1alpha1.TaskRunResource{
ResourceRef: osb.ResourceRef,
Name: osb.Name,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ func TestReconcile(t *testing.T) {
Value: "${inputs.workspace.revision}",
},
},
Resources: []v1alpha1.TaskRunResourceVersion{{
Resources: []v1alpha1.TaskRunResource{{
ResourceRef: v1alpha1.PipelineResourceRef{
Name: "some-repo",
},
Name: "workspace",
}},
},
Outputs: v1alpha1.TaskRunOutputs{
Resources: []v1alpha1.TaskRunResourceVersion{{
Resources: []v1alpha1.TaskRunResource{{
ResourceRef: v1alpha1.PipelineResourceRef{
Name: "some-image",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func ApplyParameters(b *buildv1alpha1.Build, tr *v1alpha1.TaskRun, defaults ...v
return ApplyReplacements(b, replacements)
}

// ResourceGetter is the interface used to retrieve resources which are references via a TaskRunResourceVersion.
// ResourceGetter is the interface used to retrieve resources which are references via a TaskRunResource.
type ResourceGetter interface {
Get(string) (*v1alpha1.PipelineResource, error)
}

// ApplyResources applies the templating from values in resources which are referenced in b as subitems
// of the replacementStr. It retrieves the referenced resources via the getter.
func ApplyResources(b *buildv1alpha1.Build, resources []v1alpha1.TaskRunResourceVersion, getter ResourceGetter, replacementStr string) (*buildv1alpha1.Build, error) {
func ApplyResources(b *buildv1alpha1.Build, resources []v1alpha1.TaskRunResource, getter ResourceGetter, replacementStr string) (*buildv1alpha1.Build, error) {
replacements := map[string]string{}

for _, r := range resources {
Expand Down
Loading

0 comments on commit 1963376

Please sign in to comment.