From 892564316fabd44fc672710b5b86223c3643b6ca Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Tue, 20 Nov 2018 17:47:56 -0800 Subject: [PATCH] Remove `version` from TaskRun resource binding 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 --- docs/using.md | 92 ++++------------- examples/invocations/run-kritis-test.yaml | 7 +- .../pipeline/v1alpha1/cluster_resource.go | 5 - pkg/apis/pipeline/v1alpha1/git_resource.go | 7 -- pkg/apis/pipeline/v1alpha1/image_resource.go | 5 - pkg/apis/pipeline/v1alpha1/resource_types.go | 7 +- pkg/apis/pipeline/v1alpha1/taskrun_types.go | 4 +- .../pipeline/v1alpha1/taskrun_validation.go | 2 +- .../v1alpha1/taskrun_validation_test.go | 17 +--- .../v1alpha1/zz_generated.deepcopy.go | 12 +-- .../v1alpha1/pipelinerun/pipelinerun.go | 4 +- .../v1alpha1/pipelinerun/pipelinerun_test.go | 4 +- .../v1alpha1/taskrun/resources/apply.go | 4 +- .../v1alpha1/taskrun/resources/apply_test.go | 17 ++-- .../taskrun/resources/input_resource_test.go | 99 ++++++------------- .../taskrun/resources/input_resources.go | 5 +- .../v1alpha1/taskrun/taskrun_test.go | 22 ++--- .../v1alpha1/taskrun/validate_test.go | 24 ++--- test/cluster_resource_test.go | 12 +-- test/kaniko_task_test.go | 5 +- 20 files changed, 112 insertions(+), 242 deletions(-) diff --git a/docs/using.md b/docs/using.md index 17ba5a40e6c..8674451409a 100644 --- a/docs/using.md +++ b/docs/using.md @@ -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 diff --git a/examples/invocations/run-kritis-test.yaml b/examples/invocations/run-kritis-test.yaml index 4cf5c0acd0f..985c9f94060 100644 --- a/examples/invocations/run-kritis-test.yaml +++ b/examples/invocations/run-kritis-test.yaml @@ -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' \ No newline at end of file diff --git a/pkg/apis/pipeline/v1alpha1/cluster_resource.go b/pkg/apis/pipeline/v1alpha1/cluster_resource.go index 82bb8f9695d..07209e6eeb3 100644 --- a/pkg/apis/pipeline/v1alpha1/cluster_resource.go +++ b/pkg/apis/pipeline/v1alpha1/cluster_resource.go @@ -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 diff --git a/pkg/apis/pipeline/v1alpha1/git_resource.go b/pkg/apis/pipeline/v1alpha1/git_resource.go index 009e2bff395..868a7a11dc0 100644 --- a/pkg/apis/pipeline/v1alpha1/git_resource.go +++ b/pkg/apis/pipeline/v1alpha1/git_resource.go @@ -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 diff --git a/pkg/apis/pipeline/v1alpha1/image_resource.go b/pkg/apis/pipeline/v1alpha1/image_resource.go index 231eedb4806..06c9135b5b4 100644 --- a/pkg/apis/pipeline/v1alpha1/image_resource.go +++ b/pkg/apis/pipeline/v1alpha1/image_resource.go @@ -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{} } diff --git a/pkg/apis/pipeline/v1alpha1/resource_types.go b/pkg/apis/pipeline/v1alpha1/resource_types.go index 0dc1652f653..2002891e1f0 100644 --- a/pkg/apis/pipeline/v1alpha1/resource_types.go +++ b/pkg/apis/pipeline/v1alpha1/resource_types.go @@ -43,6 +43,7 @@ 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 @@ -50,7 +51,6 @@ type PipelineResourceInterface interface { GetName() string GetType() PipelineResourceType GetParams() []Param - GetVersion() string Replacements() map[string]string } @@ -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 diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_types.go b/pkg/apis/pipeline/v1alpha1/taskrun_types.go index 3b9a54291c2..d65399d1bfd 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_types.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_types.go @@ -49,7 +49,7 @@ 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"` } @@ -57,7 +57,7 @@ type TaskRunInputs struct { // 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"` } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_validation.go b/pkg/apis/pipeline/v1alpha1/taskrun_validation.go index 67f6e8655fa..a388c98142c 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_validation.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_validation.go @@ -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. diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go index 43aa8ff461f..511ef9418ba 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go @@ -183,8 +183,7 @@ func TestInput_Validate(t *testing.T) { Name: "name", Value: "value", }}, - Resources: []TaskRunResourceVersion{{ - Version: "testv1", + Resources: []TaskRunResource{{ ResourceRef: PipelineResourceRef{ Name: "testresource", }, @@ -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", }, @@ -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", }, @@ -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", }, @@ -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", }, diff --git a/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go index 25f8ac9fdcd..668d4d8fcbf 100644 --- a/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go @@ -976,7 +976,7 @@ func (in *TaskRunInputs) DeepCopyInto(out *TaskRunInputs) { *out = *in if in.Resources != nil { in, out := &in.Resources, &out.Resources - *out = make([]TaskRunResourceVersion, len(*in)) + *out = make([]TaskRunResource, len(*in)) copy(*out, *in) } if in.Params != nil { @@ -1035,7 +1035,7 @@ func (in *TaskRunOutputs) DeepCopyInto(out *TaskRunOutputs) { *out = *in if in.Resources != nil { in, out := &in.Resources, &out.Resources - *out = make([]TaskRunResourceVersion, len(*in)) + *out = make([]TaskRunResource, len(*in)) copy(*out, *in) } if in.Params != nil { @@ -1057,18 +1057,18 @@ func (in *TaskRunOutputs) DeepCopy() *TaskRunOutputs { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskRunResourceVersion) DeepCopyInto(out *TaskRunResourceVersion) { +func (in *TaskRunResource) DeepCopyInto(out *TaskRunResource) { *out = *in out.ResourceRef = in.ResourceRef return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskRunResourceVersion. -func (in *TaskRunResourceVersion) DeepCopy() *TaskRunResourceVersion { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskRunResource. +func (in *TaskRunResource) DeepCopy() *TaskRunResource { if in == nil { return nil } - out := new(TaskRunResourceVersion) + out := new(TaskRunResource) in.DeepCopyInto(out) return out } diff --git a/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go b/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go index e32f0da2447..bfb9b2f9b0a 100644 --- a/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go @@ -258,13 +258,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, }) diff --git a/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go b/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go index 3fbff2556b7..f741ac3c93a 100644 --- a/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go @@ -208,7 +208,7 @@ func TestReconcile(t *testing.T) { Value: "${inputs.workspace.revision}", }, }, - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ Name: "some-repo", }, @@ -216,7 +216,7 @@ func TestReconcile(t *testing.T) { }}, }, Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ Name: "some-image", }, diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/apply.go b/pkg/reconciler/v1alpha1/taskrun/resources/apply.go index 460285a8bae..13252e38e8b 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/apply.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/apply.go @@ -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 { diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/apply_test.go b/pkg/reconciler/v1alpha1/taskrun/resources/apply_test.go index 5a1a0b3b3c2..e1655236f31 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/apply_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/apply_test.go @@ -61,14 +61,14 @@ var paramTaskRun = &v1alpha1.TaskRun{ }, } -var resourceVersionInputs = []v1alpha1.TaskRunResourceVersion{{ +var inputs = []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ Name: "git-resource", }, Name: "workspace", }} -var resourceVersionOutputs = []v1alpha1.TaskRunResourceVersion{{ +var outputs = []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ Name: "image-resource", }, @@ -139,11 +139,10 @@ func TestApplyParameters(t *testing.T) { tr: &v1alpha1.TaskRun{}, dp: []v1alpha1.TaskParam{ { - Name: "myimage", + Name: "myimage", Default: "mydefault", }, }, - }, want: applyMutation(simpleBuild, func(b *buildv1alpha1.Build) { b.Spec.Steps[0].Image = "mydefault" @@ -185,7 +184,7 @@ func mockGetter() *rg { func TestApplyResources(t *testing.T) { type args struct { b *buildv1alpha1.Build - r []v1alpha1.TaskRunResourceVersion + r []v1alpha1.TaskRunResource getter ResourceGetter rStr string } @@ -199,7 +198,7 @@ func TestApplyResources(t *testing.T) { name: "no replacements specified", args: args{ b: simpleBuild, - r: []v1alpha1.TaskRunResourceVersion{}, + r: []v1alpha1.TaskRunResource{}, getter: mockGetter(), rStr: "inputs", }, @@ -209,7 +208,7 @@ func TestApplyResources(t *testing.T) { name: "input resource specified", args: args{ b: simpleBuild, - r: resourceVersionInputs, + r: inputs, getter: mockGetter().With("git-resource", gitResource), rStr: "inputs", }, @@ -221,7 +220,7 @@ func TestApplyResources(t *testing.T) { name: "output resource specified", args: args{ b: simpleBuild, - r: resourceVersionOutputs, + r: outputs, getter: mockGetter().With("image-resource", imageResource), rStr: "outputs", }, @@ -233,7 +232,7 @@ func TestApplyResources(t *testing.T) { name: "resource does not exist", args: args{ b: simpleBuild, - r: resourceVersionInputs, + r: inputs, getter: mockGetter(), rStr: "inputs", }, diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go b/pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go index 80d537d1c8b..a7e4a70a5da 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go @@ -40,7 +40,7 @@ func setUp() { pipelineResourceInformer := sharedInfomer.Pipeline().V1alpha1().PipelineResources() pipelineResourceLister = pipelineResourceInformer.Lister() - res := &v1alpha1.PipelineResource{ + rs := []*v1alpha1.PipelineResource{{ ObjectMeta: metav1.ObjectMeta{ Name: "the-git", Namespace: "marshmallow", @@ -52,10 +52,22 @@ func setUp() { Value: "https://github.com/grafeas/kritis", }}, }, - } - pipelineResourceInformer.Informer().GetIndexer().Add(res) - - clusterRes := &v1alpha1.PipelineResource{ + }, { + ObjectMeta: metav1.ObjectMeta{ + Name: "the-git-with-branch", + Namespace: "marshmallow", + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: "git", + Params: []v1alpha1.Param{{ + Name: "Url", + Value: "https://github.com/grafeas/kritis", + }, { + Name: "Revision", + Value: "branch", + }}, + }, + }, { ObjectMeta: metav1.ObjectMeta{ Name: "cluster2", Namespace: "marshmallow", @@ -72,10 +84,7 @@ func setUp() { SecretName: "secret1", }}, }, - } - pipelineResourceInformer.Informer().GetIndexer().Add(clusterRes) - - clusterResText := &v1alpha1.PipelineResource{ + }, { ObjectMeta: metav1.ObjectMeta{ Name: "cluster3", Namespace: "marshmallow", @@ -91,8 +100,10 @@ func setUp() { Value: "bXktY2EtY2VydAo=", }}, }, + }} + for _, r := range rs { + pipelineResourceInformer.Informer().GetIndexer().Add(r) } - pipelineResourceInformer.Informer().GetIndexer().Add(clusterResText) } func build() *buildv1alpha1.Build { @@ -145,12 +156,11 @@ func TestAddResourceToBuild(t *testing.T) { Name: "simpleTask", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ Name: "the-git", }, - Version: "master", - Name: "workspace", + Name: "workspace", }}, }, }, @@ -164,7 +174,7 @@ func TestAddResourceToBuild(t *testing.T) { wantErr bool want *buildv1alpha1.Build }{{ - desc: "simple", + desc: "simple with default revision", task: task, taskRun: taskRun, build: build(), @@ -208,60 +218,9 @@ func TestAddResourceToBuild(t *testing.T) { Name: "simpleTask", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "the-git", - }, - Version: "branch", - Name: "workspace", - }}, - }, - }, - }, - build: build(), - wantErr: false, - want: &buildv1alpha1.Build{ - TypeMeta: metav1.TypeMeta{ - Kind: "Build", - APIVersion: "build.knative.dev/v1alpha1"}, - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "pipeline.knative.dev/v1alpha1", - Kind: "TaskRun", - Name: "build-from-repo-run", - Controller: &boolTrue, - BlockOwnerDeletion: &boolTrue, - }, - }, - }, - Spec: buildv1alpha1.BuildSpec{ - Source: &buildv1alpha1.SourceSpec{ - Git: &buildv1alpha1.GitSourceSpec{ - Url: "https://github.com/grafeas/kritis", - Revision: "branch", - }, - }, - }, - }, - }, { - desc: "set revision to default value", - task: task, - taskRun: &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "simpleTask", - }, - Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "the-git", + Name: "the-git-with-branch", }, Name: "workspace", }}, @@ -291,7 +250,7 @@ func TestAddResourceToBuild(t *testing.T) { Source: &buildv1alpha1.SourceSpec{ Git: &buildv1alpha1.GitSourceSpec{ Url: "https://github.com/grafeas/kritis", - Revision: "master", + Revision: "branch", }, }, }, @@ -346,7 +305,7 @@ func TestAddResourceToBuild(t *testing.T) { Name: "build-from-repo", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ Name: "target-cluster", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "cluster3", @@ -412,7 +371,7 @@ func TestAddResourceToBuild(t *testing.T) { Name: "build-from-repo", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ Name: "target-cluster", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "cluster2", diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go b/pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go index 6281c112319..0432597e09a 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go @@ -30,7 +30,7 @@ import ( var kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "override-with-kubeconfig-writer:latest", "The container image containing our kubeconfig writer binary.") -func getBoundResource(resourceName string, boundResources []v1alpha1.TaskRunResourceVersion) (*v1alpha1.TaskRunResourceVersion, error) { +func getBoundResource(resourceName string, boundResources []v1alpha1.TaskRunResource) (*v1alpha1.TaskRunResource, error) { for _, br := range boundResources { if br.Name == resourceName { return &br, nil @@ -71,9 +71,6 @@ func AddInputResource( if err != nil { return nil, fmt.Errorf("task %q invalid Pipeline Resource: %q", task.Name, boundResource.ResourceRef.Name) } - if boundResource.Version != "" { - gitResource.Revision = boundResource.Version - } gitSourceSpec := &buildv1alpha1.GitSourceSpec{ Url: gitResource.URL, Revision: gitResource.Revision, diff --git a/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go b/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go index 8a750d03eb7..3cdaeb3fbae 100644 --- a/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go @@ -261,25 +261,23 @@ func TestReconcile(t *testing.T) { Value: "foo", }, }, - Resources: []v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ { ResourceRef: v1alpha1.PipelineResourceRef{ Name: gitResource.Name, APIVersion: "a1", }, - Version: "myversion", - Name: "workspace", + Name: "workspace", }, }, }, Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResourceVersion{{ + Resources: []v1alpha1.TaskRunResource{{ ResourceRef: v1alpha1.PipelineResourceRef{ Name: "image-resource", APIVersion: "a1", }, - Version: "myversion", - Name: "myimage", + Name: "myimage", }}, }, }, @@ -300,14 +298,13 @@ func TestReconcile(t *testing.T) { Value: "foo", }, }, - Resources: []v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ { ResourceRef: v1alpha1.PipelineResourceRef{ Name: gitResource.Name, APIVersion: "a1", }, - Version: "myversion", - Name: gitResource.Name, + Name: gitResource.Name, }, }, }, @@ -323,14 +320,13 @@ func TestReconcile(t *testing.T) { APIVersion: "a1", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ { ResourceRef: v1alpha1.PipelineResourceRef{ Name: gitResource.Name, APIVersion: "a1", }, - Version: "myversion", - Name: gitResource.Name, + Name: gitResource.Name, }, }, }, @@ -405,7 +401,7 @@ func TestReconcile(t *testing.T) { Source: &buildv1alpha1.SourceSpec{ Git: &buildv1alpha1.GitSourceSpec{ Url: "https://foo.git", - Revision: "myversion", + Revision: "master", }, }, Steps: []corev1.Container{ diff --git a/pkg/reconciler/v1alpha1/taskrun/validate_test.go b/pkg/reconciler/v1alpha1/taskrun/validate_test.go index 579a4371939..3c6fd1bd1ad 100644 --- a/pkg/reconciler/v1alpha1/taskrun/validate_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/validate_test.go @@ -29,8 +29,8 @@ func Test_ValidTaskRunTask(t *testing.T) { Name: "task-valid-input", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ + v1alpha1.TaskRunResource{ Name: "resource-to-build", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "example-resource", @@ -115,8 +115,8 @@ func Test_InvalidTaskRunTask(t *testing.T) { Name: "unit-test-task", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ + v1alpha1.TaskRunResource{ Name: "test-resource-name", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "non-existent-resource1", @@ -135,8 +135,8 @@ func Test_InvalidTaskRunTask(t *testing.T) { Name: "unit-test-task", }, Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ + v1alpha1.TaskRunResource{ Name: "test-resource-name", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "non-existent-resource1", @@ -155,8 +155,8 @@ func Test_InvalidTaskRunTask(t *testing.T) { Name: "unit-test-wrong-input", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ + v1alpha1.TaskRunResource{ Name: "test-resource-name", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "non-existent", @@ -175,8 +175,8 @@ func Test_InvalidTaskRunTask(t *testing.T) { Name: "unit-test-task", }, Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ + v1alpha1.TaskRunResource{ Name: "test-resource-name", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "non-existent", @@ -213,8 +213,8 @@ func Test_InvalidTaskRunTask(t *testing.T) { Name: "unit-task-bad-resourcetype", }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ + v1alpha1.TaskRunResource{ Name: "testimageinput", ResourceRef: v1alpha1.PipelineResourceRef{ Name: "git-test-resource", diff --git a/test/cluster_resource_test.go b/test/cluster_resource_test.go index c20fecb5633..b418466106f 100644 --- a/test/cluster_resource_test.go +++ b/test/cluster_resource_test.go @@ -195,14 +195,12 @@ func getClusterResourceTaskRun(namespace, name, taskName, resName string) *v1alp }, }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ - { - Name: "target-cluster", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: resName, - }, + Resources: []v1alpha1.TaskRunResource{{ + Name: "target-cluster", + ResourceRef: v1alpha1.PipelineResourceRef{ + Name: resName, }, - }, + }}, }, }, } diff --git a/test/kaniko_task_test.go b/test/kaniko_task_test.go index e41fd8c75fb..c2a30e7f659 100644 --- a/test/kaniko_task_test.go +++ b/test/kaniko_task_test.go @@ -169,13 +169,12 @@ func getTaskRun(namespace string) *v1alpha1.TaskRun { }, }, Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResourceVersion{ + Resources: []v1alpha1.TaskRunResource{ { ResourceRef: v1alpha1.PipelineResourceRef{ Name: kanikoResourceName, }, - Version: "master", - Name: "workspace", + Name: "workspace", }, }, },