From 4d876daaa372936fbf280d6a875bf6c6ce2374b9 Mon Sep 17 00:00:00 2001 From: Jerome Ju Date: Wed, 1 Feb 2023 03:57:36 +0000 Subject: [PATCH] Remove Git and Storage PipelineResources This commit removes the Git and Storage Resources: - removes the Storage resources support at `pkg/apis/resource/v1alpha1/storage` - removes the `pkg/artifacts` - removes the Git resources support at `pkg/apis/resource/v1alpha1/git` - their corresponding unit test cases, examples and integration tests - the generic logics for input and output resources since `storage` and `git` resources are the only allowed types --- config/config-artifact-bucket.yaml | 33 - docs/resources.md | 278 --- docs/variables.md | 23 - .../pipelineruns/output-pipelinerun.yaml | 106 -- .../pipelinerun-with-resourcespec.yaml | 65 - examples/v1beta1/taskruns/gcs-resource.yaml | 26 - examples/v1beta1/taskruns/git-resource.yaml | 80 - .../git-ssh-creds-without-known_hosts.yaml | 52 - examples/v1beta1/taskruns/git-ssh-creds.yaml | 52 - .../optional-resources-with-clustertask.yaml | 36 - .../v1beta1/taskruns/optional-resources.yaml | 133 -- .../taskruns/task-multiple-output-image.yaml | 124 -- .../v1beta1/taskruns/task-output-image.yaml | 97 - hack/update-codegen.sh | 5 - pkg/apis/config/artifact_bucket.go | 112 -- pkg/apis/config/artifact_bucket_test.go | 103 -- pkg/apis/config/artifact_pvc.go | 86 - pkg/apis/config/artifact_pvc_test.go | 101 -- pkg/apis/config/store.go | 19 - pkg/apis/config/store_test.go | 12 - .../config-artifact-bucket-all-set.yaml | 24 - .../config-artifact-bucket-empty.yaml | 26 - .../testdata/config-artifact-bucket.yaml | 21 - .../testdata/config-artifact-pvc-all-set.yaml | 22 - .../testdata/config-artifact-pvc-empty.yaml | 26 - .../config/testdata/config-artifact-pvc.yaml | 21 - pkg/apis/config/zz_generated.deepcopy.go | 32 - .../v1beta1/pipeline_conversion_test.go | 8 +- .../v1beta1/pipeline_validation_test.go | 26 +- pkg/apis/pipeline/v1beta1/resource_types.go | 6 - .../pipeline/v1beta1/task_validation_test.go | 73 - .../v1beta1/taskrun_validation_test.go | 4 +- pkg/apis/resource/resource.go | 9 +- .../resource/v1alpha1/git/git_resource.go | 212 --- .../v1alpha1/git/git_resource_test.go | 912 ---------- .../v1alpha1/image/image_resource_test.go | 2 +- .../v1alpha1/pipeline_resource_types.go | 16 +- .../v1alpha1/pipelineresource_validation.go | 28 - .../pipelineresource_validation_test.go | 120 +- .../v1alpha1/storage/artifact_bucket.go | 103 -- .../v1alpha1/storage/artifact_bucket_test.go | 104 -- .../resource/v1alpha1/storage/artifact_pvc.go | 104 -- .../v1alpha1/storage/artifact_pvc_test.go | 128 -- pkg/apis/resource/v1alpha1/storage/gcs.go | 172 -- .../resource/v1alpha1/storage/gcs_test.go | 457 ----- pkg/apis/resource/v1alpha1/storage/secret.go | 60 - pkg/apis/resource/v1alpha1/storage/storage.go | 92 - .../v1alpha1/storage/zz_generated.deepcopy.go | 69 - pkg/artifacts/artifact_storage_test.go | 620 ------- pkg/artifacts/artifacts_storage.go | 244 --- pkg/pipelinerunmetrics/metrics_test.go | 2 +- pkg/reconciler/pipelinerun/pipelinerun.go | 27 +- .../pipelinerun/pipelinerun_test.go | 265 +-- .../resources/input_output_steps.go | 25 +- .../resources/input_output_steps_test.go | 148 +- .../resources/pipelinerunresolution_test.go | 38 +- .../resources/pipelinerunstate_test.go | 2 +- .../taskrun/resources/apply_test.go | 70 - .../taskrun/resources/input_resource_test.go | 1364 -------------- .../taskrun/resources/input_resources.go | 146 -- .../taskrun/resources/output_resource.go | 41 +- .../taskrun/resources/output_resource_test.go | 1601 +---------------- .../resources/taskresourceresolution_test.go | 69 +- pkg/reconciler/taskrun/resources/volume.go | 70 - .../taskrun/resources/volume_test.go | 38 - pkg/reconciler/taskrun/taskrun.go | 6 - pkg/reconciler/taskrun/taskrun_test.go | 280 +-- .../taskrun/validate_resources_test.go | 89 +- pkg/taskrunmetrics/metrics_test.go | 2 +- test/artifact_bucket_test.go | 358 ---- test/controller.go | 20 +- test/controller_test.go | 8 - test/conversion_test.go | 74 +- test/custom_task_test.go | 28 + test/dag_test.go | 85 +- test/embed_test.go | 115 -- test/git_checkout_test.go | 278 --- test/helm_task_test.go | 371 ---- test/kaniko_task_test.go | 256 --- test/ko_test.go | 53 - test/pipelinerun_test.go | 231 --- test/resolvers_test.go | 1 + 82 files changed, 233 insertions(+), 11212 deletions(-) delete mode 100644 config/config-artifact-bucket.yaml delete mode 100644 examples/v1beta1/pipelineruns/output-pipelinerun.yaml delete mode 100644 examples/v1beta1/pipelineruns/pipelinerun-with-resourcespec.yaml delete mode 100644 examples/v1beta1/taskruns/gcs-resource.yaml delete mode 100644 examples/v1beta1/taskruns/git-resource.yaml delete mode 100644 examples/v1beta1/taskruns/git-ssh-creds-without-known_hosts.yaml delete mode 100644 examples/v1beta1/taskruns/git-ssh-creds.yaml delete mode 100644 examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml delete mode 100644 examples/v1beta1/taskruns/optional-resources.yaml delete mode 100644 examples/v1beta1/taskruns/task-multiple-output-image.yaml delete mode 100644 examples/v1beta1/taskruns/task-output-image.yaml delete mode 100644 pkg/apis/config/artifact_bucket.go delete mode 100644 pkg/apis/config/artifact_bucket_test.go delete mode 100644 pkg/apis/config/artifact_pvc.go delete mode 100644 pkg/apis/config/artifact_pvc_test.go delete mode 100644 pkg/apis/config/testdata/config-artifact-bucket-all-set.yaml delete mode 100644 pkg/apis/config/testdata/config-artifact-bucket-empty.yaml delete mode 100644 pkg/apis/config/testdata/config-artifact-bucket.yaml delete mode 100644 pkg/apis/config/testdata/config-artifact-pvc-all-set.yaml delete mode 100644 pkg/apis/config/testdata/config-artifact-pvc-empty.yaml delete mode 100644 pkg/apis/config/testdata/config-artifact-pvc.yaml delete mode 100644 pkg/apis/resource/v1alpha1/git/git_resource.go delete mode 100644 pkg/apis/resource/v1alpha1/git/git_resource_test.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/artifact_bucket.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/artifact_pvc.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/gcs.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/gcs_test.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/secret.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/storage.go delete mode 100644 pkg/apis/resource/v1alpha1/storage/zz_generated.deepcopy.go delete mode 100644 pkg/artifacts/artifact_storage_test.go delete mode 100644 pkg/artifacts/artifacts_storage.go delete mode 100644 pkg/reconciler/taskrun/resources/input_resource_test.go delete mode 100644 pkg/reconciler/taskrun/resources/input_resources.go delete mode 100644 pkg/reconciler/taskrun/resources/volume.go delete mode 100644 pkg/reconciler/taskrun/resources/volume_test.go delete mode 100644 test/artifact_bucket_test.go delete mode 100644 test/embed_test.go delete mode 100644 test/git_checkout_test.go delete mode 100644 test/helm_task_test.go delete mode 100644 test/kaniko_task_test.go delete mode 100644 test/ko_test.go diff --git a/config/config-artifact-bucket.yaml b/config/config-artifact-bucket.yaml deleted file mode 100644 index 58e9693ce3d..00000000000 --- a/config/config-artifact-bucket.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-bucket - namespace: tekton-pipelines - labels: - app.kubernetes.io/instance: default - app.kubernetes.io/part-of: tekton-pipelines -# data: -# # location of the gcs bucket to be used for artifact storage -# location: "gs://bucket-name" -# # name of the secret that will contain the credentials for the service account -# # with access to the bucket -# bucket.service.account.secret.name: -# # The key in the secret with the required service account json -# bucket.service.account.secret.key: -# # The field name that should be used for the service account -# # Valid values: GOOGLE_APPLICATION_CREDENTIALS, BOTO_CONFIG. -# bucket.service.account.field.name: GOOGLE_APPLICATION_CREDENTIALS diff --git a/docs/resources.md b/docs/resources.md index 27e57289cba..d26bcf051b1 100644 --- a/docs/resources.md +++ b/docs/resources.md @@ -45,10 +45,7 @@ For example: - [Resource Status](#resource-status) - [Optional Resources](#optional-resources) - [Resource types](#resource-types) - - [Git Resource](#git-resource) - [Image Resource](#image-resource) - - [Storage Resource](#storage-resource) - - [GCS Storage Resource](#gcs-storage-resource) - [Why Aren't PipelineResources in Beta?](#why-aren-t-pipelineresources-in-beta) ## Syntax @@ -224,22 +221,6 @@ spec: emptyDir: {} ``` -### Resource Status - -When resources are bound inside a `TaskRun`, they can include extra information -in the `TaskRun` Status.ResourcesResult field. This information can be useful -for auditing the exact resources used by a `TaskRun` later. Currently the Image -and Git resources use this mechanism. - -For an example of what this output looks like: - -```yaml -resourcesResult: - - key: digest - value: sha256:a08412a4164b85ae521b0c00cf328e3aab30ba94a526821367534b81e51cb1cb - resourceName: skaffold-image-leeroy-web -``` - ### Description The `description` field is an optional field and can be used to provide description of the Resource. @@ -289,171 +270,6 @@ You can refer to different examples demonstrating usage of optional resources in ## Resource Types -### Git Resource - -The `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. - -To create a git resource using the `PipelineResource` CRD: - -```yaml -apiVersion: tekton.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, you can use this to - change the repo, e.g. [to use a fork](#using-a-fork) -1. `revision`: Git [revision][git-rev] (branch, tag, commit SHA or ref) to - clone. You can use this to control what commit [or branch](#using-a-branch) - is used. [git checkout][git-checkout] is used to switch to the - revision, and will result in a detached HEAD in most cases. Use refspec - along with revision if you want to checkout a particular branch without a - detached HEAD. _If no revision is specified, the resource inspects remote repository to determine the correct default branch._ -1. `refspec`: (Optional) specify a git [refspec][git-refspec] to pass to git-fetch. - Note that if this field is specified, it must specify all refs, branches, tags, - or commits required to checkout the specified `revision`. An additional fetch - will not be run to obtain the contents of the revision field. If no refspec - is specified, the value of the `revision` field will be fetched directly. - The refspec is useful in manipulating the repository in several cases: - * when the server does not support fetches via the commit SHA (i.e. does - not have `uploadpack.allowReachableSHA1InWant` enabled) and you want - to fetch and checkout a specific commit hash from a ref chain. - * when you want to fetch several other refs alongside your revision - (for instance, tags) - * when you want to checkout a specific branch, the revision and refspec - fields can work together to be able to set the destination of the incoming - branch and switch to the branch. - - Examples: - - Check out a specified revision commit SHA1 after fetching ref (detached)
-   `revision`: cb17eba165fe7973ef9afec20e7c6971565bd72f
-   `refspec`: refs/smoke/myref
- - Fetch all tags alongside refs/heads/master and switch to the master branch - (not detached)
-   `revision`: master
-   `refspec`: "refs/tags/\*:refs/tags/\* +refs/heads/master:refs/heads/master"
- - Fetch the develop branch and switch to it (not detached)
-   `revision`: develop
-   `refspec`: refs/heads/develop:refs/heads/develop
- - Fetch refs/pull/1009/head into the master branch and switch to it (not detached)
-   `revision`: master
-   `refspec`: refs/pull/1009/head:refs/heads/master
- -1. `submodules`: defines if the resource should initialize and fetch the - submodules, value is either `true` or `false`. _If not specified, this will - default to true_ -1. `depth`: performs a [shallow clone][git-depth] where only the most recent - commit(s) will be fetched. This setting also applies to submodules. If set to - `'0'`, all commits will be fetched. _If not specified, the default depth is 1._ -1. `sslVerify`: defines if [http.sslVerify][git-http.sslVerify] should be set - to `true` or `false` in the global git config. _Defaults to `true` if - omitted._ - -[git-rev]: https://git-scm.com/docs/gitrevisions#_specifying_revisions -[git-checkout]: https://git-scm.com/docs/git-checkout -[git-refspec]: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec -[git-depth]: https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt -[git-http.sslVerify]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-httpsslVerify - -When used as an input, the Git resource includes the exact commit fetched in the -`resourceResults` section of the `taskRun`'s status object: - -```yaml -resourceResults: - - key: commit - value: 6ed7aad5e8a36052ee5f6079fc91368e362121f7 - resourceName: skaffold-git -``` - -#### Using a fork - -The `Url` parameter can be used to point at any git repository, for example to -use a GitHub fork at master: - -```yaml -spec: - type: git - params: - - name: url - value: https://github.com/bobcatfish/wizzbang.git -``` - -#### Using a branch - -The `revision` can be any -[git commit-ish (revision)](https://git-scm.com/docs/gitrevisions#_specifying_revisions). -You can use this to create a git `PipelineResource` that points at a branch, for -example: - -```yaml -spec: - type: git - params: - - name: url - value: https://github.com/wizzbangcorp/wizzbang.git - - name: revision - value: some_awesome_feature -``` - -To point at a pull request, you can use -[the pull requests's branch](https://help.github.com/articles/checking-out-pull-requests-locally/): - -```yaml -spec: - type: git - params: - - name: url - value: https://github.com/wizzbangcorp/wizzbang.git - - name: revision - value: refs/pull/52525/head -``` - -#### Using HTTP/HTTPS Proxy - -The `httpProxy` and `httpsProxy` parameter can be used to proxy non-SSL/SSL requests, for example to use an enterprise -proxy server for SSL requests: - -```yaml -spec: - type: git - params: - - name: url - value: https://github.com/bobcatfish/wizzbang.git - - name: httpsProxy - value: "my-enterprise.proxy.com" -``` - -#### Using No Proxy - -The `noProxy` parameter can be used to opt out of proxying, for example, to not proxy HTTP/HTTPS requests to -`no.proxy.com`: - -```yaml -spec: - type: git - params: - - name: url - value: https://github.com/bobcatfish/wizzbang.git - - name: noProxy - value: "no.proxy.com" -``` - -Note: `httpProxy`, `httpsProxy`, and `noProxy` are all optional but no validation done if all three are specified. - ### Image Resource An `image` resource represents an image that lives in a remote repository. It is @@ -540,100 +356,6 @@ status: If the `index.json` file is not produced, the image digest will not be included in the `taskRun` output. -### Storage Resource - -The `storage` resource represents blob storage, that contains either an object -or directory. Adding the storage resource as an input to a `Task` will download -the blob and allow the `Task` to perform the required actions on the contents of -the blob. - -Only blob storage type -[Google Cloud Storage](https://cloud.google.com/storage/)(gcs) is supported as -of now via [GCS storage resource](#gcs-storage-resource). - -#### GCS Storage Resource - -The `gcs` storage resource points to -[Google Cloud Storage](https://cloud.google.com/storage/) blob. - -To create a GCS type of storage resource using the `PipelineResource` CRD: - -```yaml -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: wizzbang-storage - namespace: default -spec: - type: storage - params: - - name: type - value: gcs - - name: location - value: gs://some-bucket - - name: dir - value: "y" # This can have any value to be considered "true" -``` - -Params that can be added are the following: - -1. `location`: represents the location of the blob storage. -1. `type`: represents the type of blob storage. For GCS storage resource this - value should be set to `gcs`. -1. `dir`: represents whether the blob storage is a directory or not. By default - a storage artifact is not considered a directory. - - - If the artifact is a directory then `-r`(recursive) flag is used, to - copy all files under the source directory to a GCS bucket. Eg: `gsutil - cp -r source_dir/* gs://some-bucket` - - If an artifact is a single file like a zip or tar, then the copy will be - only 1 level deep(not recursive). It will not trigger a copy of sub - directories in the source directory. Eg: `gsutil cp source.tar - gs://some-bucket.tar`. - -Private buckets can also be configured as storage resources. To access GCS -private buckets, service accounts with correct permissions are required. The -`secrets` field on the storage resource is used for configuring this -information. Below is an example on how to create a storage resource with a -service account. - -1. Refer to the - [official documentation](https://cloud.google.com/compute/docs/access/service-accounts) - on how to create service accounts and configuring - [IAM permissions](https://cloud.google.com/storage/docs/access-control/iam-permissions) - to access buckets. - -1. Create a Kubernetes secret from a downloaded service account json key - - ```bash - kubectl create secret generic bucket-sa --from-file=./service_account.json - ``` - -1. To access the GCS private bucket environment variable - [`GOOGLE_APPLICATION_CREDENTIALS`](https://cloud.google.com/docs/authentication/production) - should be set, so apply the above created secret to the GCS storage resource - under the `fieldName` key. - - ```yaml - apiVersion: tekton.dev/v1alpha1 - kind: PipelineResource - metadata: - name: wizzbang-storage - namespace: default - spec: - type: storage - params: - - name: type - value: gcs - - name: location - value: gs://some-private-bucket - - name: dir - value: "y" - secrets: - - fieldName: GOOGLE_APPLICATION_CREDENTIALS - secretName: bucket-sa - secretKey: service_account.json - ``` -------------------------------------------------------------------------------- diff --git a/docs/variables.md b/docs/variables.md index d8dd1f42237..134eb1283b7 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -84,21 +84,6 @@ of variables. This section lists the variables exposed by each type. You can acc variable via `resources.inputs..` or `resources.outputs..`. -#### Variables for the `Git` type - -| Variable | Description | -| -------- | ----------- | -| `name` | The name of the resource. | -| `type` | Type value of `"git"`. | -| `url` | The URL of the Git repository. | -| `revision` | The revision to check out. | -| `refspec` | The value of the resource's `refspec` parameter. | -| `depth` | The integer value of the resource's `depth` parameter. | -| `sslVerify` | The value of the resource's `sslVerify` parameter, either `"true"` or `"false"`. | -| `httpProxy` | The value of the resource's `httpProxy` parameter. | -| `httpsProxy` | The value of the resource's `httpsProxy` parameter. | -| `noProxy` | The value of the resource's `noProxy` parameter. | - #### Variables for the `Image` type | Variable | Description | @@ -108,14 +93,6 @@ variable via `resources.inputs..` or | `url` | The complete path to the image. | | `digest` | The digest of the image. | -#### Variables for the `GCS` type - -| Variable | Description | -| -------- | ----------- | -| `name` | The name of the resource. | -| `type` | Type value of `"gcs"`. | -| `location` | The fully qualified address of the blob storage. | - #### Variables for the `Cluster` type | Variable | Description | diff --git a/examples/v1beta1/pipelineruns/output-pipelinerun.yaml b/examples/v1beta1/pipelineruns/output-pipelinerun.yaml deleted file mode 100644 index b4ab5803756..00000000000 --- a/examples/v1beta1/pipelineruns/output-pipelinerun.yaml +++ /dev/null @@ -1,106 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-git-output-pipelinerun -spec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# Task writes "some stuff" to a predefined path in the workspace git PipelineResource -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: create-file -spec: - resources: - inputs: - - name: workspace - type: git - targetPath: damnworkspace - outputs: - - name: workspace - type: git - steps: - - name: read-docs-old - image: ubuntu - command: ["/bin/bash"] - args: ['-c', 'ls -la /workspace/damnworkspace/docs/README.md'] # tests that targetpath works - - name: write-new-stuff - image: ubuntu - command: ['bash'] - args: ['-c', 'ln -s /workspace/damnworkspace /workspace/output/workspace && echo some stuff > /workspace/output/workspace/stuff'] ---- -# Reads a file from a predefined path in the workspace git PipelineResource -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: check-stuff-file-exists -spec: - params: - - name: args - type: array - resources: - inputs: - - name: workspace - type: git - targetPath: newworkspace - steps: - - name: read - image: ubuntu - command: ["/bin/bash"] - args: ['$(inputs.params.args[*])'] # tests that new targetpath and previous task output is dumped ---- -# The Output of the first Task (git resource) create-file is given as an `Input` -# to the next `Task` check-stuff-file-exists using`from` clause. - -apiVersion: tekton.dev/v1beta1 -kind: Pipeline -metadata: - name: output-pipeline -spec: - resources: - - name: source-repo - type: git - tasks: - - name: first-create-file # 1. create file - taskRef: - name: create-file - resources: - inputs: - - name: workspace - resource: source-repo - outputs: - - name: workspace - resource: source-repo - - name: then-check # 2. check file exists - taskRef: - name: check-stuff-file-exists - params: - - name: args - value: - - '-c' - - 'cat /workspace/newworkspace/stuff' - resources: - inputs: - - name: workspace - resource: source-repo - from: [first-create-file] ---- -apiVersion: tekton.dev/v1beta1 -kind: PipelineRun -metadata: - name: output-pipeline-run -spec: - pipelineRef: - name: output-pipeline - serviceAccountName: 'default' - resources: - - name: source-repo - resourceRef: - name: skaffold-git-output-pipelinerun diff --git a/examples/v1beta1/pipelineruns/pipelinerun-with-resourcespec.yaml b/examples/v1beta1/pipelineruns/pipelinerun-with-resourcespec.yaml deleted file mode 100644 index 0020987fde8..00000000000 --- a/examples/v1beta1/pipelineruns/pipelinerun-with-resourcespec.yaml +++ /dev/null @@ -1,65 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: task-to-list-files -spec: - resources: - inputs: - - name: pipeline-git - type: git - outputs: - - name: pipeline-git - type: git - steps: - - name: list - image: ubuntu - command: - - bash - args: - - -c - - | - ls -al $(resources.inputs.pipeline-git.path) ---- - -apiVersion: tekton.dev/v1beta1 -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 ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: PipelineRun -metadata: - name: demo-pipelinerun-with-resourcespec -spec: - pipelineRef: - name: pipeline-to-list-files - serviceAccountName: 'default' - resources: - - name: pipeline-git - resourceSpec: - type: git - params: - - name: revision - value: main - - name: url - value: https://github.com/tektoncd/pipeline diff --git a/examples/v1beta1/taskruns/gcs-resource.yaml b/examples/v1beta1/taskruns/gcs-resource.yaml deleted file mode 100644 index 1accc4a18ab..00000000000 --- a/examples/v1beta1/taskruns/gcs-resource.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - generateName: gcs-resource- -spec: - taskSpec: - resources: - inputs: - - name: source - type: storage - steps: - - image: alpine - workingDir: /workspace - script: unzip source/archive.zip && cat file.txt - resources: - inputs: - - name: source - resourceSpec: - type: storage - params: - - name: location - value: gs://build-crd-tests/archive.zip - - name: type - value: gcs diff --git a/examples/v1beta1/taskruns/git-resource.yaml b/examples/v1beta1/taskruns/git-resource.yaml deleted file mode 100644 index ae8b535ebb6..00000000000 --- a/examples/v1beta1/taskruns/git-resource.yaml +++ /dev/null @@ -1,80 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - generateName: git-resource-tag- -spec: - taskSpec: - resources: - inputs: - - name: skaffold - type: git - steps: - - image: ubuntu - workingDir: /workspace - script: cat skaffold/README.md - resources: - inputs: - - name: skaffold - resourceSpec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - generateName: git-resource-branch- -spec: - taskSpec: - resources: - inputs: - - name: skaffold - type: git - steps: - - image: ubuntu - workingDir: /workspace - script: cat skaffold/README.md - resources: - inputs: - - name: skaffold - resourceSpec: - type: git - params: - - name: revision - value: master - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - generateName: git-resource-ref- -spec: - taskSpec: - resources: - inputs: - - name: skaffold - type: git - steps: - - image: ubuntu - workingDir: /workspace - script: cat skaffold/README.md - resources: - inputs: - - name: skaffold - resourceSpec: - type: git - params: - - name: revision - value: pull/2932/head - - name: url - value: https://github.com/GoogleContainerTools/skaffold diff --git a/examples/v1beta1/taskruns/git-ssh-creds-without-known_hosts.yaml b/examples/v1beta1/taskruns/git-ssh-creds-without-known_hosts.yaml deleted file mode 100644 index 812190d9880..00000000000 --- a/examples/v1beta1/taskruns/git-ssh-creds-without-known_hosts.yaml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: git-ssh-without-known-hosts - annotations: - tekton.dev/git-0: github.com -type: kubernetes.io/ssh-auth -data: - # Generated by: - # cat id_rsa | base64 -w 0 - # This deploy key has read-only permissions on github.com/knative/build - ssh-privatekey: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlKSndJQkFBS0NBZ0VBc0YrY3ZIdUlKRjBwNWZNVDBUUVZhMWpTZVBNVlhtUWhGa1F0andsamJFSXVKaVh5CmVrU1I0WUtDbFZIZVo0M2VOa2p5SzFwTDVmVnZnY3J2bkVUMXE5dmFmOThtNzdHWjZUdnJGY0RyZjViZDFIZGUKTU1MTFZRRU8vN1lkcEJFeVJ1UjA4RXRzbWp0RUVaNERVZnBUWGQ5RnAyTU5UWTYwVzFpa0p0Mm53dGhWVlF0OApubFcxTTRvc1d0SHE1OVFDbnhqUkVmNzNhdHdtUTZ6enlXcCtJM3ZBRFRJUmZpTWcvSjc0UDJHOWlwL0U1U0YrCnNuRmRnU2x0cjhyd0tmTE5jTDVYandOSE53aHErQ2NJRHBUZGhuVTBUaEFZNlRsa25KWFJudXRicGNRajA4MjAKMyt1aXRxaXhJcnIwQmkrU2NDQ21GNERxZGdRUXIwRzdieXRKemJkdjJOL3dGbGFpWmVOTWtXSVd5TzRpdnU4TQoxbGUyajVHeDZFaVQ0TG5sNitoRHd3aXozUGR4Y1I0S0VxZzVqRmQ3QjNDcHQ0cUswRDFHVVhnMmx1ZHRsMU40CjVoNUJaNEZZcWF0VU1LQkVjeHd4ekZVVE1iNFZmdFhuMEJOSHkyVXlxUkx6VnBMZWgyRHRYcmtaZnRnTlFCeFAKNkNKc2FnYkpuRmZ1Mk1IaTh5VkE3UFZnUXExS3hPWnF0c0JKb3RvSzJXb0lONldpbnl0d0lwUFhsblJrZ3duYgo4dVBZdmhoZDB0ZVllZ2pYNW85azcwaDhFOEFpZGtqaFpKRkwzakRjc0NFdGJQSWtBMHp3bCs0UFN5aWV2UXpVCldFTkFTSzhXc1NxSk40bUtNSEJMbDU2WWZpTnBJNXVEUGx6eC9hS3hnQis2RExYL25GRzB0Y2ZTYlJFQ0F3RUEKQVFLQ0FnQnRjQlpZR2FxakxhK213RXFHbi9PK2RSRzcvTkZBalk2K096V3RzRnlodXZyWnJ1Z2pGOU1SQTZNMQpOZVJ6aXVMYitpMVIyeWlIR3VEQ3Y0SW9DOTRJY2xYRXpGbGpsMmJ5QXJ6ZTlhTHF1MWtQMGJWL09nOWl3bEpsCk5zSnpvRHY3SXh5d1VZeWtzcXVNNXVnV2dPWWp0RHVMSG5vTnFzT2Nmb2IwbXNyU3F0dGY5czJ2ald6dSt3aUUKbmdaTkxROG5Xd1czVGVhRnh1NXpSYWpMVEtuU0tLSkZUZER1M0t0R05QbkNra3BDN3RvRWR1RWZwaG9uMytYdwprMUtzSkwxMi9KUmw1OW5UZXdTc3o4TS9FUDNYeFhmY0RENzQwQ1R1eUVPV2dXR1BuUUhDRmJ6cXlGSmhWcEQ3CkJOZ1Awb3JoeWxCayt4Z0FmSXRCdzk2aW4xQ2VMZHZKek9TdDNXSUVrY0w3ZVB0bkpzWVpBa1J4eFU1NWF6ajEKbFJHNWRWN010ZzgwWXJTcDdoYXIxamhTQ0JjVzZMUHdueTdXK1psWEd6VG9Gb1o2clIwdytJdGRjNGpPSEhtTgpRVk9tWFd3SFJuZm5rQWZlNXdDQkZQbXpMT2tYbnloWjdaNWxmVlJQaE9lT0hlV09NeHJvWFZoRmJPcTFxemo1Cm85a1dMVGxwTk42YXhrOW41R1N6NlZDVDRHSW1iOUsyWmpQUklOMktQZ3Vxd0RRSFVmd0ViZ0NnTkVUOG5wc2UKelYxRnRpRUJaeVJPa2RwdDhDd2NrbGxHc0Nab0dIa3Z1OXlRSytMUldvV2xJS041WGJXYVljaW01VVhIZlIzUgp4ZGx2QmgxNDl2MW02Y3haMWpzNUFJM09Xb0lpaXlaWjdKUGUxbUIycDE2dUlsUGhsUUtDQVFFQTRNZmNPRVluCkdrQVEzaEdKMm5ia0ZzZ1hJemJrQkQvanIrY1JHd1pjeitBZ2x0cXFZRnQ2Rzh3eElBMGd2V1BLNDFhR1UzU1AKdHVjUEF6VjVEYlR3WklFdjVpY3kycHJlbHJ1ZTB4RkV4WWRZNFFCVGRiVFM4TE9ZWncxTEZpTGRXb1VKVlhiWApTaE4rSktpSDVpM3J1K2dwTHArT0ZHUSthWFdQSFp0TjdjTUZidEpUUkNQUlZqUkVHb25qejY3c2NNcWxZNjAyCkYxaFlURGRkTGNnNnhiN0M3ZmdXc25pdEh4ZWY5UHZFUlZSUWdyRW9RT3lOcFczL0VOU1RQN1IzTzhnNnNHTXYKUXI4SDd1a3RGUlAxUVRqSGNvdmtrdm9aaERHOHRGREd4T0FhbFMxK2phQVpBMmNVdEI4VU5ueHpqMFJFNE43VAp3OHZST3NHbjJ2aG9vd0tDQVFFQXlONmV1d0FFdllpanVlV21pYWNJTUQ0bExaL3JjLzF6T0RUQ3grWm05SHBCCjZyUGMvMG8yR3lGV2Y2aVN3UjhOWlVyM2dvREh6ck8vTHdZUTNyUEhhZFpkRGRFVWh5UXBHeDFuOG9ONXhSU0sKVkVkdnVESkF4SnhHdXRWYk9sNzlDUitadjBqa3hGY2xaOTBaSGdhVEl5TnBlK1dIcTI3Mm1oaENaOXNmK0RTMgppM2V2MEkrQ0t6eXppV2NUdzJKL0ROSlpIN0ZnUlc0U1M3OXBLcDFPOXk0a2hQMk0xQU9nVUp4eFBta0xMc05oCk45dlB0QmpXMENZZmxiei9zWjBYZEVtL1hEUE9xNWVXc0tsZm5XcnpzR3ZZVHRvZkxpN1pVekJhMjRyc1AzT3UKT0JqeFVQWDBhTnQ2bVlOSWVSQkNkVk9BZlFsbGFqSW1hVENNNXZQcXV3S0NBUUF1RXFrZjI3aytGeTJkNXVoagpvQVRtYW9MYmsrK3VzMDIvQzFTbFBtdWRyQ25oNGRZVVJBdkdVTmNzNDZQM1RkSVRRUFB0ZlRITDRwWmdLUUN6Ci80ZGFnbVJILzNiYitleHY1dXNLQmpzYlpiK2c5c2tra2ppK1g0RjRkZkFUREhoa2ltbzhXMHlMZ1cxVXBEcWUKd29EVUZpVUN5bTk3M0lReVo0YzdJVThhMGVOMk1LUWlqbGpsRzNkdUhSOVZ2VnYzVG9JUjZUbnlGUWljTHFqcApybVhsakZFMko2aTNVaWJoL1p5cXdVUWNsY2llMFNNWUU2U0E2UWZqOGo1d1MxUTVLN1JqM1NDZHhMd2lpeWJUCmNERFArb3hlL1MrUHRMV3dNK1dpNi8raDhQRmg3RjVKTnl5SlZ3S1dYTnh1d3BtSkh3d2pMMmttYzh0aUNMbVkKRjF5VEFvSUJBRWpJdWRWaW5WVWNKTTlnVW1jQWVpd1k2Sm5PbjU5bzBBNG11QWw5Q0FOQUpaQm8yZ1E3SEwzWgo1NkRjTVVqKytuaWdvR3pPUXhnMzgyZVRtQnRLSTFETFZ1NkJ1eUY0emRoQVlJRDBlUFFiakVBYm5uU3M2T0VWCkMxLzVuVlBhUlcrLzNwTDhVOEI5SDFXeVBMNnZmVE0zU3FxVk1nTEJjMlBFdEpNelNETkV6bnhjd3YwY2N2czkKeElSZU1FQVUrWnBvd2RpRkNqQStRU3puVDdFY1RSZXR4WmZXMCtlaTVMMHc0cXZObmpxMG13NkZmSTV5amF2ZwpsSU5LZDVBaEx2VjVIM2pHWVBXMk9Pa01obFBoQkNvQitlQWdrem5GeWdPbHV0WmdVVmh3ajBsT2FHcUFwSzQyCkVRZDlGWTZnZ0tSSXZIOFNINGhLWWJhdDIvQjNvNjhDZ2dFQVNnUGZubVdZcXpQTlpwYXh4VFZ3NXl0cXovMGcKUHlhcW41elhDSHFsdDluNkZFYWdRVjE4bjl0bUZzTWtnOFd4MHp1TjY5ajNvcXVDaWVDSkVRTTFDR05GUWg2MQpEV0xrd210R1FPNXZxc0VhcXpLZk9yWktnYTJ5L3BuejY2SkNlUW83UlJEdVVZVHpPY3NpQmtxNmNUNHFLQjY0ClBCVlVhQTROQkVCZlRoc1o5dDhpWHFDQWhUQnVlTDdhQ3pHV0ZjR1k5dndrZkJHNjNacURXbVlqZkZwRGlqSWIKL21ySnJVTTB0a09HcUhESk5aUWhpZXc1VHF6NWp3VElyTDY3YUdZNFpuNEVyODFlb3JOZnpEeDVnak1NYnoweQoyTGZoN1c0MFlWMDA4ZmZJTk5BbXA4VjNqay9qcWFUSFlWYlFQNGxhdTRIWkc5Q2g1Q1VpSmFvN2xBPT0KLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0K - # Note: We are not including a known_hosts entry here. This forces - # the Git PipelineResource to accept github's public key the first - # time it fetches the repository. ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: robot-git-ssh-without-known-hosts -secrets: -- name: git-ssh-without-known-hosts ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: git-ssh-creds-without-known-hosts -spec: - serviceAccountName: robot-git-ssh-without-known-hosts - resources: - inputs: - - name: gitssh - resourceSpec: - type: git - params: - - name: revision - value: main - - name: url - value: git@github.com:tektoncd/pipeline.git - taskSpec: - resources: - inputs: - - name: gitssh - type: git - steps: - - name: config - image: ubuntu - script: | - #!/usr/bin/env bash - cat /workspace/gitssh/README.md diff --git a/examples/v1beta1/taskruns/git-ssh-creds.yaml b/examples/v1beta1/taskruns/git-ssh-creds.yaml deleted file mode 100644 index 56eeed19bc8..00000000000 --- a/examples/v1beta1/taskruns/git-ssh-creds.yaml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: git-ssh - annotations: - tekton.dev/git-0: github.com -type: kubernetes.io/ssh-auth -data: - # Generated by: - # cat id_rsa | base64 -w 0 - # This deploy key has read-only permissions on github.com/knative/build - ssh-privatekey: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlKSndJQkFBS0NBZ0VBc0YrY3ZIdUlKRjBwNWZNVDBUUVZhMWpTZVBNVlhtUWhGa1F0andsamJFSXVKaVh5CmVrU1I0WUtDbFZIZVo0M2VOa2p5SzFwTDVmVnZnY3J2bkVUMXE5dmFmOThtNzdHWjZUdnJGY0RyZjViZDFIZGUKTU1MTFZRRU8vN1lkcEJFeVJ1UjA4RXRzbWp0RUVaNERVZnBUWGQ5RnAyTU5UWTYwVzFpa0p0Mm53dGhWVlF0OApubFcxTTRvc1d0SHE1OVFDbnhqUkVmNzNhdHdtUTZ6enlXcCtJM3ZBRFRJUmZpTWcvSjc0UDJHOWlwL0U1U0YrCnNuRmRnU2x0cjhyd0tmTE5jTDVYandOSE53aHErQ2NJRHBUZGhuVTBUaEFZNlRsa25KWFJudXRicGNRajA4MjAKMyt1aXRxaXhJcnIwQmkrU2NDQ21GNERxZGdRUXIwRzdieXRKemJkdjJOL3dGbGFpWmVOTWtXSVd5TzRpdnU4TQoxbGUyajVHeDZFaVQ0TG5sNitoRHd3aXozUGR4Y1I0S0VxZzVqRmQ3QjNDcHQ0cUswRDFHVVhnMmx1ZHRsMU40CjVoNUJaNEZZcWF0VU1LQkVjeHd4ekZVVE1iNFZmdFhuMEJOSHkyVXlxUkx6VnBMZWgyRHRYcmtaZnRnTlFCeFAKNkNKc2FnYkpuRmZ1Mk1IaTh5VkE3UFZnUXExS3hPWnF0c0JKb3RvSzJXb0lONldpbnl0d0lwUFhsblJrZ3duYgo4dVBZdmhoZDB0ZVllZ2pYNW85azcwaDhFOEFpZGtqaFpKRkwzakRjc0NFdGJQSWtBMHp3bCs0UFN5aWV2UXpVCldFTkFTSzhXc1NxSk40bUtNSEJMbDU2WWZpTnBJNXVEUGx6eC9hS3hnQis2RExYL25GRzB0Y2ZTYlJFQ0F3RUEKQVFLQ0FnQnRjQlpZR2FxakxhK213RXFHbi9PK2RSRzcvTkZBalk2K096V3RzRnlodXZyWnJ1Z2pGOU1SQTZNMQpOZVJ6aXVMYitpMVIyeWlIR3VEQ3Y0SW9DOTRJY2xYRXpGbGpsMmJ5QXJ6ZTlhTHF1MWtQMGJWL09nOWl3bEpsCk5zSnpvRHY3SXh5d1VZeWtzcXVNNXVnV2dPWWp0RHVMSG5vTnFzT2Nmb2IwbXNyU3F0dGY5czJ2ald6dSt3aUUKbmdaTkxROG5Xd1czVGVhRnh1NXpSYWpMVEtuU0tLSkZUZER1M0t0R05QbkNra3BDN3RvRWR1RWZwaG9uMytYdwprMUtzSkwxMi9KUmw1OW5UZXdTc3o4TS9FUDNYeFhmY0RENzQwQ1R1eUVPV2dXR1BuUUhDRmJ6cXlGSmhWcEQ3CkJOZ1Awb3JoeWxCayt4Z0FmSXRCdzk2aW4xQ2VMZHZKek9TdDNXSUVrY0w3ZVB0bkpzWVpBa1J4eFU1NWF6ajEKbFJHNWRWN010ZzgwWXJTcDdoYXIxamhTQ0JjVzZMUHdueTdXK1psWEd6VG9Gb1o2clIwdytJdGRjNGpPSEhtTgpRVk9tWFd3SFJuZm5rQWZlNXdDQkZQbXpMT2tYbnloWjdaNWxmVlJQaE9lT0hlV09NeHJvWFZoRmJPcTFxemo1Cm85a1dMVGxwTk42YXhrOW41R1N6NlZDVDRHSW1iOUsyWmpQUklOMktQZ3Vxd0RRSFVmd0ViZ0NnTkVUOG5wc2UKelYxRnRpRUJaeVJPa2RwdDhDd2NrbGxHc0Nab0dIa3Z1OXlRSytMUldvV2xJS041WGJXYVljaW01VVhIZlIzUgp4ZGx2QmgxNDl2MW02Y3haMWpzNUFJM09Xb0lpaXlaWjdKUGUxbUIycDE2dUlsUGhsUUtDQVFFQTRNZmNPRVluCkdrQVEzaEdKMm5ia0ZzZ1hJemJrQkQvanIrY1JHd1pjeitBZ2x0cXFZRnQ2Rzh3eElBMGd2V1BLNDFhR1UzU1AKdHVjUEF6VjVEYlR3WklFdjVpY3kycHJlbHJ1ZTB4RkV4WWRZNFFCVGRiVFM4TE9ZWncxTEZpTGRXb1VKVlhiWApTaE4rSktpSDVpM3J1K2dwTHArT0ZHUSthWFdQSFp0TjdjTUZidEpUUkNQUlZqUkVHb25qejY3c2NNcWxZNjAyCkYxaFlURGRkTGNnNnhiN0M3ZmdXc25pdEh4ZWY5UHZFUlZSUWdyRW9RT3lOcFczL0VOU1RQN1IzTzhnNnNHTXYKUXI4SDd1a3RGUlAxUVRqSGNvdmtrdm9aaERHOHRGREd4T0FhbFMxK2phQVpBMmNVdEI4VU5ueHpqMFJFNE43VAp3OHZST3NHbjJ2aG9vd0tDQVFFQXlONmV1d0FFdllpanVlV21pYWNJTUQ0bExaL3JjLzF6T0RUQ3grWm05SHBCCjZyUGMvMG8yR3lGV2Y2aVN3UjhOWlVyM2dvREh6ck8vTHdZUTNyUEhhZFpkRGRFVWh5UXBHeDFuOG9ONXhSU0sKVkVkdnVESkF4SnhHdXRWYk9sNzlDUitadjBqa3hGY2xaOTBaSGdhVEl5TnBlK1dIcTI3Mm1oaENaOXNmK0RTMgppM2V2MEkrQ0t6eXppV2NUdzJKL0ROSlpIN0ZnUlc0U1M3OXBLcDFPOXk0a2hQMk0xQU9nVUp4eFBta0xMc05oCk45dlB0QmpXMENZZmxiei9zWjBYZEVtL1hEUE9xNWVXc0tsZm5XcnpzR3ZZVHRvZkxpN1pVekJhMjRyc1AzT3UKT0JqeFVQWDBhTnQ2bVlOSWVSQkNkVk9BZlFsbGFqSW1hVENNNXZQcXV3S0NBUUF1RXFrZjI3aytGeTJkNXVoagpvQVRtYW9MYmsrK3VzMDIvQzFTbFBtdWRyQ25oNGRZVVJBdkdVTmNzNDZQM1RkSVRRUFB0ZlRITDRwWmdLUUN6Ci80ZGFnbVJILzNiYitleHY1dXNLQmpzYlpiK2c5c2tra2ppK1g0RjRkZkFUREhoa2ltbzhXMHlMZ1cxVXBEcWUKd29EVUZpVUN5bTk3M0lReVo0YzdJVThhMGVOMk1LUWlqbGpsRzNkdUhSOVZ2VnYzVG9JUjZUbnlGUWljTHFqcApybVhsakZFMko2aTNVaWJoL1p5cXdVUWNsY2llMFNNWUU2U0E2UWZqOGo1d1MxUTVLN1JqM1NDZHhMd2lpeWJUCmNERFArb3hlL1MrUHRMV3dNK1dpNi8raDhQRmg3RjVKTnl5SlZ3S1dYTnh1d3BtSkh3d2pMMmttYzh0aUNMbVkKRjF5VEFvSUJBRWpJdWRWaW5WVWNKTTlnVW1jQWVpd1k2Sm5PbjU5bzBBNG11QWw5Q0FOQUpaQm8yZ1E3SEwzWgo1NkRjTVVqKytuaWdvR3pPUXhnMzgyZVRtQnRLSTFETFZ1NkJ1eUY0emRoQVlJRDBlUFFiakVBYm5uU3M2T0VWCkMxLzVuVlBhUlcrLzNwTDhVOEI5SDFXeVBMNnZmVE0zU3FxVk1nTEJjMlBFdEpNelNETkV6bnhjd3YwY2N2czkKeElSZU1FQVUrWnBvd2RpRkNqQStRU3puVDdFY1RSZXR4WmZXMCtlaTVMMHc0cXZObmpxMG13NkZmSTV5amF2ZwpsSU5LZDVBaEx2VjVIM2pHWVBXMk9Pa01obFBoQkNvQitlQWdrem5GeWdPbHV0WmdVVmh3ajBsT2FHcUFwSzQyCkVRZDlGWTZnZ0tSSXZIOFNINGhLWWJhdDIvQjNvNjhDZ2dFQVNnUGZubVdZcXpQTlpwYXh4VFZ3NXl0cXovMGcKUHlhcW41elhDSHFsdDluNkZFYWdRVjE4bjl0bUZzTWtnOFd4MHp1TjY5ajNvcXVDaWVDSkVRTTFDR05GUWg2MQpEV0xrd210R1FPNXZxc0VhcXpLZk9yWktnYTJ5L3BuejY2SkNlUW83UlJEdVVZVHpPY3NpQmtxNmNUNHFLQjY0ClBCVlVhQTROQkVCZlRoc1o5dDhpWHFDQWhUQnVlTDdhQ3pHV0ZjR1k5dndrZkJHNjNacURXbVlqZkZwRGlqSWIKL21ySnJVTTB0a09HcUhESk5aUWhpZXc1VHF6NWp3VElyTDY3YUdZNFpuNEVyODFlb3JOZnpEeDVnak1NYnoweQoyTGZoN1c0MFlWMDA4ZmZJTk5BbXA4VjNqay9qcWFUSFlWYlFQNGxhdTRIWkc5Q2g1Q1VpSmFvN2xBPT0KLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0K - # Generated by: - # ssh-keyscan github.com | base64 -w 0 - known_hosts: Z2l0aHViLmNvbSBzc2gtcnNhIEFBQUFCM056YUMxeWMyRUFBQUFCSXdBQUFRRUFxMkE3aFJHbWRubTl0VURiTzlJRFN3Qks2VGJRYStQWFlQQ1B5NnJiVHJUdHc3UEhrY2NLcnBwMHlWaHA1SGRFSWNLcjZwTGxWREJmT0xYOVFVc3lDT1Ywd3pmaklKTmxHRVlzZGxMSml6SGhibjJtVWp2U0FIUXFaRVRZUDgxZUZ6TFFOblBIdDRFVlZVaDdWZkRFU1U4NEtlem1ENVFsV3BYTG12VTMxL3lNZitTZTh4aEhUdktTQ1pJRkltV3dvRzZtYlVvV2Y5bnpwSW9hU2pCK3dlcXFVVW1wYWFhc1hWYWw3MkorVVgyQisyUlBXM1JjVDBlT3pRZ3FsSkwzUktyVEp2ZHNqRTNKRUF2R3EzbEdIU1pYeTI4RzNza3VhMlNtVmkvdzR5Q0U2Z2JPRHFuVFdsZzcrd0M2MDR5ZEdYQThWSmlTNWFwNDNKWGlVRkZBYVE9PQo= ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: robot-git-ssh -secrets: -- name: git-ssh ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: git-ssh-creds -spec: - serviceAccountName: robot-git-ssh - resources: - inputs: - - name: gitssh - resourceSpec: - type: git - params: - - name: revision - value: main - - name: url - value: git@github.com:tektoncd/pipeline.git - taskSpec: - resources: - inputs: - - name: gitssh - type: git - steps: - - name: config - image: ubuntu - script: | - #!/usr/bin/env bash - cat /workspace/gitssh/README.md diff --git a/examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml b/examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml deleted file mode 100644 index 469060123ec..00000000000 --- a/examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Note: ClusterTasks are deprecated. Please use the cluster resolver instead. -# https://github.com/tektoncd/pipeline/blob/main/docs/cluster-resolver.md -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -metadata: - name: clustertask-with-optional-resources-v1beta1 -spec: - params: - - name: filename - type: string - default: "README.md" - resources: - inputs: - - name: git-repo - type: git - optional: true - outputs: - - name: optionalimage - type: image - optional: true - steps: - - name: task-echo-success - image: ubuntu - script: | - #!/usr/bin/env bash - echo "success" ---- - -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: clustertask-without-resources -spec: - taskRef: - name: clustertask-with-optional-resources-v1beta1 - kind: ClusterTask diff --git a/examples/v1beta1/taskruns/optional-resources.yaml b/examples/v1beta1/taskruns/optional-resources.yaml deleted file mode 100644 index a5a055eb20a..00000000000 --- a/examples/v1beta1/taskruns/optional-resources.yaml +++ /dev/null @@ -1,133 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: task-check-optional-resources -spec: - params: - - name: filename - type: string - default: "README.md" - resources: - inputs: - - name: git-repo - type: git - description: "The input is code from a git repository" - optional: true - outputs: - - name: optionalimage - type: image - description: "The output is a Docker image" - optional: true - steps: - - name: check-git-repo - image: ubuntu - script: | - #!/usr/bin/env bash - if [ -d $(resources.inputs.git-repo.path) ]; then - echo "Git repo was cloned at $(resources.inputs.git-repo.path)" - if [ -f $(resources.inputs.git-repo.path)/$(inputs.params.filename) ]; then - echo "$(inputs.params.filename) does exist at $(resources.inputs.git-repo.path)" - else - echo "$(inputs.params.filename) does not exist at $(resources.inputs.git-repo.path)" - fi - else - echo "Git repo was not cloned at $(resources.inputs.git-repo.path)" - fi - if [ "$(outputs.resources.optionalimage.url)" != "" ]; then - echo "Image URL: $(outputs.resources.optionalimage.url)" - else - echo "No image URL specified." - fi - echo "Yay, Input and Output Resources can be Optional!" ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-with-resources -spec: - params: - - name: filename - value: "README.md" - resources: - inputs: - - name: git-repo - resourceSpec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline.git - outputs: - - name: optionalimage - resourceSpec: - type: image - params: - - name: url - value: gcr.io/foo/bar - taskRef: - name: task-check-optional-resources ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-invalid-filename -spec: - params: - - name: filename - value: "invalid.md" - resources: - inputs: - - name: git-repo - resourceSpec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline.git - taskRef: - name: task-check-optional-resources ---- - -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-without-resources -spec: - params: - - name: filename - value: "README.md" - taskRef: - name: task-check-optional-resources ---- - -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-without-resources-and-params -spec: - taskRef: - name: task-check-optional-resources ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-outputs-resources-with-input-resources -spec: - params: - - name: filename - value: "README.md" - resources: - inputs: - - name: git-repo - resourceSpec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline.git - taskRef: - name: task-check-optional-resources ---- diff --git a/examples/v1beta1/taskruns/task-multiple-output-image.yaml b/examples/v1beta1/taskruns/task-multiple-output-image.yaml deleted file mode 100644 index 2ba605ad9c1..00000000000 --- a/examples/v1beta1/taskruns/task-multiple-output-image.yaml +++ /dev/null @@ -1,124 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-image-leeroy-web-1 -spec: - type: image - params: - - name: url - value: gcr.io/dlorenc-vmtest2/leeroy-web # Replace this URL with $KO_DOCKER_REPO ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-image-leeroy-web-2 -spec: - type: image - params: - - name: url - value: gcr.io/christiewilson-catfactory/leeroy-web # Replace this URL with $KO_DOCKER_REPO ---- -# This demo modifies the cluster (deploys to it) you must use a service -# account with permission to admin the cluster (or make your default user an admin -# of the `default` namespace with default-cluster-admin). -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - generateName: default-cluster-admin- -subjects: - - kind: ServiceAccount - name: default - namespace: default -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: rbac.authorization.k8s.io ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-git-multiple-output-image -spec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# This task is currently hardcoding a index.json file instead of -# building an image since kaniko and other easy to use tools don't -# support exporting this file yet -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: multiple-build-push-kaniko -spec: - resources: - inputs: - - name: sourcerepo - type: git - outputs: - - name: builtImage1 - type: image - - name: builtImage2 - type: image - steps: - - name: build-and-push-1 - image: busybox - script: | - set -ex - mkdir -p /tekton/home/image-outputs/builtImage1 - cat < /tekton/home/image-outputs/builtImage1/index.json - { - "schemaVersion": 2, - "manifests": [ - { - "mediaType": "application/vnd.oci.image.index.v1+json", - "size": 314, - "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5" - } - ] - } - - name: build-and-push-2 - image: busybox - script: | - set -e - mkdir -p /tekton/home/image-outputs/builtImage2 - cat < /tekton/home/image-outputs/builtImage2/index.json - { - "schemaVersion": 2, - "manifests": [ - { - "mediaType": "application/vnd.oci.image.index.v1+json", - "size": 314, - "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5" - } - ] - } ---- -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: multiple-build-push-kaniko-run -spec: - taskRef: - name: multiple-build-push-kaniko - resources: - inputs: - - name: sourcerepo - resourceRef: - name: skaffold-git-multiple-output-image - outputs: - - name: builtImage1 - resourceRef: - name: skaffold-image-leeroy-web-1 - - name: builtImage2 - resourceRef: - name: skaffold-image-leeroy-web-2 diff --git a/examples/v1beta1/taskruns/task-output-image.yaml b/examples/v1beta1/taskruns/task-output-image.yaml deleted file mode 100644 index ad5407acfbe..00000000000 --- a/examples/v1beta1/taskruns/task-output-image.yaml +++ /dev/null @@ -1,97 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-image-leeroy-web-output-image -spec: - type: image - params: - - name: url - value: gcr.io/christiewilson-catfactory/leeroy-web # Replace this URL with $KO_DOCKER_REPO ---- -# This demo modifies the cluster (deploys to it) you must use a service -# account with permission to admin the cluster (or make your default user an admin -# of the `default` namespace with default-cluster-admin). -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - generateName: default-cluster-admin- -subjects: - - kind: ServiceAccount - name: default - namespace: default -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: rbac.authorization.k8s.io ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-git-output-image -spec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# This task is currently hardcoding a index.json file instead of -# building an image since kaniko and other easy to use tools don't -# support exporting this file yet -# -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: build-push-kaniko-output-image -spec: - resources: - inputs: - - name: sourcerepo - type: git - outputs: - - name: builtImage - type: image - targetPath: /workspace/sourcerepo - steps: - - name: build-and-push - image: busybox - script: | - set -e - cat < $(resources.inputs.sourcerepo.path)/index.json - { - "schemaVersion": 2, - "manifests": [ - { - "mediaType": "application/vnd.oci.image.index.v1+json", - "size": 314, - "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5" - } - ] - } - - name: echo - image: busybox - script: cat $(resources.inputs.sourcerepo.path)/index.json ---- -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: build-push-run-output-image -spec: - taskRef: - name: build-push-kaniko-output-image - resources: - inputs: - - name: sourcerepo - resourceRef: - name: skaffold-git-output-image - outputs: - - name: builtImage - resourceRef: - name: skaffold-image-leeroy-web-output-image diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 5336a86826d..0dba34a2d0f 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -72,11 +72,6 @@ ${PREFIX}/deepcopy-gen \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ -i github.com/tektoncd/pipeline/pkg/apis/pipeline/pod -${PREFIX}/deepcopy-gen \ - -O zz_generated.deepcopy \ - --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ --i github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage - ${PREFIX}/deepcopy-gen \ -O zz_generated.deepcopy \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ diff --git a/pkg/apis/config/artifact_bucket.go b/pkg/apis/config/artifact_bucket.go deleted file mode 100644 index abdfc6e7d81..00000000000 --- a/pkg/apis/config/artifact_bucket.go +++ /dev/null @@ -1,112 +0,0 @@ -/* -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 config - -import ( - "os" - - corev1 "k8s.io/api/core/v1" -) - -const ( - // BucketLocationKey is the name of the configmap entry that specifies - // loction of the bucket. - BucketLocationKey = "location" - - // BucketServiceAccountSecretNameKey is the name of the configmap entry that specifies - // the name of the secret that will provide the servie account with bucket access. - // This secret must have a key called serviceaccount that will have a value with - // the service account with access to the bucket - BucketServiceAccountSecretNameKey = "bucket.service.account.secret.name" - - // BucketServiceAccountSecretKeyKey is the name of the configmap entry that specifies - // the secret key that will have a value with the service account json with access - // to the bucket - BucketServiceAccountSecretKeyKey = "bucket.service.account.secret.key" - - // DefaultBucketServiceFieldName defaults to a gcs bucket - DefaultBucketServiceFieldName = "GOOGLE_APPLICATION_CREDENTIALS" - - // BucketServiceAccountFieldNameKey is the name of the configmap entry that specifies - // the field name that should be used for the service account. - // Valid values: GOOGLE_APPLICATION_CREDENTIALS, BOTO_CONFIG. - BucketServiceAccountFieldNameKey = "bucket.service.account.field.name" -) - -// ArtifactBucket holds the configurations for the artifacts PVC -// +k8s:deepcopy-gen=true -type ArtifactBucket struct { - Location string - ServiceAccountSecretName string - ServiceAccountSecretKey string - ServiceAccountFieldName string -} - -// GetArtifactBucketConfigName returns the name of the configmap containing all -// customizations for the storage bucket. -func GetArtifactBucketConfigName() string { - if e := os.Getenv("CONFIG_ARTIFACT_BUCKET_NAME"); e != "" { - return e - } - return "config-artifact-bucket" -} - -// Equals returns true if two Configs are identical -func (cfg *ArtifactBucket) Equals(other *ArtifactBucket) bool { - if cfg == nil && other == nil { - return true - } - - if cfg == nil || other == nil { - return false - } - - return other.Location == cfg.Location && - other.ServiceAccountSecretName == cfg.ServiceAccountSecretName && - other.ServiceAccountSecretKey == cfg.ServiceAccountSecretKey && - other.ServiceAccountFieldName == cfg.ServiceAccountFieldName -} - -// NewArtifactBucketFromMap returns a Config given a map corresponding to a ConfigMap -func NewArtifactBucketFromMap(cfgMap map[string]string) (*ArtifactBucket, error) { - tc := ArtifactBucket{ - ServiceAccountFieldName: DefaultBucketServiceFieldName, - } - - if location, ok := cfgMap[BucketLocationKey]; ok { - tc.Location = location - } - - if serviceAccountSecretName, ok := cfgMap[BucketServiceAccountSecretNameKey]; ok { - tc.ServiceAccountSecretName = serviceAccountSecretName - } - - if serviceAccountSecretKey, ok := cfgMap[BucketServiceAccountSecretKeyKey]; ok { - tc.ServiceAccountSecretKey = serviceAccountSecretKey - } - - if serviceAccountFieldName, ok := cfgMap[BucketServiceAccountFieldNameKey]; ok { - tc.ServiceAccountFieldName = serviceAccountFieldName - } - - return &tc, nil -} - -// NewArtifactBucketFromConfigMap returns a Config for the given configmap -func NewArtifactBucketFromConfigMap(config *corev1.ConfigMap) (*ArtifactBucket, error) { - return NewArtifactBucketFromMap(config.Data) -} diff --git a/pkg/apis/config/artifact_bucket_test.go b/pkg/apis/config/artifact_bucket_test.go deleted file mode 100644 index 106da323a1c..00000000000 --- a/pkg/apis/config/artifact_bucket_test.go +++ /dev/null @@ -1,103 +0,0 @@ -/* -Copyright 2020 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 config_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/config" - test "github.com/tektoncd/pipeline/pkg/reconciler/testing" - "github.com/tektoncd/pipeline/test/diff" -) - -func TestNewArtifactBucketFromConfigMap(t *testing.T) { - type testCase struct { - expectedConfig *config.ArtifactBucket - fileName string - } - - testCases := []testCase{ - { - expectedConfig: &config.ArtifactBucket{ - Location: "gs://my-bucket", - ServiceAccountFieldName: "GOOGLE_APPLICATION_CREDENTIALS", - }, - fileName: config.GetArtifactBucketConfigName(), - }, - { - expectedConfig: &config.ArtifactBucket{ - Location: "gs://test-bucket", - ServiceAccountSecretName: "test-secret", - ServiceAccountSecretKey: "key", - ServiceAccountFieldName: "some-field", - }, - fileName: "config-artifact-bucket-all-set", - }, - } - - for _, tc := range testCases { - verifyConfigFileWithExpectedArtifactBucketConfig(t, tc.fileName, tc.expectedConfig) - } -} - -func TestNewArtifactBucketFromEmptyConfigMap(t *testing.T) { - ArtifactBucketConfigEmptyName := "config-artifact-bucket-empty" - expectedConfig := &config.ArtifactBucket{ - ServiceAccountFieldName: "GOOGLE_APPLICATION_CREDENTIALS", - } - verifyConfigFileWithExpectedArtifactBucketConfig(t, ArtifactBucketConfigEmptyName, expectedConfig) -} - -func TestGetArtifactBucketConfigName(t *testing.T) { - for _, tc := range []struct { - description string - artifactsBucketEnvValue string - expected string - }{{ - description: "Artifact Bucket config value not set", - artifactsBucketEnvValue: "", - expected: "config-artifact-bucket", - }, { - description: "Artifact Bucket config value set", - artifactsBucketEnvValue: "config-artifact-bucket-test", - expected: "config-artifact-bucket-test", - }} { - t.Run(tc.description, func(t *testing.T) { - if tc.artifactsBucketEnvValue != "" { - t.Setenv("CONFIG_ARTIFACT_BUCKET_NAME", tc.artifactsBucketEnvValue) - } - got := config.GetArtifactBucketConfigName() - want := tc.expected - if got != want { - t.Errorf("GetArtifactBucketConfigName() = %s, want %s", got, want) - } - }) - } -} - -func verifyConfigFileWithExpectedArtifactBucketConfig(t *testing.T, fileName string, expectedConfig *config.ArtifactBucket) { - t.Helper() - cm := test.ConfigMapFromTestFile(t, fileName) - if ab, err := config.NewArtifactBucketFromConfigMap(cm); err == nil { - if d := cmp.Diff(ab, expectedConfig); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } - } else { - t.Errorf("NewArtifactBucketFromConfigMap(actual) = %v", err) - } -} diff --git a/pkg/apis/config/artifact_pvc.go b/pkg/apis/config/artifact_pvc.go deleted file mode 100644 index 5434353d398..00000000000 --- a/pkg/apis/config/artifact_pvc.go +++ /dev/null @@ -1,86 +0,0 @@ -/* -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 config - -import ( - "os" - - corev1 "k8s.io/api/core/v1" -) - -const ( - // DefaultPVCSize is the default size of the PVC to create - DefaultPVCSize = "5Gi" - - // PVCSizeKey is the name of the configmap entry that specifies the size of the PVC to create - PVCSizeKey = "size" - - // PVCStorageClassNameKey is the name of the configmap entry that specifies the storage class of the PVC to create - PVCStorageClassNameKey = "storageClassName" -) - -// ArtifactPVC holds the configurations for the artifacts PVC -// +k8s:deepcopy-gen=true -type ArtifactPVC struct { - Size string - StorageClassName string -} - -// GetArtifactPVCConfigName returns the name of the configmap containing all -// customizations for the storage PVC. -func GetArtifactPVCConfigName() string { - if e := os.Getenv("CONFIG_ARTIFACT_PVC_NAME"); e != "" { - return e - } - return "config-artifact-pvc" -} - -// Equals returns true if two Configs are identical -func (cfg *ArtifactPVC) Equals(other *ArtifactPVC) bool { - if cfg == nil && other == nil { - return true - } - - if cfg == nil || other == nil { - return false - } - - return other.Size == cfg.Size && - other.StorageClassName == cfg.StorageClassName -} - -// NewArtifactPVCFromMap returns a Config given a map corresponding to a ConfigMap -func NewArtifactPVCFromMap(cfgMap map[string]string) (*ArtifactPVC, error) { - tc := ArtifactPVC{ - Size: DefaultPVCSize, - } - - if size, ok := cfgMap[PVCSizeKey]; ok { - tc.Size = size - } - - if storageClassName, ok := cfgMap[PVCStorageClassNameKey]; ok { - tc.StorageClassName = storageClassName - } - - return &tc, nil -} - -// NewArtifactPVCFromConfigMap returns a Config for the given configmap -func NewArtifactPVCFromConfigMap(config *corev1.ConfigMap) (*ArtifactPVC, error) { - return NewArtifactPVCFromMap(config.Data) -} diff --git a/pkg/apis/config/artifact_pvc_test.go b/pkg/apis/config/artifact_pvc_test.go deleted file mode 100644 index f04fa5f9a97..00000000000 --- a/pkg/apis/config/artifact_pvc_test.go +++ /dev/null @@ -1,101 +0,0 @@ -/* -Copyright 2020 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 config_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/config" - test "github.com/tektoncd/pipeline/pkg/reconciler/testing" - "github.com/tektoncd/pipeline/test/diff" -) - -func TestNewArtifactPVCFromConfigMap(t *testing.T) { - type testCase struct { - expectedConfig *config.ArtifactPVC - fileName string - } - - testCases := []testCase{ - { - expectedConfig: &config.ArtifactPVC{ - Size: "5Gi", - StorageClassName: "my-class", - }, - fileName: config.GetArtifactPVCConfigName(), - }, - { - expectedConfig: &config.ArtifactPVC{ - Size: "10Gi", - StorageClassName: "test-class", - }, - fileName: "config-artifact-pvc-all-set", - }, - } - - for _, tc := range testCases { - verifyConfigFileWithExpectedArtifactPVCConfig(t, tc.fileName, tc.expectedConfig) - } -} - -func TestNewArtifactPVCFromEmptyConfigMap(t *testing.T) { - ArtifactPVCConfigEmptyName := "config-artifact-pvc-empty" - expectedConfig := &config.ArtifactPVC{ - Size: "5Gi", - } - verifyConfigFileWithExpectedArtifactPVCConfig(t, ArtifactPVCConfigEmptyName, expectedConfig) -} - -func TestGetArtifactPVCConfigName(t *testing.T) { - for _, tc := range []struct { - description string - artifactsPVCEnvValue string - expected string - }{{ - description: "Artifact PVC config value not set", - artifactsPVCEnvValue: "", - expected: "config-artifact-pvc", - }, { - description: "Artifact PVC config value set", - artifactsPVCEnvValue: "config-artifact-pvc-test", - expected: "config-artifact-pvc-test", - }} { - t.Run(tc.description, func(t *testing.T) { - if tc.artifactsPVCEnvValue != "" { - t.Setenv("CONFIG_ARTIFACT_PVC_NAME", tc.artifactsPVCEnvValue) - } - got := config.GetArtifactPVCConfigName() - want := tc.expected - if got != want { - t.Errorf("GetArtifactPVCConfigName() = %s, want %s", got, want) - } - }) - } -} - -func verifyConfigFileWithExpectedArtifactPVCConfig(t *testing.T, fileName string, expectedConfig *config.ArtifactPVC) { - t.Helper() - cm := test.ConfigMapFromTestFile(t, fileName) - if ab, err := config.NewArtifactPVCFromConfigMap(cm); err == nil { - if d := cmp.Diff(ab, expectedConfig); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } - } else { - t.Errorf("NewArtifactPVCFromConfigMap(actual) = %v", err) - } -} diff --git a/pkg/apis/config/store.go b/pkg/apis/config/store.go index 5143d3e0b79..77d5103b642 100644 --- a/pkg/apis/config/store.go +++ b/pkg/apis/config/store.go @@ -30,8 +30,6 @@ type cfgKey struct{} type Config struct { Defaults *Defaults FeatureFlags *FeatureFlags - ArtifactBucket *ArtifactBucket - ArtifactPVC *ArtifactPVC Metrics *Metrics TrustedResources *TrustedResources SpireConfig *sc.SpireConfig @@ -54,8 +52,6 @@ func FromContextOrDefaults(ctx context.Context) *Config { } defaults, _ := NewDefaultsFromMap(map[string]string{}) featureFlags, _ := NewFeatureFlagsFromMap(map[string]string{}) - artifactBucket, _ := NewArtifactBucketFromMap(map[string]string{}) - artifactPVC, _ := NewArtifactPVCFromMap(map[string]string{}) metrics, _ := newMetricsFromMap(map[string]string{}) trustedresources, _ := NewTrustedResourcesConfigFromMap(map[string]string{}) spireconfig, _ := NewSpireConfigFromMap(map[string]string{}) @@ -63,8 +59,6 @@ func FromContextOrDefaults(ctx context.Context) *Config { return &Config{ Defaults: defaults, FeatureFlags: featureFlags, - ArtifactBucket: artifactBucket, - ArtifactPVC: artifactPVC, Metrics: metrics, TrustedResources: trustedresources, SpireConfig: spireconfig, @@ -92,8 +86,6 @@ func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value i configmap.Constructors{ GetDefaultsConfigName(): NewDefaultsFromConfigMap, GetFeatureFlagsConfigName(): NewFeatureFlagsFromConfigMap, - GetArtifactBucketConfigName(): NewArtifactBucketFromConfigMap, - GetArtifactPVCConfigName(): NewArtifactPVCFromConfigMap, GetMetricsConfigName(): NewMetricsFromConfigMap, GetTrustedResourcesConfigName(): NewTrustedResourcesConfigFromConfigMap, GetSpireConfigName(): NewSpireConfigFromConfigMap, @@ -120,15 +112,6 @@ func (s *Store) Load() *Config { if featureFlags == nil { featureFlags, _ = NewFeatureFlagsFromMap(map[string]string{}) } - artifactBucket := s.UntypedLoad(GetArtifactBucketConfigName()) - if artifactBucket == nil { - artifactBucket, _ = NewArtifactBucketFromMap(map[string]string{}) - } - artifactPVC := s.UntypedLoad(GetArtifactPVCConfigName()) - if artifactPVC == nil { - artifactPVC, _ = NewArtifactPVCFromMap(map[string]string{}) - } - metrics := s.UntypedLoad(GetMetricsConfigName()) if metrics == nil { metrics, _ = newMetricsFromMap(map[string]string{}) @@ -145,8 +128,6 @@ func (s *Store) Load() *Config { return &Config{ Defaults: defaults.(*Defaults).DeepCopy(), FeatureFlags: featureFlags.(*FeatureFlags).DeepCopy(), - ArtifactBucket: artifactBucket.(*ArtifactBucket).DeepCopy(), - ArtifactPVC: artifactPVC.(*ArtifactPVC).DeepCopy(), Metrics: metrics.(*Metrics).DeepCopy(), TrustedResources: trustedresources.(*TrustedResources).DeepCopy(), SpireConfig: spireconfig.(*sc.SpireConfig).DeepCopy(), diff --git a/pkg/apis/config/store_test.go b/pkg/apis/config/store_test.go index fcb42a44d66..76d1bd917ac 100644 --- a/pkg/apis/config/store_test.go +++ b/pkg/apis/config/store_test.go @@ -31,16 +31,12 @@ import ( func TestStoreLoadWithContext(t *testing.T) { defaultConfig := test.ConfigMapFromTestFile(t, "config-defaults") featuresConfig := test.ConfigMapFromTestFile(t, "feature-flags-all-flags-set") - artifactBucketConfig := test.ConfigMapFromTestFile(t, "config-artifact-bucket") - artifactPVCConfig := test.ConfigMapFromTestFile(t, "config-artifact-pvc") metricsConfig := test.ConfigMapFromTestFile(t, "config-observability") trustedresourcesConfig := test.ConfigMapFromTestFile(t, "config-trusted-resources") spireConfig := test.ConfigMapFromTestFile(t, "config-spire") expectedDefaults, _ := config.NewDefaultsFromConfigMap(defaultConfig) expectedFeatures, _ := config.NewFeatureFlagsFromConfigMap(featuresConfig) - expectedArtifactBucket, _ := config.NewArtifactBucketFromConfigMap(artifactBucketConfig) - expectedArtifactPVC, _ := config.NewArtifactPVCFromConfigMap(artifactPVCConfig) metrics, _ := config.NewMetricsFromConfigMap(metricsConfig) expectedTrustedResources, _ := config.NewTrustedResourcesConfigFromConfigMap(trustedresourcesConfig) expectedSpireConfig, _ := config.NewSpireConfigFromConfigMap(spireConfig) @@ -48,8 +44,6 @@ func TestStoreLoadWithContext(t *testing.T) { expected := &config.Config{ Defaults: expectedDefaults, FeatureFlags: expectedFeatures, - ArtifactBucket: expectedArtifactBucket, - ArtifactPVC: expectedArtifactPVC, Metrics: metrics, TrustedResources: expectedTrustedResources, SpireConfig: expectedSpireConfig, @@ -58,8 +52,6 @@ func TestStoreLoadWithContext(t *testing.T) { store := config.NewStore(logtesting.TestLogger(t)) store.OnConfigChanged(defaultConfig) store.OnConfigChanged(featuresConfig) - store.OnConfigChanged(artifactBucketConfig) - store.OnConfigChanged(artifactPVCConfig) store.OnConfigChanged(metricsConfig) store.OnConfigChanged(trustedresourcesConfig) store.OnConfigChanged(spireConfig) @@ -74,8 +66,6 @@ func TestStoreLoadWithContext(t *testing.T) { func TestStoreLoadWithContext_Empty(t *testing.T) { defaults, _ := config.NewDefaultsFromMap(map[string]string{}) featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{}) - artifactBucket, _ := config.NewArtifactBucketFromMap(map[string]string{}) - artifactPVC, _ := config.NewArtifactPVCFromMap(map[string]string{}) metrics, _ := config.NewMetricsFromConfigMap(&corev1.ConfigMap{Data: map[string]string{}}) trustedresources, _ := config.NewTrustedResourcesConfigFromMap(map[string]string{}) spireConfig, _ := config.NewSpireConfigFromMap(map[string]string{}) @@ -83,8 +73,6 @@ func TestStoreLoadWithContext_Empty(t *testing.T) { want := &config.Config{ Defaults: defaults, FeatureFlags: featureFlags, - ArtifactBucket: artifactBucket, - ArtifactPVC: artifactPVC, Metrics: metrics, TrustedResources: trustedresources, SpireConfig: spireConfig, diff --git a/pkg/apis/config/testdata/config-artifact-bucket-all-set.yaml b/pkg/apis/config/testdata/config-artifact-bucket-all-set.yaml deleted file mode 100644 index 236715851ff..00000000000 --- a/pkg/apis/config/testdata/config-artifact-bucket-all-set.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2020 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-bucket - namespace: tekton-pipelines -data: - location: "gs://test-bucket" - bucket.service.account.secret.name: "test-secret" - bucket.service.account.secret.key: "key" - bucket.service.account.field.name: "some-field" diff --git a/pkg/apis/config/testdata/config-artifact-bucket-empty.yaml b/pkg/apis/config/testdata/config-artifact-bucket-empty.yaml deleted file mode 100644 index d0bfa806daa..00000000000 --- a/pkg/apis/config/testdata/config-artifact-bucket-empty.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2020 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-bucket - namespace: tekton-pipelines -data: - _example: | - ################################ - # # - # EXAMPLE CONFIGURATION # - # # - ################################ diff --git a/pkg/apis/config/testdata/config-artifact-bucket.yaml b/pkg/apis/config/testdata/config-artifact-bucket.yaml deleted file mode 100644 index a4a7f062f5e..00000000000 --- a/pkg/apis/config/testdata/config-artifact-bucket.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2020 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-bucket - namespace: tekton-pipelines -data: - location: "gs://my-bucket" \ No newline at end of file diff --git a/pkg/apis/config/testdata/config-artifact-pvc-all-set.yaml b/pkg/apis/config/testdata/config-artifact-pvc-all-set.yaml deleted file mode 100644 index 80785ff8f3e..00000000000 --- a/pkg/apis/config/testdata/config-artifact-pvc-all-set.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2020 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-pvc - namespace: tekton-pipelines -data: - size: "10Gi" - storageClassName: "test-class" diff --git a/pkg/apis/config/testdata/config-artifact-pvc-empty.yaml b/pkg/apis/config/testdata/config-artifact-pvc-empty.yaml deleted file mode 100644 index 0b5556004ea..00000000000 --- a/pkg/apis/config/testdata/config-artifact-pvc-empty.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2020 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-pvc - namespace: tekton-pipelines -data: - _example: | - ################################ - # # - # EXAMPLE CONFIGURATION # - # # - ################################ diff --git a/pkg/apis/config/testdata/config-artifact-pvc.yaml b/pkg/apis/config/testdata/config-artifact-pvc.yaml deleted file mode 100644 index 26cecb75a2c..00000000000 --- a/pkg/apis/config/testdata/config-artifact-pvc.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2020 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 -# -# https://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. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-pvc - namespace: tekton-pipelines -data: - storageClassName: "my-class" \ No newline at end of file diff --git a/pkg/apis/config/zz_generated.deepcopy.go b/pkg/apis/config/zz_generated.deepcopy.go index b6c8c8febd3..bb46f2f9929 100644 --- a/pkg/apis/config/zz_generated.deepcopy.go +++ b/pkg/apis/config/zz_generated.deepcopy.go @@ -26,38 +26,6 @@ import ( sets "k8s.io/apimachinery/pkg/util/sets" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ArtifactBucket) DeepCopyInto(out *ArtifactBucket) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArtifactBucket. -func (in *ArtifactBucket) DeepCopy() *ArtifactBucket { - if in == nil { - return nil - } - out := new(ArtifactBucket) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ArtifactPVC) DeepCopyInto(out *ArtifactPVC) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArtifactPVC. -func (in *ArtifactPVC) DeepCopy() *ArtifactPVC { - if in == nil { - return nil - } - out := new(ArtifactPVC) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Defaults) DeepCopyInto(out *Defaults) { *out = *in diff --git a/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go b/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go index d826acd345b..55153c9fa0b 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go @@ -187,11 +187,11 @@ func TestPipelineConversionFromDeprecated(t *testing.T) { Resources: []v1beta1.PipelineDeclaredResource{ { Name: "1st pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, + Type: v1beta1.PipelineResourceTypeImage, Optional: true, }, { Name: "2nd pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, + Type: v1beta1.PipelineResourceTypeImage, Optional: false, }, }, @@ -205,11 +205,11 @@ func TestPipelineConversionFromDeprecated(t *testing.T) { Resources: []v1beta1.PipelineDeclaredResource{ { Name: "1st pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, + Type: v1beta1.PipelineResourceTypeImage, Optional: true, }, { Name: "2nd pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, + Type: v1beta1.PipelineResourceTypeImage, Optional: false, }, }, diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go index 43b751bdd6e..f51ca7ddb6c 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go @@ -660,7 +660,7 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { name: "invalid pipeline with pipeline task having reference to resources which does not exist", ps: &PipelineSpec{ Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, + Name: "great-resource", Type: "invalid type", }, { Name: "wonderful-resource", Type: PipelineResourceTypeImage, }}, @@ -693,7 +693,7 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { name: "invalid pipeline spec - from referring to a pipeline task which does not exist", ps: &PipelineSpec{ Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, + Name: "great-resource", Type: PipelineResourceTypeImage, }}, Tasks: []PipelineTask{{ Name: "baz", TaskRef: &TaskRef{Name: "baz-task"}, @@ -953,17 +953,12 @@ func TestValidateDeclaredResources_Success(t *testing.T) { }{{ name: "valid resource declarations and usage", resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { Name: "wonderful-resource", Type: PipelineResourceTypeImage, }}, tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, Outputs: []PipelineTaskOutputResource{{ Name: "some-imagee", Resource: "wonderful-resource", }}, @@ -980,11 +975,7 @@ func TestValidateDeclaredResources_Success(t *testing.T) { }, { name: "valid resource declarations with extra resources, not used in any pipeline task", resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { Name: "awesome-resource", Type: PipelineResourceTypeImage, - }, { - Name: "yet-another-great-resource", Type: PipelineResourceTypeGit, }, { Name: "yet-another-awesome-resource", Type: PipelineResourceTypeImage, }}, @@ -992,9 +983,6 @@ func TestValidateDeclaredResources_Success(t *testing.T) { Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "great-resource", - }}, Outputs: []PipelineTaskOutputResource{{ Name: "the-awesome-resource", Resource: "awesome-resource", }}, @@ -1020,9 +1008,9 @@ func TestValidateDeclaredResources_Failure(t *testing.T) { }{{ name: "duplicate resource declaration - resource declarations must be unique", resources: []PipelineDeclaredResource{{ - Name: "duplicate-resource", Type: PipelineResourceTypeGit, + Name: "duplicate-resource", Type: PipelineResourceTypeImage, }, { - Name: "duplicate-resource", Type: PipelineResourceTypeGit, + Name: "duplicate-resource", Type: PipelineResourceTypeImage, }}, tasks: []PipelineTask{{ Name: "foo", @@ -1040,7 +1028,7 @@ func TestValidateDeclaredResources_Failure(t *testing.T) { }, { name: "output resource is missing from resource declarations", resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, + Name: "great-resource", Type: PipelineResourceTypeImage, }}, tasks: []PipelineTask{{ Name: "foo", @@ -1061,7 +1049,7 @@ func TestValidateDeclaredResources_Failure(t *testing.T) { }, { name: "input resource is missing from resource declarations", resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, + Name: "great-resource", Type: PipelineResourceTypeImage, }}, tasks: []PipelineTask{{ Name: "foo", @@ -2378,7 +2366,7 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, Spec: PipelineSpec{ Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, + Name: "great-resource", Type: PipelineResourceTypeImage, }, { Name: "wonderful-resource", Type: PipelineResourceTypeImage, }}, diff --git a/pkg/apis/pipeline/v1beta1/resource_types.go b/pkg/apis/pipeline/v1beta1/resource_types.go index 41ad57bd345..56849022183 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types.go +++ b/pkg/apis/pipeline/v1beta1/resource_types.go @@ -37,12 +37,6 @@ var ( ) const ( - // PipelineResourceTypeGit indicates that this source is a GitHub repo. - PipelineResourceTypeGit PipelineResourceType = resource.PipelineResourceTypeGit - - // PipelineResourceTypeStorage indicates that this source is a storage blob resource. - PipelineResourceTypeStorage PipelineResourceType = resource.PipelineResourceTypeStorage - // PipelineResourceTypeImage indicates that this source is a docker Image. PipelineResourceTypeImage PipelineResourceType = resource.PipelineResourceTypeImage ) diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index a96a19ca6e3..8e864ef60bd 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -33,13 +33,6 @@ import ( "knative.dev/pkg/apis" ) -var validResource = v1beta1.TaskResource{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "validsource", - Type: "git", - }, -} - var invalidResource = v1beta1.TaskResource{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "invalidsource", @@ -187,22 +180,6 @@ func TestTaskSpecValidate(t *testing.T) { Image: "myotherimage", }}, }, - }, { - name: "valid input resources", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{validResource}, - }, - Steps: validSteps, - }, - }, { - name: "valid output resources", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{validResource}, - }, - Steps: validSteps, - }, }, { name: "valid params type implied", fields: fields{ @@ -591,31 +568,6 @@ func TestTaskSpecValidateError(t *testing.T) { Message: `invalid value: what`, Paths: []string{"resources.inputs[0].invalidsource.type"}, }, - }, { - name: "one invalid input resource", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{validResource, invalidResource}, - }, - Steps: validSteps, - }, - expectedError: apis.FieldError{ - Message: `invalid value: what`, - Paths: []string{"resources.inputs[1].invalidsource.type"}, - }, - }, { - name: "duplicated inputs resources", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{validResource, validResource}, - Outputs: []v1beta1.TaskResource{validResource}, - }, - Steps: validSteps, - }, - expectedError: apis.FieldError{ - Message: `expected exactly one, got both`, - Paths: []string{"resources.inputs.name"}, - }, }, { name: "invalid output resource", fields: fields{ @@ -628,31 +580,6 @@ func TestTaskSpecValidateError(t *testing.T) { Message: `invalid value: what`, Paths: []string{"resources.outputs[0].invalidsource.type"}, }, - }, { - name: "one invalid output resource", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{validResource, invalidResource}, - }, - Steps: validSteps, - }, - expectedError: apis.FieldError{ - Message: `invalid value: what`, - Paths: []string{"resources.outputs[1].invalidsource.type"}, - }, - }, { - name: "duplicated outputs resources", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{validResource}, - Outputs: []v1beta1.TaskResource{validResource, validResource}, - }, - Steps: validSteps, - }, - expectedError: apis.FieldError{ - Message: `expected exactly one, got both`, - Paths: []string{"resources.outputs.name"}, - }, }, { name: "invalid param name format", fields: fields{ diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go index cca73d3da38..477fb2bcfc0 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go @@ -1019,7 +1019,7 @@ func TestResources_Invalidate(t *testing.T) { Name: "testresource", }, ResourceSpec: &resource.PipelineResourceSpec{ - Type: v1beta1.PipelineResourceTypeGit, + Type: v1beta1.PipelineResourceTypeImage, }, Name: "resource-dup", }, @@ -1078,7 +1078,7 @@ func TestResources_Invalidate(t *testing.T) { Name: "testresource", }, ResourceSpec: &resource.PipelineResourceSpec{ - Type: v1beta1.PipelineResourceTypeGit, + Type: v1beta1.PipelineResourceTypeImage, }, Name: "resource-dup", }, diff --git a/pkg/apis/resource/resource.go b/pkg/apis/resource/resource.go index d9038dd29f7..dd8c08aad4b 100644 --- a/pkg/apis/resource/resource.go +++ b/pkg/apis/resource/resource.go @@ -22,22 +22,15 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/git" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" ) // FromType returns an instance of the correct PipelineResource object type which can be // used to add input and output containers as well as volumes to a TaskRun's pod in order to realize // a PipelineResource in a pod. func FromType(name string, r *resourcev1alpha1.PipelineResource, images pipeline.Images) (pipelinev1beta1.PipelineResourceInterface, error) { - switch r.Spec.Type { - case resourcev1alpha1.PipelineResourceTypeGit: - return git.NewResource(name, images.GitImage, r) - case resourcev1alpha1.PipelineResourceTypeImage: + if r.Spec.Type == resourcev1alpha1.PipelineResourceTypeImage { return image.NewResource(name, r) - case resourcev1alpha1.PipelineResourceTypeStorage: - return storage.NewResource(name, images, r) } return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineResource", r.Spec.Type) } diff --git a/pkg/apis/resource/v1alpha1/git/git_resource.go b/pkg/apis/resource/v1alpha1/git/git_resource.go deleted file mode 100644 index 1b9c2e2269b..00000000000 --- a/pkg/apis/resource/v1alpha1/git/git_resource.go +++ /dev/null @@ -1,212 +0,0 @@ -/* -Copyright 2019-2020 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 git - -import ( - "fmt" - "strconv" - "strings" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/names" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/ptr" -) - -var ( - gitSource = "git-source" -) - -// Resource is an endpoint from which to get data which is required -// by a Build/Task for context (e.g. a repo from which to build an image). -type Resource struct { - Name string `json:"name"` - Type resource.PipelineResourceType `json:"type"` - URL string `json:"url"` - // Git revision (branch, tag, commit SHA) to clone, and optionally the refspec to fetch from. - // See https://git-scm.com/docs/gitrevisions#_specifying_revisions for more information. - Revision string `json:"revision"` - Refspec string `json:"refspec"` - Submodules bool `json:"submodules"` - - Depth uint `json:"depth"` - SSLVerify bool `json:"sslVerify"` - HTTPProxy string `json:"httpProxy"` - HTTPSProxy string `json:"httpsProxy"` - NOProxy string `json:"noProxy"` - GitImage string `json:"-"` -} - -// NewResource creates a new git resource to pass to a Task -func NewResource(name, gitImage string, r *resource.PipelineResource) (*Resource, error) { - if r.Spec.Type != resource.PipelineResourceTypeGit { - return nil, fmt.Errorf("git.Resource: Cannot create a Git resource from a %s Pipeline Resource", r.Spec.Type) - } - gitResource := Resource{ - Name: name, - Type: r.Spec.Type, - GitImage: gitImage, - Submodules: true, - Depth: 1, - SSLVerify: true, - } - for _, param := range r.Spec.Params { - switch { - case strings.EqualFold(param.Name, "URL"): - gitResource.URL = param.Value - case strings.EqualFold(param.Name, "Revision"): - gitResource.Revision = param.Value - case strings.EqualFold(param.Name, "Refspec"): - gitResource.Refspec = param.Value - case strings.EqualFold(param.Name, "Submodules"): - gitResource.Submodules = toBool(param.Value, true) - case strings.EqualFold(param.Name, "Depth"): - gitResource.Depth = toUint(param.Value, 1) - case strings.EqualFold(param.Name, "SSLVerify"): - gitResource.SSLVerify = toBool(param.Value, true) - case strings.EqualFold(param.Name, "HTTPProxy"): - gitResource.HTTPProxy = param.Value - case strings.EqualFold(param.Name, "HTTPSProxy"): - gitResource.HTTPSProxy = param.Value - case strings.EqualFold(param.Name, "NOProxy"): - gitResource.NOProxy = param.Value - } - } - - return &gitResource, nil -} - -func toBool(s string, d bool) bool { - switch s { - case "true": - return true - case "false": - return false - default: - return d - } -} - -func toUint(s string, d uint) uint { - v, err := strconv.ParseUint(s, 10, 32) - if err != nil { - return d - } - return uint(v) -} - -// GetName returns the name of the resource -func (s Resource) GetName() string { - return s.Name -} - -// GetType returns the type of the resource, in this case "Git" -func (s Resource) GetType() resource.PipelineResourceType { - return resource.PipelineResourceTypeGit -} - -// GetURL returns the url to be used with this resource -func (s *Resource) GetURL() string { - return s.URL -} - -// Replacements is used for template replacement on a GitResource inside of a Taskrun. -func (s *Resource) Replacements() map[string]string { - return map[string]string{ - "name": s.Name, - "type": s.Type, - "url": s.URL, - "revision": s.Revision, - "refspec": s.Refspec, - "submodules": strconv.FormatBool(s.Submodules), - "depth": strconv.FormatUint(uint64(s.Depth), 10), - "sslVerify": strconv.FormatBool(s.SSLVerify), - "httpProxy": s.HTTPProxy, - "httpsProxy": s.HTTPSProxy, - "noProxy": s.NOProxy, - } -} - -// GetInputTaskModifier returns the TaskModifier to be used when this resource is an input. -func (s *Resource) GetInputTaskModifier(_ *v1beta1.TaskSpec, path string) (v1beta1.TaskModifier, error) { - args := []string{ - "-url", s.URL, - "-path", path, - } - - if s.Revision != "" { - args = append(args, "-revision", s.Revision) - } - - if s.Refspec != "" { - args = append(args, "-refspec", s.Refspec) - } - if !s.Submodules { - args = append(args, "-submodules=false") - } - if s.Depth != 1 { - args = append(args, "-depth", strconv.FormatUint(uint64(s.Depth), 10)) - } - if !s.SSLVerify { - args = append(args, "-sslVerify=false") - } - - env := []corev1.EnvVar{{ - Name: "TEKTON_RESOURCE_NAME", - Value: s.Name, - }, { - Name: "HOME", - Value: pipeline.HomeDir, - }} - - if len(s.HTTPProxy) != 0 { - env = append(env, corev1.EnvVar{Name: "HTTP_PROXY", Value: s.HTTPProxy}) - } - - if len(s.HTTPSProxy) != 0 { - env = append(env, corev1.EnvVar{Name: "HTTPS_PROXY", Value: s.HTTPSProxy}) - } - - if len(s.NOProxy) != 0 { - env = append(env, corev1.EnvVar{Name: "NO_PROXY", Value: s.NOProxy}) - } - - step := v1beta1.Step{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(gitSource + "-" + s.Name), - Image: s.GitImage, - Command: []string{"/ko-app/git-init"}, - Args: args, - WorkingDir: pipeline.WorkspaceDir, - // This is used to populate the ResourceResult status. - Env: env, - SecurityContext: &corev1.SecurityContext{ - // The git pipeline resource only works when running as root. - RunAsUser: ptr.Int64(0), - }, - } - - return &v1beta1.InternalTaskModifier{ - StepsToPrepend: []v1beta1.Step{step}, - }, nil -} - -// GetOutputTaskModifier returns a No-op TaskModifier. -func (s *Resource) GetOutputTaskModifier(_ *v1beta1.TaskSpec, _ string) (v1beta1.TaskModifier, error) { - return &v1beta1.InternalTaskModifier{}, nil -} diff --git a/pkg/apis/resource/v1alpha1/git/git_resource_test.go b/pkg/apis/resource/v1alpha1/git/git_resource_test.go deleted file mode 100644 index 7a56205271a..00000000000 --- a/pkg/apis/resource/v1alpha1/git/git_resource_test.go +++ /dev/null @@ -1,912 +0,0 @@ -/* -Copyright 2019-2020 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 git_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/git" - "github.com/tektoncd/pipeline/test/diff" - "github.com/tektoncd/pipeline/test/names" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/ptr" -) - -func TestNewGitResource_Invalid(t *testing.T) { - if _, err := git.NewResource("test-resource", "override-with-git:latest", - &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGCS, - }, - }); err == nil { - t.Error("Expected error creating Git resource") - } -} - -func TestNewGitResource_Valid(t *testing.T) { - for _, tc := range []struct { - desc string - pipelineResource *resourcev1alpha1.PipelineResource - want *git.Resource - }{{ - desc: "With Revision", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 1, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "Without Revision", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "git@github.com:test/test.git", - }}, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 1, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "With Refspec", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Refspec", - Value: "refs/changes/22/222134", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "", - Refspec: "refs/changes/22/222134", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 1, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "Without Refspec", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "git@github.com:test/test.git", - }}, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 1, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "With Submodules", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 1, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "Without Submodules", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Submodules", - Value: "false", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "With positive depth", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Depth", - Value: "8", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 8, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "With zero depth", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Depth", - Value: "0", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 0, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "Without SSLVerify", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Depth", - Value: "0", - }, - { - Name: "SSLVerify", - Value: "false", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 0, - SSLVerify: false, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "With HTTPProxy", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Depth", - Value: "0", - }, - { - Name: "HTTPProxy", - Value: "http-proxy.git.com", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 0, - SSLVerify: true, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "", - NOProxy: "", - }, - }, { - desc: "With HTTPSProxy", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Depth", - Value: "0", - }, - { - Name: "HTTPSProxy", - Value: "https-proxy.git.com", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 0, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "", - }, - }, { - desc: "With NOProxy", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "URL", - Value: "git@github.com:test/test.git", - }, - { - Name: "Revision", - Value: "test", - }, - { - Name: "Depth", - Value: "0", - }, - { - Name: "NOProxy", - Value: "*", - }, - }, - }, - }, - want: &git.Resource{ - Name: "test-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "test", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 0, - SSLVerify: true, - HTTPProxy: "", - HTTPSProxy: "", - NOProxy: "*", - }, - }} { - t.Run(tc.desc, func(t *testing.T) { - got, err := git.NewResource("test-resource", "override-with-git:latest", tc.pipelineResource) - if err != nil { - t.Fatalf("Unexpected error creating Git resource: %s", err) - } - - if d := cmp.Diff(tc.want, got); d != "" { - t.Errorf("Mismatch of Git resource %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestGitResource_Replacements(t *testing.T) { - r := &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - Submodules: false, - Depth: 16, - SSLVerify: false, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "*", - } - - want := map[string]string{ - "name": "git-resource", - "type": resourcev1alpha1.PipelineResourceTypeGit, - "url": "git@github.com:test/test.git", - "revision": "master", - "refspec": "", - "submodules": "false", - "depth": "16", - "sslVerify": "false", - "httpProxy": "http-proxy.git.com", - "httpsProxy": "https-proxy.git.com", - "noProxy": "*", - } - - got := r.Replacements() - - if d := cmp.Diff(want, got); d != "" { - t.Errorf("Mismatch of GitResource Replacements %s", diff.PrintWantGot(d)) - } -} - -func TestGitResource_GetDownloadTaskModifier(t *testing.T) { - names.TestingSeed() - securityContext := &corev1.SecurityContext{RunAsUser: ptr.Int64(0)} - for _, tc := range []struct { - desc string - gitResource *git.Resource - want v1beta1.Step - }{{ - desc: "With basic values", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 1, - SSLVerify: true, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "Without submodules", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: true, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-mz4c7", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-submodules=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "With more depth", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: true, - Depth: 8, - SSLVerify: true, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-mssqb", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-depth", - "8", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "Without sslVerify", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: false, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-78c5n", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-submodules=false", - "-sslVerify=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "Without httpProxy", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: false, - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-6nl7g", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-submodules=false", - "-sslVerify=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "Without httpsProxy", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: false, - HTTPProxy: "http-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-j2tds", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-submodules=false", - "-sslVerify=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "Without noProxy", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: false, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-vr6ds", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-submodules=false", - "-sslVerify=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "With Refspec", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "master", - Refspec: "refs/tags/v1.0:refs/tags/v1.0 refs/heads/master:refs/heads/master", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: true, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-l22wn", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-revision", - "master", - "-refspec", - "refs/tags/v1.0:refs/tags/v1.0 refs/heads/master:refs/heads/master", - "-submodules=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }, { - desc: "Without Refspec and without revision", - gitResource: &git.Resource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, - URL: "git@github.com:test/test.git", - Revision: "", - Refspec: "", - GitImage: "override-with-git:latest", - Submodules: false, - Depth: 1, - SSLVerify: true, - HTTPProxy: "http-proxy.git.com", - HTTPSProxy: "https-proxy.git.com", - NOProxy: "no-proxy.git.com", - }, - want: v1beta1.Step{ - Name: "git-source-git-resource-twkr2", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{ - "-url", - "git@github.com:test/test.git", - "-path", - "/test/test", - "-submodules=false", - }, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, - {Name: "HOME", Value: pipeline.HomeDir}, - {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, - {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, - {Name: "NO_PROXY", Value: "no-proxy.git.com"}, - }, - SecurityContext: securityContext, - }, - }} { - t.Run(tc.desc, func(t *testing.T) { - ts := v1beta1.TaskSpec{} - modifier, err := tc.gitResource.GetInputTaskModifier(&ts, "/test/test") - if err != nil { - t.Fatalf("Unexpected error getting GetDownloadTaskModifier: %s", err) - } - - if d := cmp.Diff([]v1beta1.Step{tc.want}, modifier.GetStepsToPrepend()); d != "" { - t.Errorf("Mismatch of GitResource DownloadContainerSpec %s", diff.PrintWantGot(d)) - } - }) - } -} diff --git a/pkg/apis/resource/v1alpha1/image/image_resource_test.go b/pkg/apis/resource/v1alpha1/image/image_resource_test.go index 0f1f633576e..a20c5ef6a47 100644 --- a/pkg/apis/resource/v1alpha1/image/image_resource_test.go +++ b/pkg/apis/resource/v1alpha1/image/image_resource_test.go @@ -34,7 +34,7 @@ func TestNewImageResource_Invalid(t *testing.T) { Name: "test-resource", }, Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, + Type: "invalid type", }, } diff --git a/pkg/apis/resource/v1alpha1/pipeline_resource_types.go b/pkg/apis/resource/v1alpha1/pipeline_resource_types.go index e588feb9184..fcee76f19fb 100644 --- a/pkg/apis/resource/v1alpha1/pipeline_resource_types.go +++ b/pkg/apis/resource/v1alpha1/pipeline_resource_types.go @@ -27,28 +27,16 @@ type PipelineResourceType = string var ( // AllowedOutputResources are the resource types that can be used as outputs - AllowedOutputResources = map[PipelineResourceType]bool{ - PipelineResourceTypeStorage: true, - PipelineResourceTypeGit: true, - } + AllowedOutputResources = map[PipelineResourceType]bool{} ) const ( - // PipelineResourceTypeGit indicates that this source is a GitHub repo. - PipelineResourceTypeGit PipelineResourceType = "git" - - // PipelineResourceTypeStorage indicates that this source is a storage blob resource. - PipelineResourceTypeStorage PipelineResourceType = "storage" - // PipelineResourceTypeImage indicates that this source is a docker Image. PipelineResourceTypeImage PipelineResourceType = "image" - - // PipelineResourceTypeGCS is the subtype for the GCSResources, which is backed by a GCS blob/directory. - PipelineResourceTypeGCS PipelineResourceType = "gcs" ) // AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types. -var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypeImage} +var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeImage} // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/resource/v1alpha1/pipelineresource_validation.go b/pkg/apis/resource/v1alpha1/pipelineresource_validation.go index f4004b05b97..dbfca8b185d 100644 --- a/pkg/apis/resource/v1alpha1/pipelineresource_validation.go +++ b/pkg/apis/resource/v1alpha1/pipelineresource_validation.go @@ -18,7 +18,6 @@ package v1alpha1 import ( "context" - "strings" "github.com/tektoncd/pipeline/pkg/apis/validate" "k8s.io/apimachinery/pkg/api/equality" @@ -43,28 +42,6 @@ func (rs *PipelineResourceSpec) Validate(ctx context.Context) *apis.FieldError { if equality.Semantic.DeepEqual(rs, &PipelineResourceSpec{}) { return apis.ErrMissingField("spec.type") } - if rs.Type == PipelineResourceTypeStorage { - foundTypeParam := false - var location string - for _, param := range rs.Params { - switch { - case strings.EqualFold(param.Name, "type"): - if !AllowedStorageType(param.Value) { - return apis.ErrInvalidValue(param.Value, "spec.params.type") - } - foundTypeParam = true - case strings.EqualFold(param.Name, "Location"): - location = param.Value - } - } - - if !foundTypeParam { - return apis.ErrMissingField("spec.params.type") - } - if location == "" { - return apis.ErrMissingField("spec.params.location") - } - } for _, allowedType := range AllResourceTypes { if allowedType == rs.Type { @@ -74,8 +51,3 @@ func (rs *PipelineResourceSpec) Validate(ctx context.Context) *apis.FieldError { return apis.ErrInvalidValue("spec.type", rs.Type) } - -// AllowedStorageType returns true if the provided string can be used as a storage type, and false otherwise -func AllowedStorageType(gotType string) bool { - return gotType == PipelineResourceTypeGCS -} diff --git a/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go b/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go index 4f0ac3b8749..a8d9a093410 100644 --- a/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go +++ b/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go @@ -32,86 +32,26 @@ func TestResourceValidation_Invalid(t *testing.T) { name string res *v1alpha1.PipelineResource want *apis.FieldError - }{ - { - name: "storage with no type", - res: &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "temp", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeStorage, - Params: []v1alpha1.ResourceParam{{ - Name: "no-type-param", Value: "something", - }}, - }, + }{{ + name: "invalid resource type", + res: &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: "temp", }, - want: apis.ErrMissingField("spec.params.type"), - }, { - name: "storage with unimplemented type", - res: &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "temp", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeStorage, - Params: []v1alpha1.ResourceParam{{ - Name: "type", Value: "not-implemented-yet", - }}, - }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: "not-supported", }, - want: apis.ErrInvalidValue("not-implemented-yet", "spec.params.type"), - }, { - name: "storage with gcs type with no location param", - res: &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "temp", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeStorage, - Params: []v1alpha1.ResourceParam{{ - Name: "type", Value: "gcs", - }}, - }, - }, - want: apis.ErrMissingField("spec.params.location"), - }, { - name: "storage with gcs type with empty location param", - res: &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "temp", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeStorage, - Params: []v1alpha1.ResourceParam{{ - Name: "type", Value: "gcs", - }, { - Name: "location", Value: "", - }}, - }, - }, - want: apis.ErrMissingField("spec.params.location"), - }, { - name: "invalid resource type", - res: &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "temp", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "not-supported", - }, - }, - want: apis.ErrInvalidValue("spec.type", "not-supported"), - }, { - name: "missing spec", - res: &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "temp", - }, + }, + want: apis.ErrInvalidValue("spec.type", "not-supported"), + }, { + name: "missing spec", + res: &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: "temp", }, - want: apis.ErrMissingField("spec.type"), }, - } + want: apis.ErrMissingField("spec.type"), + }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.res.Validate(context.Background()) @@ -121,31 +61,3 @@ func TestResourceValidation_Invalid(t *testing.T) { }) } } - -func TestAllowedGCSStorageType(t *testing.T) { - tests := []struct { - name string - storageType string - want bool - }{ - {name: "storage with gcs type", - storageType: "gcs", - want: true, - }, - {name: "storage with incorrent type", - storageType: "t", - want: false, - }, - {name: "storage with empty type", - storageType: "", - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if v1alpha1.AllowedStorageType(tt.storageType) != tt.want { - t.Errorf("PipleineResource.allowedStorageType should return %t, got %t for %s", tt.want, !tt.want, tt.storageType) - } - }) - } -} diff --git a/pkg/apis/resource/v1alpha1/storage/artifact_bucket.go b/pkg/apis/resource/v1alpha1/storage/artifact_bucket.go deleted file mode 100644 index 48b4986b419..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/artifact_bucket.go +++ /dev/null @@ -1,103 +0,0 @@ -/* -Copyright 2019-2020 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 storage - -import ( - "fmt" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/names" - corev1 "k8s.io/api/core/v1" -) - -// For some reason gosec thinks this string has enough entropy to be a potential secret. -// The nosec comment disables it for this line. -/* #nosec */ -const secretVolumeMountPath = "/var/bucketsecret" - -// ArtifactBucket contains the Storage bucket configuration defined in the -// Bucket config map. -// +k8s:deepcopy-gen=true -type ArtifactBucket struct { - Name string - Location string - Secrets []resource.SecretParam - - ShellImage string - GsutilImage string -} - -// GetType returns the type of the artifact storage -func (b *ArtifactBucket) GetType() string { - return pipeline.ArtifactStorageBucketType -} - -// StorageBasePath returns the path to be used to store artifacts in a pipelinerun temporary storage -func (b *ArtifactBucket) StorageBasePath(pr *v1beta1.PipelineRun) string { - return fmt.Sprintf("%s-%s-bucket", pr.Name, pr.Namespace) -} - -// GetCopyFromStorageToSteps returns a container used to download artifacts from temporary storage -func (b *ArtifactBucket) GetCopyFromStorageToSteps(name, sourcePath, destinationPath string) []v1beta1.Step { - envVars, secretVolumeMount := getSecretEnvVarsAndVolumeMounts("bucket", secretVolumeMountPath, b.Secrets) - - return []v1beta1.Step{{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("artifact-dest-mkdir-%s", name)), - Image: b.ShellImage, - Command: []string{"mkdir", "-p", destinationPath}, - }, { - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("artifact-copy-from-%s", name)), - Image: b.GsutilImage, - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", fmt.Sprintf("%s/%s/*", b.Location, sourcePath), destinationPath}, - Env: envVars, - VolumeMounts: secretVolumeMount, - }} -} - -// GetCopyToStorageFromSteps returns a container used to upload artifacts for temporary storage -func (b *ArtifactBucket) GetCopyToStorageFromSteps(name, sourcePath, destinationPath string) []v1beta1.Step { - envVars, secretVolumeMount := getSecretEnvVarsAndVolumeMounts("bucket", secretVolumeMountPath, b.Secrets) - - return []v1beta1.Step{{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("artifact-copy-to-%s", name)), - Image: b.GsutilImage, - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", sourcePath, fmt.Sprintf("%s/%s", b.Location, destinationPath)}, - Env: envVars, - VolumeMounts: secretVolumeMount, - }} -} - -// GetSecretsVolumes returns the list of volumes for secrets to be mounted -// on pod -func (b *ArtifactBucket) GetSecretsVolumes() []corev1.Volume { - volumes := []corev1.Volume{} - for _, sec := range b.Secrets { - volumes = append(volumes, corev1.Volume{ - Name: fmt.Sprintf("volume-bucket-%s", sec.SecretName), - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: sec.SecretName, - }, - }, - }) - } - return volumes -} diff --git a/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go b/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go deleted file mode 100644 index bad8640d838..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -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 storage_test - -import ( - "fmt" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - "github.com/tektoncd/pipeline/test/diff" - "github.com/tektoncd/pipeline/test/names" - corev1 "k8s.io/api/core/v1" -) - -const ( - secretName = "secret1" -) - -var ( - expectedVolumeName = fmt.Sprintf("volume-bucket-%s", secretName) - - bucket = storage.ArtifactBucket{ - Location: "gs://fake-bucket", - Secrets: []resourcev1alpha1.SecretParam{{ - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretName: secretName, - SecretKey: "serviceaccount", - }}, - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - } -) - -func TestBucketGetCopyFromContainerSpec(t *testing.T) { - names.TestingSeed() - - want := []v1beta1.Step{{ - Name: "artifact-dest-mkdir-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/destination"}, - }, { - Name: "artifact-copy-from-workspace-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "gs://fake-bucket/src-path/*", "/workspace/destination"}, - Env: []corev1.EnvVar{{Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: fmt.Sprintf("/var/bucketsecret/%s/serviceaccount", secretName)}}, - VolumeMounts: []corev1.VolumeMount{{Name: expectedVolumeName, MountPath: fmt.Sprintf("/var/bucketsecret/%s", secretName)}}, - }} - - got := bucket.GetCopyFromStorageToSteps("workspace", "src-path", "/workspace/destination") - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} - -func TestBucketGetCopyToContainerSpec(t *testing.T) { - names.TestingSeed() - want := []v1beta1.Step{{ - Name: "artifact-copy-to-workspace-9l9zj", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "src-path", "gs://fake-bucket/workspace/destination"}, - Env: []corev1.EnvVar{{Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: fmt.Sprintf("/var/bucketsecret/%s/serviceaccount", secretName)}}, - VolumeMounts: []corev1.VolumeMount{{Name: expectedVolumeName, MountPath: fmt.Sprintf("/var/bucketsecret/%s", secretName)}}, - }} - - got := bucket.GetCopyToStorageFromSteps("workspace", "src-path", "workspace/destination") - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} - -func TestGetSecretsVolumes(t *testing.T) { - names.TestingSeed() - want := []corev1.Volume{{ - Name: expectedVolumeName, - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: secretName, - }, - }, - }} - got := bucket.GetSecretsVolumes() - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} diff --git a/pkg/apis/resource/v1alpha1/storage/artifact_pvc.go b/pkg/apis/resource/v1alpha1/storage/artifact_pvc.go deleted file mode 100644 index 117e90a7e72..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/artifact_pvc.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright 2019-2020 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 storage - -import ( - "fmt" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/names" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/ptr" -) - -var ( - pvcDir = "/pvc" -) - -// ArtifactPVC represents the pvc created by the pipelinerun for artifacts temporary storage. -// +k8s:deepcopy-gen=true -type ArtifactPVC struct { - Name string - PersistentVolumeClaim *corev1.PersistentVolumeClaim - - ShellImage string -} - -// GetType returns the type of the artifact storage. -func (p *ArtifactPVC) GetType() string { - return pipeline.ArtifactStoragePVCType -} - -// StorageBasePath returns the path to be used to store artifacts in a pipelinerun temporary storage. -func (p *ArtifactPVC) StorageBasePath(pr *v1beta1.PipelineRun) string { - return pvcDir -} - -// GetCopyFromStorageToSteps returns a container used to download artifacts from temporary storage. -func (p *ArtifactPVC) GetCopyFromStorageToSteps(name, sourcePath, destinationPath string) []v1beta1.Step { - return []v1beta1.Step{{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-copy-%s", name)), - Image: p.ShellImage, - Command: []string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath}, - Env: []corev1.EnvVar{{ - Name: "TEKTON_RESOURCE_NAME", - Value: name, - }}, - }} -} - -// GetCopyToStorageFromSteps returns a container used to upload artifacts for temporary storage. -func (p *ArtifactPVC) GetCopyToStorageFromSteps(name, sourcePath, destinationPath string) []v1beta1.Step { - return []v1beta1.Step{{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-mkdir-%s", name)), - Image: p.ShellImage, - // This requires us to run as root, and the ShellImage is nonroot - // by default. - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"mkdir", "-p", destinationPath}, - VolumeMounts: []corev1.VolumeMount{GetPvcMount(p.Name)}, - }, { - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-copy-%s", name)), - Image: p.ShellImage, - // This requires us to run as root, and the ShellImage is nonroot - // by default. - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath}, - VolumeMounts: []corev1.VolumeMount{GetPvcMount(p.Name)}, - Env: []corev1.EnvVar{{ - Name: "TEKTON_RESOURCE_NAME", - Value: name, - }}, - }} -} - -// GetPvcMount returns a mounting of the volume with the mount path /pvc. -func GetPvcMount(name string) corev1.VolumeMount { - return corev1.VolumeMount{ - Name: name, // taskrun pvc name - MountPath: pvcDir, // nothing should be mounted here - } -} - -// GetSecretsVolumes returns the list of volumes for secrets to be mounted on -// pod. -func (p *ArtifactPVC) GetSecretsVolumes() []corev1.Volume { return nil } diff --git a/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go b/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go deleted file mode 100644 index 1894a9ac10f..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go +++ /dev/null @@ -1,128 +0,0 @@ -/* -Copyright 2019-2020 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 storage_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - "github.com/tektoncd/pipeline/test/diff" - "github.com/tektoncd/pipeline/test/names" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/ptr" -) - -func TestPVCGetCopyFromContainerSpec(t *testing.T) { - names.TestingSeed() - - pvc := storage.ArtifactPVC{ - Name: "pipelinerun-pvc", - ShellImage: "busybox", - } - want := []v1beta1.Step{{ - Name: "source-copy-workspace-9l9zj", - Image: "busybox", - - Command: []string{"cp", "-r", "src-path/.", "/workspace/destination"}, - Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "workspace"}}, - }} - - got := pvc.GetCopyFromStorageToSteps("workspace", "src-path", "/workspace/destination") - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} - -func TestPVCGetCopyToContainerSpec(t *testing.T) { - names.TestingSeed() - - pvc := storage.ArtifactPVC{ - Name: "pipelinerun-pvc", - ShellImage: "busybox", - } - want := []v1beta1.Step{{ - Name: "source-mkdir-workspace-9l9zj", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"mkdir", "-p", "/workspace/destination"}, - VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}}, - }, { - Name: "source-copy-workspace-mz4c7", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"cp", "-r", "src-path/.", "/workspace/destination"}, - VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}}, - Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "workspace"}}, - }} - - got := pvc.GetCopyToStorageFromSteps("workspace", "src-path", "/workspace/destination") - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} - -func TestPVCGetPvcMount(t *testing.T) { - names.TestingSeed() - name := "pipelinerun-pvc" - pvcDir := "/pvc" - - want := corev1.VolumeMount{ - Name: name, - MountPath: pvcDir, - } - got := storage.GetPvcMount(name) - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} - -func TestPVCGetMakeStep(t *testing.T) { - names.TestingSeed() - - want := v1beta1.Step{ - Name: "create-dir-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/destination"}, - } - got := storage.CreateDirStep("busybox", "workspace", "/workspace/destination") - if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} - -func TestStorageBasePath(t *testing.T) { - pvc := storage.ArtifactPVC{ - Name: "pipelinerun-pvc", - } - pipelinerun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "pipelineruntest", - }, - } - got := pvc.StorageBasePath(pipelinerun) - if d := cmp.Diff(got, "/pvc"); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } -} diff --git a/pkg/apis/resource/v1alpha1/storage/gcs.go b/pkg/apis/resource/v1alpha1/storage/gcs.go deleted file mode 100644 index 9660a3975fa..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/gcs.go +++ /dev/null @@ -1,172 +0,0 @@ -/* -Copyright 2019-2020 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 storage - -import ( - "fmt" - "path/filepath" - "strings" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/names" - corev1 "k8s.io/api/core/v1" -) - -const ( - gcsSecretVolumeMountPath = "/var/secret" - activateServiceAccountScript = `#!/usr/bin/env bash -if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then - echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account... - gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} -fi -` -) - -// GCSResource is a GCS endpoint from which to get artifacts which is required -// by a Build/Task for context (e.g. a archive from which to build an image). -type GCSResource struct { - Name string `json:"name"` - Type resourcev1alpha1.PipelineResourceType `json:"type"` - Location string `json:"location"` - TypeDir bool `json:"typeDir"` - // Secret holds a struct to indicate a field name and corresponding secret name to populate it - Secrets []resourcev1alpha1.SecretParam `json:"secrets"` - - ShellImage string `json:"-"` - GsutilImage string `json:"-"` -} - -// NewGCSResource creates a new GCS resource to pass to a Task -func NewGCSResource(name string, images pipeline.Images, r *resourcev1alpha1.PipelineResource) (*GCSResource, error) { - if r.Spec.Type != resourcev1alpha1.PipelineResourceTypeStorage { - return nil, fmt.Errorf("GCSResource: Cannot create a GCS resource from a %s Pipeline Resource", r.Spec.Type) - } - var location string - var locationSpecified, dir bool - - for _, param := range r.Spec.Params { - switch { - case strings.EqualFold(param.Name, "Location"): - location = param.Value - if param.Value != "" { - locationSpecified = true - } - case strings.EqualFold(param.Name, "Dir"): - dir = true // if dir flag is present then its a dir - } - } - - if !locationSpecified { - return nil, fmt.Errorf("GCSResource: Need Location to be specified in order to create GCS resource %s", r.Name) - } - return &GCSResource{ - Name: name, - Type: r.Spec.Type, - Location: location, - TypeDir: dir, - Secrets: r.Spec.SecretParams, - ShellImage: images.ShellImage, - GsutilImage: images.GsutilImage, - }, nil -} - -// GetName returns the name of the resource -func (s GCSResource) GetName() string { - return s.Name -} - -// GetType returns the type of the resource, in this case "storage" -func (s GCSResource) GetType() resourcev1alpha1.PipelineResourceType { - return resourcev1alpha1.PipelineResourceTypeStorage -} - -// GetSecretParams returns the resource secret params -func (s *GCSResource) GetSecretParams() []resourcev1alpha1.SecretParam { return s.Secrets } - -// Replacements is used for template replacement on an GCSResource inside of a Taskrun. -func (s *GCSResource) Replacements() map[string]string { - return map[string]string{ - "name": s.Name, - "type": s.Type, - "location": s.Location, - } -} - -// GetOutputTaskModifier returns the TaskModifier to be used when this resource is an output. -func (s *GCSResource) GetOutputTaskModifier(ts *v1beta1.TaskSpec, path string) (v1beta1.TaskModifier, error) { - var args []string - if s.TypeDir { - args = []string{"rsync", "-d", "-r", path, s.Location} - } else { - args = []string{"cp", filepath.Join(path, "*"), s.Location} - } - - envVars, secretVolumeMount := getSecretEnvVarsAndVolumeMounts(s.Name, gcsSecretVolumeMountPath, s.Secrets) - - envVars = append(envVars, corev1.EnvVar{Name: "HOME", Value: pipeline.HomeDir}) - - step := v1beta1.Step{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("upload-%s", s.Name)), - Image: s.GsutilImage, - Command: []string{"gsutil"}, - Args: args, - VolumeMounts: secretVolumeMount, - Env: envVars, - } - - volumes := getStorageVolumeSpec(s, *ts) - - return &v1beta1.InternalTaskModifier{ - StepsToAppend: []v1beta1.Step{step}, - Volumes: volumes, - }, nil -} - -// GetInputTaskModifier returns the TaskModifier to be used when this resource is an input. -func (s *GCSResource) GetInputTaskModifier(ts *v1beta1.TaskSpec, path string) (v1beta1.TaskModifier, error) { - if path == "" { - return nil, fmt.Errorf("GCSResource: Expect Destination Directory param to be set %s", s.Name) - } - script := activateServiceAccountScript - if s.TypeDir { - script += fmt.Sprintf("gsutil rsync -d -r %s %s\n", s.Location, path) - } else { - script += fmt.Sprintf("gsutil cp %s %s\n", s.Location, path) - } - - envVars, secretVolumeMount := getSecretEnvVarsAndVolumeMounts(s.Name, gcsSecretVolumeMountPath, s.Secrets) - envVars = append(envVars, corev1.EnvVar{Name: "HOME", Value: pipeline.HomeDir}) - steps := []v1beta1.Step{ - CreateDirStep(s.ShellImage, s.Name, path), - { - Script: script, - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("fetch-%s", s.Name)), - Image: s.GsutilImage, - Env: envVars, - VolumeMounts: secretVolumeMount, - }, - } - - volumes := getStorageVolumeSpec(s, *ts) - - return &v1beta1.InternalTaskModifier{ - StepsToPrepend: steps, - Volumes: volumes, - }, nil -} diff --git a/pkg/apis/resource/v1alpha1/storage/gcs_test.go b/pkg/apis/resource/v1alpha1/storage/gcs_test.go deleted file mode 100644 index 289b5b9a075..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/gcs_test.go +++ /dev/null @@ -1,457 +0,0 @@ -/* -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 storage_test - -import ( - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - "github.com/tektoncd/pipeline/test/diff" - "github.com/tektoncd/pipeline/test/names" - corev1 "k8s.io/api/core/v1" -) - -var images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", -} - -func TestInvalidNewStorageResource(t *testing.T) { - for _, tc := range []struct { - name string - pipelineResource *resourcev1alpha1.PipelineResource - }{{ - name: "wrong-resource-type", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - }, { - name: "unimplemented type", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "Location", - Value: "gs://fake-bucket", - }, - { - Name: "type", - Value: "non-existent-type", - }, - }, - }, - }, - }, { - name: "no type", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://fake-bucket", - }}, - }, - }, - }, { - name: "no location params", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "NotLocation", - Value: "doesntmatter", - }, - { - Name: "type", - Value: "gcs", - }, - }, - }, - }, - }, { - name: "location param with empty value", - pipelineResource: &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "Location", - Value: "", - }, - { - Name: "type", - Value: "gcs", - }, - }, - }, - }, - }} { - t.Run(tc.name, func(t *testing.T) { - _, err := storage.NewResource("test-resource", images, tc.pipelineResource) - if err == nil { - t.Error("Expected error creating GCS resource") - } - }) - } -} - -func TestValidNewGCSResource(t *testing.T) { - pr := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "Location", - Value: "gs://fake-bucket", - }, - { - Name: "type", - Value: "gcs", - }, - { - Name: "dir", - Value: "anything", - }, - }, - SecretParams: []resourcev1alpha1.SecretParam{{ - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretKey: "secretKey", - SecretName: "secretName", - }}, - }, - } - expectedGCSResource := &storage.GCSResource{ - Name: "test-resource", - Location: "gs://fake-bucket", - Type: resourcev1alpha1.PipelineResourceTypeStorage, - TypeDir: true, - Secrets: []resourcev1alpha1.SecretParam{{ - SecretName: "secretName", - SecretKey: "secretKey", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - }}, - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - } - - gcsRes, err := storage.NewGCSResource("test-resource", images, pr) - if err != nil { - t.Fatalf("Unexpected error creating GCS resource: %s", err) - } - if d := cmp.Diff(expectedGCSResource, gcsRes); d != "" { - t.Errorf("Mismatch of GCS resource %s", diff.PrintWantGot(d)) - } -} - -func TestGCSGetReplacements(t *testing.T) { - gcsResource := &storage.GCSResource{ - Name: "gcs-resource", - Location: "gs://fake-bucket", - Type: resourcev1alpha1.PipelineResourceTypeGCS, - } - expectedReplacementMap := map[string]string{ - "name": "gcs-resource", - "type": "gcs", - "location": "gs://fake-bucket", - } - if d := cmp.Diff(gcsResource.Replacements(), expectedReplacementMap); d != "" { - t.Errorf("GCS Replacement map mismatch %s", diff.PrintWantGot(d)) - } -} - -func TestGetParams(t *testing.T) { - pr := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{ - { - Name: "Location", - Value: "gs://some-bucket.zip", - }, - { - Name: "type", - Value: "gcs", - }, - { - Name: "dir", - Value: "anything", - }, - }, - SecretParams: []resourcev1alpha1.SecretParam{{ - FieldName: "test-field-name", - SecretKey: "test-secret-key", - SecretName: "test-secret-name", - }}, - }, - } - gcsResource, err := storage.NewResource("test-resource", images, pr) - if err != nil { - t.Fatalf("Error creating storage resource: %s", err.Error()) - } - expectedSp := []resourcev1alpha1.SecretParam{{ - SecretKey: "test-secret-key", - SecretName: "test-secret-name", - FieldName: "test-field-name", - }} - if d := cmp.Diff(gcsResource.GetSecretParams(), expectedSp); d != "" { - t.Errorf("Error mismatch on storage secret params %s", diff.PrintWantGot(d)) - } -} - -func TestGetInputSteps(t *testing.T) { - names.TestingSeed() - - for _, tc := range []struct { - name string - gcsResource *storage.GCSResource - wantSteps []v1beta1.Step - wantErr bool - }{{ - name: "valid download protected buckets", - gcsResource: &storage.GCSResource{ - Name: "gcs-valid", - Location: "gs://some-bucket", - TypeDir: true, - Secrets: []resourcev1alpha1.SecretParam{{ - SecretName: "secretName", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretKey: "key.json", - }}, - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-gcs-valid-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace"}, - }, { - Script: `#!/usr/bin/env bash -if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then - echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account... - gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} -fi -gsutil rsync -d -r gs://some-bucket /workspace -`, - Name: "fetch-gcs-valid-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Env: []corev1.EnvVar{{ - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/secret/secretName/key.json", - }, { - Name: "HOME", - Value: "/tekton/home", - }}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-gcs-valid-secretName", - MountPath: "/var/secret/secretName", - }}, - }}, - }, { - name: "duplicate secret mount paths", - gcsResource: &storage.GCSResource{ - Name: "gcs-valid", - Location: "gs://some-bucket", - Secrets: []resourcev1alpha1.SecretParam{{ - SecretName: "secretName", - FieldName: "fieldName", - SecretKey: "key.json", - }, { - SecretKey: "key.json", - SecretName: "secretName", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - }}, - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-gcs-valid-mssqb", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace"}, - }, { - Script: `#!/usr/bin/env bash -if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then - echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account... - gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} -fi -gsutil cp gs://some-bucket /workspace -`, - Name: "fetch-gcs-valid-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Env: []corev1.EnvVar{{ - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/secret/secretName/key.json", - }, { - Name: "HOME", - Value: "/tekton/home", - }}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-gcs-valid-secretName", - MountPath: "/var/secret/secretName", - }}, - }}, - }} { - t.Run(tc.name, func(t *testing.T) { - ts := v1beta1.TaskSpec{} - gotSpec, err := tc.gcsResource.GetInputTaskModifier(&ts, "/workspace") - if tc.wantErr && err == nil { - t.Fatalf("Expected error to be %t but got %v:", tc.wantErr, err) - } - if d := cmp.Diff(tc.wantSteps, gotSpec.GetStepsToPrepend()); d != "" { - t.Errorf("Diff %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestGetOutputTaskModifier(t *testing.T) { - names.TestingSeed() - - for _, tc := range []struct { - name string - gcsResource *storage.GCSResource - wantSteps []v1beta1.Step - wantErr bool - }{{ - name: "valid upload to protected buckets with directory paths", - gcsResource: &storage.GCSResource{ - Name: "gcs-valid", - Location: "gs://some-bucket", - TypeDir: true, - Secrets: []resourcev1alpha1.SecretParam{{ - SecretName: "secretName", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretKey: "key.json", - }}, - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - wantSteps: []v1beta1.Step{{ - Name: "upload-gcs-valid-9l9zj", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/", "gs://some-bucket"}, - Env: []corev1.EnvVar{{ - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/secret/secretName/key.json", - }, { - Name: "HOME", - Value: "/tekton/home", - }}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-gcs-valid-secretName", - MountPath: "/var/secret/secretName", - }}, - }}, - }, { - name: "duplicate secret mount paths", - gcsResource: &storage.GCSResource{ - Name: "gcs-valid", - Location: "gs://some-bucket", - Secrets: []resourcev1alpha1.SecretParam{{ - SecretName: "secretName", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretKey: "key.json", - }, { - SecretKey: "key.json", - SecretName: "secretName", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - }}, - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - wantSteps: []v1beta1.Step{{ - Name: "upload-gcs-valid-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "/workspace/*", "gs://some-bucket"}, - Env: []corev1.EnvVar{{ - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/secret/secretName/key.json", - }, { - Name: "HOME", - Value: "/tekton/home", - }}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-gcs-valid-secretName", - MountPath: "/var/secret/secretName", - }}, - }}, - }, { - name: "valid upload to protected buckets with single file", - gcsResource: &storage.GCSResource{ - Name: "gcs-valid", - Location: "gs://some-bucket", - TypeDir: false, - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - wantSteps: []v1beta1.Step{{ - Name: "upload-gcs-valid-mssqb", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "/workspace/*", "gs://some-bucket"}, - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: "/tekton/home", - }}, - }}, - }} { - t.Run(tc.name, func(t *testing.T) { - ts := v1beta1.TaskSpec{} - got, err := tc.gcsResource.GetOutputTaskModifier(&ts, "/workspace/") - if (err != nil) != tc.wantErr { - t.Fatalf("Expected error to be %t but got %v:", tc.wantErr, err) - } - - if d := cmp.Diff(tc.wantSteps, got.GetStepsToAppend()); d != "" { - t.Errorf("Error mismatch between upload containers spec %s", diff.PrintWantGot(d)) - } - }) - } -} diff --git a/pkg/apis/resource/v1alpha1/storage/secret.go b/pkg/apis/resource/v1alpha1/storage/secret.go deleted file mode 100644 index 03ed0807274..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/secret.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2019-2020 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 storage - -import ( - "fmt" - "path/filepath" - "strings" - - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - corev1 "k8s.io/api/core/v1" -) - -func getSecretEnvVarsAndVolumeMounts(name, mountPath string, secrets []resource.SecretParam) ([]corev1.EnvVar, []corev1.VolumeMount) { - mountPaths := make(map[string]struct{}) - var ( - envVars []corev1.EnvVar - secretVolumeMount []corev1.VolumeMount - ) - - allowedFields := map[string]bool{ - "GOOGLE_APPLICATION_CREDENTIALS": false, - "BOTO_CONFIG": false, - } - - for _, secretParam := range secrets { - if authVar, ok := allowedFields[secretParam.FieldName]; ok && !authVar { - allowedFields[secretParam.FieldName] = true - mountPath := filepath.Join(mountPath, secretParam.SecretName) - - envVars = append(envVars, corev1.EnvVar{ - Name: strings.ToUpper(secretParam.FieldName), - Value: filepath.Join(mountPath, secretParam.SecretKey), - }) - - if _, ok := mountPaths[mountPath]; !ok { - secretVolumeMount = append(secretVolumeMount, corev1.VolumeMount{ - Name: fmt.Sprintf("volume-%s-%s", name, secretParam.SecretName), - MountPath: mountPath, - }) - mountPaths[mountPath] = struct{}{} - } - } - } - return envVars, secretVolumeMount -} diff --git a/pkg/apis/resource/v1alpha1/storage/storage.go b/pkg/apis/resource/v1alpha1/storage/storage.go deleted file mode 100644 index 7fa7bf13e39..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/storage.go +++ /dev/null @@ -1,92 +0,0 @@ -/* -Copyright 2019-2020 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 storage - -import ( - "fmt" - "strings" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/names" - corev1 "k8s.io/api/core/v1" -) - -// PipelineStorageResourceInterface adds a function to the PipelineResourceInterface for retrieving -// secrets that are usually needed for storage PipelineResources. -type PipelineStorageResourceInterface interface { - v1beta1.PipelineResourceInterface - GetSecretParams() []resource.SecretParam -} - -// NewResource returns an instance of the requested storage subtype, which can be used -// to add input and output steps and volumes to an executing pod. -func NewResource(name string, images pipeline.Images, r *resource.PipelineResource) (PipelineStorageResourceInterface, error) { - if r.Spec.Type != v1beta1.PipelineResourceTypeStorage { - return nil, fmt.Errorf("StoreResource: Cannot create a storage resource from a %s Pipeline Resource", r.Spec.Type) - } - - for _, param := range r.Spec.Params { - if strings.EqualFold(param.Name, "type") { - if strings.EqualFold(param.Value, resource.PipelineResourceTypeGCS) { - return NewGCSResource(name, images, r) - } - return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineStorageResource", param.Value) - } - } - return nil, fmt.Errorf("StoreResource: Cannot create a storage resource without type %s in spec", r.Name) -} - -func getStorageVolumeSpec(s PipelineStorageResourceInterface, spec v1beta1.TaskSpec) []corev1.Volume { - var storageVol []corev1.Volume - mountedSecrets := map[string]struct{}{} - - for _, volume := range spec.Volumes { - mountedSecrets[volume.Name] = struct{}{} - } - - // Map holds list of secrets that are mounted as volumes - for _, secretParam := range s.GetSecretParams() { - volName := fmt.Sprintf("volume-%s-%s", s.GetName(), secretParam.SecretName) - if _, ok := mountedSecrets[volName]; ok { - // There is already a volume mounted with this name - continue - } - - gcsSecretVolume := corev1.Volume{ - Name: volName, - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: secretParam.SecretName, - }, - }, - } - storageVol = append(storageVol, gcsSecretVolume) - mountedSecrets[volName] = struct{}{} - } - return storageVol -} - -// CreateDirStep returns a Step that creates a given directory with a given name. -func CreateDirStep(shellImage string, name, destinationPath string) v1beta1.Step { - return v1beta1.Step{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("create-dir-%s", strings.ToLower(name))), - Image: shellImage, - Command: []string{"mkdir", "-p", destinationPath}, - } -} diff --git a/pkg/apis/resource/v1alpha1/storage/zz_generated.deepcopy.go b/pkg/apis/resource/v1alpha1/storage/zz_generated.deepcopy.go deleted file mode 100644 index 4477bf20762..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/zz_generated.deepcopy.go +++ /dev/null @@ -1,69 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright 2020 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. -*/ - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package storage - -import ( - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - v1 "k8s.io/api/core/v1" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ArtifactBucket) DeepCopyInto(out *ArtifactBucket) { - *out = *in - if in.Secrets != nil { - in, out := &in.Secrets, &out.Secrets - *out = make([]v1alpha1.SecretParam, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArtifactBucket. -func (in *ArtifactBucket) DeepCopy() *ArtifactBucket { - if in == nil { - return nil - } - out := new(ArtifactBucket) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ArtifactPVC) DeepCopyInto(out *ArtifactPVC) { - *out = *in - if in.PersistentVolumeClaim != nil { - in, out := &in.PersistentVolumeClaim, &out.PersistentVolumeClaim - *out = new(v1.PersistentVolumeClaim) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArtifactPVC. -func (in *ArtifactPVC) DeepCopy() *ArtifactPVC { - if in == nil { - return nil - } - out := new(ArtifactPVC) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/artifacts/artifact_storage_test.go b/pkg/artifacts/artifact_storage_test.go deleted file mode 100644 index 238423747c2..00000000000 --- a/pkg/artifacts/artifact_storage_test.go +++ /dev/null @@ -1,620 +0,0 @@ -/* -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 artifacts - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - "github.com/tektoncd/pipeline/test/diff" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - fakek8s "k8s.io/client-go/kubernetes/fake" - "knative.dev/pkg/kmeta" -) - -var ( - images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", - } - pipelinerun = &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "pipelineruntest", - }, - } - defaultStorageClass *string - customStorageClass = "custom-storage-class" - persistentVolumeClaim = getPersistentVolumeClaim(config.DefaultPVCSize, defaultStorageClass) - quantityComparer = cmp.Comparer(func(x, y resource.Quantity) bool { - return x.Cmp(y) == 0 - }) - - pipelineWithTasksWithFrom = v1beta1.Pipeline{ - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{{ - Name: "input1", - Type: "git", - }, { - Name: "output", - Type: "git", - }}, - Tasks: []v1beta1.PipelineTask{ - { - Name: "task1", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "foo", - Resource: "output", - }}, - }, - }, - { - Name: "task2", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "foo", - Resource: "output", - From: []string{"task1"}, - }}, - }, - }, - }, - }, - } -) - -func getPersistentVolumeClaim(size string, storageClassName *string) *corev1.PersistentVolumeClaim { - pvc := &corev1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelineruntest-pvc", Namespace: pipelinerun.Namespace, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(pipelinerun)}}, - Spec: corev1.PersistentVolumeClaimSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(size)}}, - StorageClassName: storageClassName, - }, - } - return pvc -} - -func TestNeedsPVC(t *testing.T) { - for _, c := range []struct { - desc string - bucketConfig map[string]string - pvcNeeded bool - }{{ - desc: "valid bucket", - bucketConfig: map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - pvcNeeded: false, - }, { - desc: "location empty", - bucketConfig: map[string]string{ - config.BucketLocationKey: "", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - pvcNeeded: true, - }, { - desc: "missing location", - bucketConfig: map[string]string{ - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - pvcNeeded: true, - }, { - desc: "no config map data", - bucketConfig: map[string]string{}, - pvcNeeded: true, - }, { - desc: "no secret", - bucketConfig: map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - }, - pvcNeeded: false, - }} { - t.Run(c.desc, func(t *testing.T) { - artifactBucket, _ := config.NewArtifactBucketFromMap(c.bucketConfig) - configs := config.Config{ - ArtifactBucket: artifactBucket, - } - ctx := config.ToContext(context.Background(), &configs) - needed := needsPVC(ctx) - if needed != c.pvcNeeded { - t.Fatalf("Expected that ConfigMapNeedsPVC would be %t, but was %t", c.pvcNeeded, needed) - } - }) - } -} - -func TestInitializeArtifactStorage(t *testing.T) { - for _, c := range []struct { - desc string - storageConfig map[string]string - storagetype string - expectedArtifactStorage ArtifactStorageInterface - }{{ - desc: "pvc configmap size", - storageConfig: map[string]string{ - config.PVCSizeKey: "10Gi", - }, - storagetype: "pvc", - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: "pipelineruntest", - PersistentVolumeClaim: getPersistentVolumeClaim("10Gi", defaultStorageClass), - ShellImage: "busybox", - }, - }, { - desc: "pvc configmap storageclass", - storageConfig: map[string]string{ - config.PVCStorageClassNameKey: customStorageClass, - }, - storagetype: "pvc", - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: "pipelineruntest", - PersistentVolumeClaim: getPersistentVolumeClaim("5Gi", &customStorageClass), - ShellImage: "busybox", - }, - }, { - desc: "valid bucket", - storageConfig: map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - storagetype: "bucket", - expectedArtifactStorage: &storage.ArtifactBucket{ - Location: "gs://fake-bucket", - Secrets: []resourcev1alpha1.SecretParam{{ - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretKey: "sakey", - SecretName: "secret1", - }}, - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - }, { - desc: "location empty", - storageConfig: map[string]string{ - config.BucketLocationKey: "", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - storagetype: "pvc", - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: "pipelineruntest", - PersistentVolumeClaim: persistentVolumeClaim, - ShellImage: "busybox", - }, - }, { - desc: "missing location", - storageConfig: map[string]string{ - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - storagetype: "pvc", - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: "pipelineruntest", - PersistentVolumeClaim: persistentVolumeClaim, - ShellImage: "busybox", - }, - }, { - desc: "no config map data", - storageConfig: map[string]string{}, - storagetype: "pvc", - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: "pipelineruntest", - PersistentVolumeClaim: persistentVolumeClaim, - ShellImage: "busybox", - }, - }, { - desc: "no secret", - storageConfig: map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - }, - storagetype: "bucket", - expectedArtifactStorage: &storage.ArtifactBucket{ - Location: "gs://fake-bucket", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - }, { - desc: "valid bucket with boto config", - storageConfig: map[string]string{ - config.BucketLocationKey: "s3://fake-bucket", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - config.BucketServiceAccountFieldNameKey: "BOTO_CONFIG", - }, - storagetype: "bucket", - expectedArtifactStorage: &storage.ArtifactBucket{ - Location: "s3://fake-bucket", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Secrets: []resourcev1alpha1.SecretParam{{ - FieldName: "BOTO_CONFIG", - SecretKey: "sakey", - SecretName: "secret1", - }}, - }, - }} { - t.Run(c.desc, func(t *testing.T) { - fakekubeclient := fakek8s.NewSimpleClientset() - configs := config.Config{} - if c.storagetype == "bucket" { - configs.ArtifactBucket, _ = config.NewArtifactBucketFromMap(c.storageConfig) - } else { - configs.ArtifactPVC, _ = config.NewArtifactPVCFromMap(c.storageConfig) - } - ctx := config.ToContext(context.Background(), &configs) - artifactStorage, err := InitializeArtifactStorage(ctx, images, pipelinerun, &pipelineWithTasksWithFrom.Spec, fakekubeclient) - if err != nil { - t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err) - } - if artifactStorage == nil { - t.Fatal("artifactStorage was nil, expected an actual value") - } - // If the expected storage type is PVC, make sure we're actually creating that PVC. - if c.storagetype == "pvc" { - _, err := fakekubeclient.CoreV1().PersistentVolumeClaims(pipelinerun.Namespace).Get(ctx, GetPVCName(pipelinerun), metav1.GetOptions{}) - if err != nil { - t.Fatalf("Error getting expected PVC %s for PipelineRun %s: %s", GetPVCName(pipelinerun), pipelinerun.Name, err) - } - } - // Make sure we don't get any errors running CleanupArtifactStorage against the resulting storage, whether it's - // a bucket or a PVC. - if err := CleanupArtifactStorage(ctx, pipelinerun, fakekubeclient); err != nil { - t.Fatalf("Error cleaning up artifact storage: %s", err) - } - if d := cmp.Diff(artifactStorage.GetType(), c.storagetype); d != "" { - t.Fatalf(diff.PrintWantGot(d)) - } - if d := cmp.Diff(artifactStorage, c.expectedArtifactStorage, quantityComparer); d != "" { - t.Fatalf(diff.PrintWantGot(d)) - } - }) - } -} - -func TestInitializeArtifactStorageNoStorageNeeded(t *testing.T) { - // This Pipeline has Tasks that use both inputs and outputs, but there is - // no link between the inputs and outputs, so no storage is needed - pipeline := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "pipelineruntest", - }, - Spec: v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{ - { - Name: "task1", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "resource", - }}, - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "output", - Resource: "resource", - }}, - }, - }, - { - Name: "task2", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "resource", - }}, - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "output", - Resource: "resource", - }}, - }, - }, - }, - }, - } - pipelinerun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun", - Namespace: "namespace", - }, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - }, - } - for _, c := range []struct { - desc string - storageConfig map[string]string - storagetype string - }{{ - desc: "has pvc configured", - storageConfig: map[string]string{ - config.PVCSizeKey: "10Gi", - }, - storagetype: "pvc", - }, { - desc: "has bucket configured", - storageConfig: map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - storagetype: "bucket", - }, { - desc: "no configmap", - storageConfig: map[string]string{ - config.BucketLocationKey: "", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - storagetype: "bucket", - }} { - t.Run(c.desc, func(t *testing.T) { - fakekubeclient := fakek8s.NewSimpleClientset() - configs := config.Config{} - if c.storagetype == "bucket" { - configs.ArtifactBucket, _ = config.NewArtifactBucketFromMap(c.storageConfig) - } else { - configs.ArtifactPVC, _ = config.NewArtifactPVCFromMap(c.storageConfig) - } - ctx := config.ToContext(context.Background(), &configs) - artifactStorage, err := InitializeArtifactStorage(ctx, images, pipelinerun, &pipeline.Spec, fakekubeclient) - if err != nil { - t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err) - } - if artifactStorage.GetType() != "none" { - t.Errorf("Expected NoneArtifactStorage when none is needed but got %s", artifactStorage.GetType()) - } - }) - } -} - -func TestCleanupArtifactStorage(t *testing.T) { - pipelinerun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "pipelineruntest", - }, - } - for _, c := range []struct { - desc string - storageConfig map[string]string - }{{ - desc: "location empty", - storageConfig: map[string]string{ - config.BucketLocationKey: "", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - }, { - desc: "missing location", - storageConfig: map[string]string{ - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - }, { - desc: "no config map data", - storageConfig: map[string]string{}, - }} { - t.Run(c.desc, func(t *testing.T) { - fakekubeclient := fakek8s.NewSimpleClientset(getPVCSpec(pipelinerun, persistentVolumeClaim.Spec.Resources.Requests["storage"], defaultStorageClass)) - ab, err := config.NewArtifactBucketFromMap(c.storageConfig) - if err != nil { - t.Fatalf("Error getting an ArtifactBucket from data %s, %s", c.storageConfig, err) - } - configs := config.Config{ - ArtifactBucket: ab, - } - ctx := config.ToContext(context.Background(), &configs) - _, err = fakekubeclient.CoreV1().PersistentVolumeClaims(pipelinerun.Namespace).Get(ctx, GetPVCName(pipelinerun), metav1.GetOptions{}) - if err != nil { - t.Fatalf("Error getting expected PVC %s for PipelineRun %s: %s", GetPVCName(pipelinerun), pipelinerun.Name, err) - } - if err := CleanupArtifactStorage(ctx, pipelinerun, fakekubeclient); err != nil { - t.Fatalf("Error cleaning up artifact storage: %s", err) - } - _, err = fakekubeclient.CoreV1().PersistentVolumeClaims(pipelinerun.Namespace).Get(ctx, GetPVCName(pipelinerun), metav1.GetOptions{}) - if err == nil { - t.Fatalf("Found PVC %s for PipelineRun %s after it should have been cleaned up", GetPVCName(pipelinerun), pipelinerun.Name) - } else if !errors.IsNotFound(err) { - t.Fatalf("Error checking if PVC %s for PipelineRun %s has been cleaned up: %s", GetPVCName(pipelinerun), pipelinerun.Name, err) - } - }) - } -} - -func TestInitializeArtifactStorageWithoutConfigMap(t *testing.T) { - pipelinerun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelineruntest", - Namespace: "foo", - }, - } - fakekubeclient := fakek8s.NewSimpleClientset() - - pvc, err := InitializeArtifactStorage(context.Background(), images, pipelinerun, &pipelineWithTasksWithFrom.Spec, fakekubeclient) - if err != nil { - t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err) - } - - expectedArtifactPVC := &storage.ArtifactPVC{ - Name: "pipelineruntest", - PersistentVolumeClaim: persistentVolumeClaim, - ShellImage: "busybox", - } - - if d := cmp.Diff(pvc, expectedArtifactPVC, cmpopts.IgnoreUnexported(resource.Quantity{})); d != "" { - t.Fatalf(diff.PrintWantGot(d)) - } -} - -func TestGetArtifactStorageWithConfig(t *testing.T) { - pipelinerun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "pipelineruntest", - }, - } - for _, c := range []struct { - desc string - storageConfig map[string]string - expectedArtifactStorage ArtifactStorageInterface - }{{ - desc: "valid bucket", - storageConfig: map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - expectedArtifactStorage: &storage.ArtifactBucket{ - Location: "gs://fake-bucket", - Secrets: []resourcev1alpha1.SecretParam{{ - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - SecretKey: "sakey", - SecretName: "secret1", - }}, - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - }, - }, { - desc: "location empty", - storageConfig: map[string]string{ - config.BucketLocationKey: "", - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: pipelinerun.Name, - ShellImage: "busybox", - }, - }, { - desc: "missing location", - storageConfig: map[string]string{ - config.BucketServiceAccountSecretNameKey: "secret1", - config.BucketServiceAccountSecretKeyKey: "sakey", - }, - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: pipelinerun.Name, - ShellImage: "busybox", - }, - }, { - desc: "no config map data", - storageConfig: map[string]string{}, - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: pipelinerun.Name, - ShellImage: "busybox", - }, - }} { - t.Run(c.desc, func(t *testing.T) { - fakekubeclient := fakek8s.NewSimpleClientset() - ab, err := config.NewArtifactBucketFromMap(c.storageConfig) - if err != nil { - t.Fatalf("Error getting an ArtifactBucket from data %s, %s", c.storageConfig, err) - } - configs := config.Config{ - ArtifactBucket: ab, - } - ctx := config.ToContext(context.Background(), &configs) - artifactStorage := GetArtifactStorage(ctx, images, pipelinerun.Name, fakekubeclient) - - if d := cmp.Diff(artifactStorage, c.expectedArtifactStorage); d != "" { - t.Fatalf(diff.PrintWantGot(d)) - } - }) - } -} - -func TestGetArtifactStorageWithoutConfig(t *testing.T) { - fakekubeclient := fakek8s.NewSimpleClientset() - pvc := GetArtifactStorage(context.Background(), images, "pipelineruntest", fakekubeclient) - - expectedArtifactPVC := &storage.ArtifactPVC{ - Name: "pipelineruntest", - ShellImage: "busybox", - } - - if d := cmp.Diff(pvc, expectedArtifactPVC); d != "" { - t.Fatalf(diff.PrintWantGot(d)) - } -} - -func TestGetArtifactStorageWithPVCConfig(t *testing.T) { - prName := "pipelineruntest" - for _, c := range []struct { - desc string - storageConfig map[string]string - expectedArtifactStorage ArtifactStorageInterface - }{{ - desc: "valid pvc", - storageConfig: map[string]string{ - config.PVCSizeKey: "10Gi", - }, - expectedArtifactStorage: &storage.ArtifactPVC{ - Name: "pipelineruntest", - ShellImage: "busybox", - }, - }} { - t.Run(c.desc, func(t *testing.T) { - fakekubeclient := fakek8s.NewSimpleClientset() - ap, err := config.NewArtifactPVCFromMap(c.storageConfig) - if err != nil { - t.Fatalf("Error getting an ArtifactPVC from data %s, %s", c.storageConfig, err) - } - configs := config.Config{ - ArtifactPVC: ap, - } - ctx := config.ToContext(context.Background(), &configs) - artifactStorage := GetArtifactStorage(ctx, images, prName, fakekubeclient) - - if d := cmp.Diff(artifactStorage, c.expectedArtifactStorage); d != "" { - t.Fatalf(diff.PrintWantGot(d)) - } - }) - } -} diff --git a/pkg/artifacts/artifacts_storage.go b/pkg/artifacts/artifacts_storage.go deleted file mode 100644 index 60d0c0f0b9a..00000000000 --- a/pkg/artifacts/artifacts_storage.go +++ /dev/null @@ -1,244 +0,0 @@ -/* -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 artifacts - -import ( - "context" - "fmt" - "strings" - - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/client-go/kubernetes" - "knative.dev/pkg/kmeta" - "knative.dev/pkg/logging" -) - -// ArtifactStorageInterface is an interface to define the steps to copy -// an pipeline artifact to/from temporary storage -type ArtifactStorageInterface interface { - GetCopyToStorageFromSteps(name, sourcePath, destinationPath string) []v1beta1.Step - GetCopyFromStorageToSteps(name, sourcePath, destinationPath string) []v1beta1.Step - GetSecretsVolumes() []corev1.Volume - GetType() string - StorageBasePath(pr *v1beta1.PipelineRun) string -} - -// ArtifactStorageNone is used when no storage is needed. -type ArtifactStorageNone struct{} - -// GetCopyToStorageFromSteps returns no containers because none are needed. -func (a *ArtifactStorageNone) GetCopyToStorageFromSteps(name, sourcePath, destinationPath string) []v1beta1.Step { - return nil -} - -// GetCopyFromStorageToSteps returns no containers because none are needed. -func (a *ArtifactStorageNone) GetCopyFromStorageToSteps(name, sourcePath, destinationPath string) []v1beta1.Step { - return nil -} - -// GetSecretsVolumes returns no volumes because none are needed. -func (a *ArtifactStorageNone) GetSecretsVolumes() []corev1.Volume { - return nil -} - -// GetType returns the string "none" to indicate this is the None storage type. -func (a *ArtifactStorageNone) GetType() string { - return "none" -} - -// StorageBasePath returns an empty string because no storage is being used and so -// there is no path that resources should be copied from / to. -func (a *ArtifactStorageNone) StorageBasePath(pr *v1beta1.PipelineRun) string { - return "" -} - -// InitializeArtifactStorage will check if there is there is a -// bucket configured, create a PVC or return nil if no storage is required. -func InitializeArtifactStorage(ctx context.Context, images pipeline.Images, pr *v1beta1.PipelineRun, ps *v1beta1.PipelineSpec, c kubernetes.Interface) (ArtifactStorageInterface, error) { - // Artifact storage is needed under the following condition: - // Any Task in the pipeline contains an Output resource - // AND that Output resource is one of the AllowedOutputResource types. - - needStorage := false - // Build an index of resources used in the pipeline that are an AllowedOutputResource - possibleOutputs := sets.NewString() - for _, r := range ps.Resources { - if _, ok := v1beta1.AllowedOutputResources[r.Type]; ok { - possibleOutputs.Insert(r.Name) - } - } - - // Use that index to see if any of these are used as OutputResources. - for _, t := range ps.Tasks { - if t.Resources != nil { - for _, o := range t.Resources.Outputs { - if possibleOutputs.Has(o.Resource) { - needStorage = true - } - } - } - } - if !needStorage { - return &ArtifactStorageNone{}, nil - } - - if needsPVC(ctx) { - pvc, err := createPVC(ctx, pr, c) - if err != nil { - return nil, err - } - return &storage.ArtifactPVC{Name: pr.Name, PersistentVolumeClaim: pvc, ShellImage: images.ShellImage}, nil - } - - return newArtifactBucketFromConfig(ctx, images), nil -} - -// CleanupArtifactStorage will delete the PipelineRun's artifact storage PVC if it exists. The PVC is created for using -// an output workspace or artifacts from one Task to another Task. No other PVCs will be impacted by this cleanup. -func CleanupArtifactStorage(ctx context.Context, pr *v1beta1.PipelineRun, c kubernetes.Interface) error { - if needsPVC(ctx) { - err := deletePVC(ctx, pr, c) - if err != nil { - return err - } - } - return nil -} - -// needsPVC checks if the Tekton is configured to use a bucket for artifact storage, -// returning true if instead a PVC is needed. -func needsPVC(ctx context.Context) bool { - bucketConfig := config.FromContextOrDefaults(ctx).ArtifactBucket - if bucketConfig == nil { - return true - } - if strings.TrimSpace(bucketConfig.Location) == "" { - logging.FromContext(ctx).Warnf("the configmap key %q is empty", config.BucketLocationKey) - return true - } - return false -} - -// GetArtifactStorage returns the storage interface to enable -// consumer code to get a container step for copy to/from storage -func GetArtifactStorage(ctx context.Context, images pipeline.Images, prName string, c kubernetes.Interface) ArtifactStorageInterface { - if needsPVC(ctx) { - return &storage.ArtifactPVC{Name: prName, ShellImage: images.ShellImage} - } - return newArtifactBucketFromConfig(ctx, images) -} - -// newArtifactBucketFromConfig creates a Bucket from the supplied ConfigMap -func newArtifactBucketFromConfig(ctx context.Context, images pipeline.Images) *storage.ArtifactBucket { - c := &storage.ArtifactBucket{ - ShellImage: images.ShellImage, - GsutilImage: images.GsutilImage, - } - - bucketConfig := config.FromContextOrDefaults(ctx).ArtifactBucket - c.Location = bucketConfig.Location - sp := resourcev1alpha1.SecretParam{} - if bucketConfig.ServiceAccountSecretName != "" && bucketConfig.ServiceAccountSecretKey != "" { - sp.SecretName = bucketConfig.ServiceAccountSecretName - sp.SecretKey = bucketConfig.ServiceAccountSecretKey - sp.FieldName = bucketConfig.ServiceAccountFieldName - c.Secrets = append(c.Secrets, sp) - } - return c -} - -func createPVC(ctx context.Context, pr *v1beta1.PipelineRun, c kubernetes.Interface) (*corev1.PersistentVolumeClaim, error) { - if _, err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Get(ctx, GetPVCName(pr), metav1.GetOptions{}); err != nil { - if errors.IsNotFound(err) { - pvcConfig := config.FromContextOrDefaults(ctx).ArtifactPVC - pvcSize, err := resource.ParseQuantity(pvcConfig.Size) - if err != nil { - return nil, err - } - - // The storage class name on pod spec has three states. Tekton doesn't support the empty-string case. - // - nil if we don't care - // - "" if we explicitly want to have no class names - // - "$name" if we want a specific name - // https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class-1 - var pvcStorageClassName *string - if pvcConfig.StorageClassName == "" { - pvcStorageClassName = nil - } else { - pvcStorageClassName = &pvcConfig.StorageClassName - } - - pvcSpec := getPVCSpec(pr, pvcSize, pvcStorageClassName) - pvc, err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Create(ctx, pvcSpec, metav1.CreateOptions{}) - if err != nil { - return nil, fmt.Errorf("failed to claim Persistent Volume %q due to error: %w", pr.Name, err) - } - return pvc, nil - } - return nil, fmt.Errorf("failed to get claim Persistent Volume %q due to error: %w", pr.Name, err) - } - return nil, nil -} - -func deletePVC(ctx context.Context, pr *v1beta1.PipelineRun, c kubernetes.Interface) error { - if _, err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Get(ctx, GetPVCName(pr), metav1.GetOptions{}); err != nil { - if !errors.IsNotFound(err) { - return fmt.Errorf("failed to get Persistent Volume %q due to error: %w", GetPVCName(pr), err) - } - } else if err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Delete(ctx, GetPVCName(pr), metav1.DeleteOptions{}); err != nil { - return fmt.Errorf("failed to delete Persistent Volume %q due to error: %w", pr.Name, err) - } - return nil -} - -// getPVCSpec returns the PVC to create for a given PipelineRun -func getPVCSpec(pr *v1beta1.PipelineRun, pvcSize resource.Quantity, storageClassName *string) *corev1.PersistentVolumeClaim { - return &corev1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: pr.Namespace, - Name: GetPVCName(pr), - OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(pr)}, - }, - Spec: corev1.PersistentVolumeClaimSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, - Resources: corev1.ResourceRequirements{ - Requests: map[corev1.ResourceName]resource.Quantity{ - corev1.ResourceStorage: pvcSize, - }, - }, - StorageClassName: storageClassName, - }, - } -} - -// GetPVCName returns the name that should be used for the PVC for a PipelineRun -func GetPVCName(n named) string { - return fmt.Sprintf("%s-pvc", n.GetName()) -} - -type named interface { - GetName() string -} diff --git a/pkg/pipelinerunmetrics/metrics_test.go b/pkg/pipelinerunmetrics/metrics_test.go index 41e89f71714..0447e87aca3 100644 --- a/pkg/pipelinerunmetrics/metrics_test.go +++ b/pkg/pipelinerunmetrics/metrics_test.go @@ -78,7 +78,7 @@ func TestMetricsOnStore(t *testing.T) { } // We check that there's no change when incorrect config is passed - MetricsOnStore(logger)(config.GetMetricsConfigName(), &config.ArtifactBucket{}) + MetricsOnStore(logger)(config.GetMetricsConfigName(), &config.Store{}) // Comparing function assign to struct with the one which should yield same value if reflect.ValueOf(metrics.insertTag).Pointer() != reflect.ValueOf(pipelinerunInsertTag).Pointer() { t.Fatal("metrics recorder shouldn't change during this OnStore call") diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index 799d2abd37d..49c54699a83 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -33,7 +33,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" runv1beta1 "github.com/tektoncd/pipeline/pkg/apis/run/v1beta1" - "github.com/tektoncd/pipeline/pkg/artifacts" clientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" pipelinerunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/pipelinerun" alpha1listers "github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1alpha1" @@ -205,10 +204,6 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, pr *v1beta1.PipelineRun) if pr.IsDone() { pr.SetDefaults(ctx) - if err := artifacts.CleanupArtifactStorage(ctx, pr, c.KubeClientSet); err != nil { - logger.Errorf("Failed to delete PVC for PipelineRun %s: %v", pr.Name, err) - return c.finishReconcileUpdateEmitEvents(ctx, pr, before, err) - } if err := c.cleanupAffinityAssistants(ctx, pr); err != nil { logger.Errorf("Failed to delete StatefulSet for PipelineRun %s: %v", pr.Name, err) return c.finishReconcileUpdateEmitEvents(ctx, pr, before, err) @@ -647,12 +642,6 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get } } - as, err := artifacts.InitializeArtifactStorage(ctx, c.Images, pr, pipelineSpec, c.KubeClientSet) - if err != nil { - logger.Infof("PipelineRun failed to initialize artifact storage %s", pr.Name) - return controller.NewPermanentError(err) - } - if pr.Status.FinallyStartTime == nil { if pr.HaveTasksTimedOut(ctx, c.Clock) { tasksToTimeOut := sets.NewString() @@ -688,7 +677,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get } } } - if err := c.runNextSchedulableTask(ctx, pr, pipelineRunFacts, as); err != nil { + if err := c.runNextSchedulableTask(ctx, pr, pipelineRunFacts); err != nil { return err } @@ -734,7 +723,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get // runNextSchedulableTask gets the next schedulable Tasks from the dag based on the current // pipeline run state, and starts them // after all DAG tasks are done, it's responsible for scheduling final tasks and start executing them -func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.PipelineRun, pipelineRunFacts *resources.PipelineRunFacts, as artifacts.ArtifactStorageInterface) error { +func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.PipelineRun, pipelineRunFacts *resources.PipelineRunFacts) error { ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "runNextSchedulableTask") defer span.End() @@ -801,13 +790,13 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.Pip return fmt.Errorf("error creating Run called %s for PipelineTask %s from PipelineRun %s: %w", rpt.RunObjectName, rpt.PipelineTask.Name, pr.Name, err) } case rpt.IsMatrixed(): - rpt.TaskRuns, err = c.createTaskRuns(ctx, rpt, pr, as.StorageBasePath(pr)) + rpt.TaskRuns, err = c.createTaskRuns(ctx, rpt, pr) if err != nil { recorder.Eventf(pr, corev1.EventTypeWarning, "TaskRunsCreationFailed", "Failed to create TaskRuns %q: %v", rpt.TaskRunNames, err) return fmt.Errorf("error creating TaskRuns called %s for PipelineTask %s from PipelineRun %s: %w", rpt.TaskRunNames, rpt.PipelineTask.Name, pr.Name, err) } default: - rpt.TaskRun, err = c.createTaskRun(ctx, rpt.TaskRunName, nil, rpt, pr, as.StorageBasePath(pr)) + rpt.TaskRun, err = c.createTaskRun(ctx, rpt.TaskRunName, nil, rpt, pr) if err != nil { recorder.Eventf(pr, corev1.EventTypeWarning, "TaskRunCreationFailed", "Failed to create TaskRun %q: %v", rpt.TaskRunName, err) return fmt.Errorf("error creating TaskRun called %s for PipelineTask %s from PipelineRun %s: %w", rpt.TaskRunName, rpt.PipelineTask.Name, pr.Name, err) @@ -827,14 +816,14 @@ func (c *Reconciler) setFinallyStartedTimeIfNeeded(pr *v1beta1.PipelineRun, fact } } -func (c *Reconciler) createTaskRuns(ctx context.Context, rpt *resources.ResolvedPipelineTask, pr *v1beta1.PipelineRun, storageBasePath string) ([]*v1beta1.TaskRun, error) { +func (c *Reconciler) createTaskRuns(ctx context.Context, rpt *resources.ResolvedPipelineTask, pr *v1beta1.PipelineRun) ([]*v1beta1.TaskRun, error) { ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "createTaskRuns") defer span.End() var taskRuns []*v1beta1.TaskRun matrixCombinations := matrix.FanOut(rpt.PipelineTask.Matrix.Params).ToMap() for i, taskRunName := range rpt.TaskRunNames { params := matrixCombinations[strconv.Itoa(i)] - taskRun, err := c.createTaskRun(ctx, taskRunName, params, rpt, pr, storageBasePath) + taskRun, err := c.createTaskRun(ctx, taskRunName, params, rpt, pr) if err != nil { return nil, err } @@ -843,7 +832,7 @@ func (c *Reconciler) createTaskRuns(ctx context.Context, rpt *resources.Resolved return taskRuns, nil } -func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, params []v1beta1.Param, rpt *resources.ResolvedPipelineTask, pr *v1beta1.PipelineRun, storageBasePath string) (*v1beta1.TaskRun, error) { +func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, params []v1beta1.Param, rpt *resources.ResolvedPipelineTask, pr *v1beta1.PipelineRun) (*v1beta1.TaskRun, error) { ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "createTaskRun") defer span.End() logger := logging.FromContext(ctx) @@ -897,7 +886,7 @@ func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, para tr.Annotations[workspace.AnnotationAffinityAssistantName] = getAffinityAssistantName(pipelinePVCWorkspaceName, pr.Name) } - resources.WrapSteps(&tr.Spec, rpt.PipelineTask, rpt.ResolvedTaskResources.Inputs, rpt.ResolvedTaskResources.Outputs, storageBasePath) + resources.WrapSteps(&tr.Spec, rpt.PipelineTask, rpt.ResolvedTaskResources.Inputs, rpt.ResolvedTaskResources.Outputs) logger.Infof("Creating a new TaskRun object %s for pipeline task %s", taskRunName, rpt.PipelineTask.Name) return c.PipelineClientSet.TektonV1beta1().TaskRuns(pr.Namespace).Create(ctx, tr, metav1.CreateOptions{}) } diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 4fcd0979f83..0ac4e01cad2 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -35,7 +35,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" resolutionutil "github.com/tektoncd/pipeline/pkg/internal/resolution" "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/events/k8sevent" @@ -216,16 +215,6 @@ spec: value: somethingmorefun pipelineRef: name: test-pipeline - resources: - - name: git-repo - resourceRef: - name: some-repo - - name: best-image - resourceSpec: - params: - - name: url - value: gcr.io/sven - type: image serviceAccountName: test-sa `)} ps := []*v1beta1.Pipeline{parse.MustParseV1beta1Pipeline(t, ` @@ -242,37 +231,21 @@ spec: type: string - name: bar type: string - resources: - - name: git-repo - type: git - - name: best-image - type: image tasks: - - name: unit-test-3 + - name: unit-test-2 params: - name: foo value: somethingfun - name: bar value: $(params.bar) - - name: templatedparam - value: $(inputs.workspace.$(params.rev-param)) - name: contextRunParam value: $(context.pipelineRun.name) - name: contextPipelineParam value: $(context.pipeline.name) - name: contextRetriesParam value: $(context.pipelineTask.retries) - resources: - inputs: - - name: workspace - resource: git-repo - outputs: - - name: image-to-use - resource: best-image - - name: workspace - resource: git-repo runAfter: - - unit-test-2 + - unit-test-1 taskRef: name: unit-test-task - name: unit-test-1 @@ -281,56 +254,25 @@ spec: value: somethingfun - name: bar value: $(params.bar) - - name: templatedparam - value: $(inputs.workspace.$(params.rev-param)) - name: contextRunParam value: $(context.pipelineRun.name) - name: contextPipelineParam value: $(context.pipeline.name) - name: contextRetriesParam value: $(context.pipelineTask.retries) - resources: - inputs: - - name: workspace - resource: git-repo - outputs: - - name: image-to-use - resource: best-image - - name: workspace - resource: git-repo retries: 5 taskRef: name: unit-test-task - - name: unit-test-2 - resources: - inputs: - - from: - - unit-test-1 - name: workspace - resource: git-repo - taskRef: - name: unit-test-followup-task - name: unit-test-cluster-task params: - name: foo value: somethingfun - name: bar value: $(params.bar) - - name: templatedparam - value: $(inputs.workspace.$(params.rev-param)) - name: contextRunParam value: $(context.pipelineRun.name) - name: contextPipelineParam value: $(context.pipeline.name) - resources: - inputs: - - name: workspace - resource: git-repo - outputs: - - name: image-to-use - resource: best-image - - name: workspace - resource: git-repo taskRef: kind: ClusterTask name: unit-test-cluster-task @@ -346,35 +288,13 @@ spec: type: string - name: bar type: string - - name: templatedparam - type: string - name: contextRunParam type: string - name: contextPipelineParam type: string - name: contextRetriesParam type: string - resources: - inputs: - - name: workspace - type: git - outputs: - - name: image-to-use - type: image - - name: workspace - type: git -`), - parse.MustParseV1beta1Task(t, ` -metadata: - name: unit-test-followup-task - namespace: foo -spec: - resources: - inputs: - - name: workspace - type: git -`), - } +`)} clusterTasks := []*v1beta1.ClusterTask{ parse.MustParseClusterTask(t, ` metadata: @@ -385,55 +305,18 @@ spec: type: string - name: bar type: string - - name: templatedparam - type: string - name: contextRunParam type: string - name: contextPipelineParam type: string - resources: - inputs: - - name: workspace - type: git - outputs: - - name: image-to-use - type: image - - name: workspace - type: git -`), - parse.MustParseClusterTask(t, ` -metadata: - name: unit-test-followup-task -spec: - resources: - inputs: - - name: workspace - type: git -`), - } - rs := []*resourcev1alpha1.PipelineResource{parse.MustParsePipelineResource(t, ` -metadata: - name: some-repo - namespace: foo -spec: - params: - - name: url - value: https://github.com/kristoff/reindeer - type: git `)} - // When PipelineResources are created in the cluster, Kubernetes will add a SelfLink. We - // are using this to differentiate between Resources that we are referencing by Spec or by Ref - // after we have resolved them. - rs[0].SelfLink = "some/link" - d := test.Data{ - PipelineRuns: prs, - Pipelines: ps, - Tasks: ts, - ClusterTasks: clusterTasks, - PipelineResources: rs, - ConfigMaps: []*corev1.ConfigMap{newFeatureFlagsConfigMap()}, + PipelineRuns: prs, + Pipelines: ps, + Tasks: ts, + ClusterTasks: clusterTasks, + ConfigMaps: []*corev1.ConfigMap{newFeatureFlagsConfigMap()}, } prt := newPipelineRunTest(t, d) defer prt.Cancel() @@ -456,8 +339,6 @@ spec: value: somethingfun - name: bar value: somethingmorefun - - name: templatedparam - value: $(inputs.workspace.revision) - name: contextRunParam value: test-pipeline-run-success - name: contextPipelineParam @@ -465,27 +346,7 @@ spec: - name: contextRetriesParam value: "5" retries: 5 - resources: - inputs: - - name: workspace - resourceRef: - apiVersion: tekton.dev/v1alpha1 - name: some-repo - outputs: - - name: image-to-use - paths: - - /pvc/unit-test-1/image-to-use - resourceSpec: - params: - - name: url - value: gcr.io/sven - type: image - - name: workspace - paths: - - /pvc/unit-test-1/workspace - resourceRef: - apiVersion: tekton.dev/v1alpha1 - name: some-repo + resources: {} serviceAccountName: test-sa taskRef: name: unit-test-task @@ -508,9 +369,6 @@ spec: verifyTaskRunStatusesCount(t, reconciledRun.Status, 2) verifyTaskRunStatusesNames(t, reconciledRun.Status, tr1Name, tr2Name) - - // A PVC should have been created to deal with output -> input linking - ensurePVCCreated(prt.TestAssets.Ctx, t, clients, expectedTaskRun.GetPipelineRunPVCName(), "foo") } // TestReconcile_CustomTask runs "Reconcile" on a PipelineRun with one Custom @@ -983,16 +841,6 @@ spec: key1: {} key2: {} `, v1beta1.ParamTypeObject)), - parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: a-task-that-needs-a-resource - namespace: foo -spec: - resources: - inputs: - - name: workspace - type: %s -`, resourcev1alpha1.PipelineResourceTypeGit)), } ps := []*v1beta1.Pipeline{parse.MustParseV1beta1Pipeline(t, ` @@ -1015,23 +863,6 @@ spec: taskRef: name: a-task-that-needs-params `), - parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` -metadata: - name: a-fine-pipeline - namespace: foo -spec: - tasks: - - name: some-task - taskRef: - name: a-task-that-exists - resources: - inputs: - - name: needed-resource - resource: a-resource - resources: - - name: a-resource - type: %s -`, resourcev1alpha1.PipelineResourceTypeGit)), parse.MustParseV1beta1Pipeline(t, ` metadata: name: a-pipeline-that-should-be-caught-by-admission-control @@ -1041,10 +872,6 @@ spec: - name: some-task taskRef: name: a-task-that-exists - resources: - inputs: - - name: needed-resource - resource: a-resource `), parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` metadata: @@ -1133,58 +960,6 @@ spec: "Normal Started", "Warning Failed invalid input params for task a-task-that-needs-params: missing values", }, - }, { - name: "invalid-pipeline-run-resources-not-bound-shd-stop-reconciling", - pipelineRun: parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: pipeline-resources-not-bound - namespace: foo -spec: - pipelineRef: - name: a-fine-pipeline -`), - reason: ReasonInvalidBindings, - permanentError: true, - wantEvents: []string{ - "Normal Started", - "Warning Failed PipelineRun foo/pipeline-resources-not-bound doesn't bind Pipeline", - }, - }, { - name: "invalid-pipeline-run-missing-resource-shd-stop-reconciling", - pipelineRun: parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: pipeline-resources-dont-exist - namespace: foo -spec: - pipelineRef: - name: a-fine-pipeline - resources: - - name: a-resource - resourceRef: - name: missing-resource -`), - reason: ReasonCouldntGetResource, - permanentError: true, - wantEvents: []string{ - "Normal Started", - "Warning Failed PipelineRun foo/pipeline-resources-dont-exist can't be Run; it tries to bind Resources", - }, - }, { - name: "invalid-pipeline-missing-declared-resource-shd-stop-reconciling", - pipelineRun: parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: pipeline-resources-not-declared - namespace: foo -spec: - pipelineRef: - name: a-pipeline-that-should-be-caught-by-admission-control -`), - reason: ReasonFailedValidation, - permanentError: true, - wantEvents: []string{ - "Normal Started", - "Warning Failed Pipeline foo/a-pipeline-that-should-be-caught-by-admission-control can't be Run; it has an invalid spec", - }, }, { name: "invalid-pipeline-mismatching-parameter-types", pipelineRun: parse.MustParseV1beta1PipelineRun(t, ` @@ -1224,28 +999,6 @@ spec: "Normal Started", "Warning Failed PipelineRun foo/pipeline-missing-object-param-keys parameters is missing object keys required by Pipeline foo/a-pipeline-with-object-params's parameters: PipelineRun missing object keys for parameters", }, - }, { - name: "invalid-embedded-pipeline-resources-bot-bound-shd-stop-reconciling", - pipelineRun: parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: embedded-pipeline-resources-not-bound - namespace: foo -spec: - pipelineSpec: - tasks: - - name: some-task - taskRef: - name: a-task-that-needs-a-resource - resources: - - name: workspace - type: %s -`, resourcev1alpha1.PipelineResourceTypeGit)), - reason: ReasonInvalidBindings, - permanentError: true, - wantEvents: []string{ - "Normal Started", - "Warning Failed PipelineRun foo/embedded-pipeline-resources-not-bound doesn't bind Pipeline", - }, }, { name: "invalid-embedded-pipeline-bad-name-shd-stop-reconciling", pipelineRun: parse.MustParseV1beta1PipelineRun(t, ` diff --git a/pkg/reconciler/pipelinerun/resources/input_output_steps.go b/pkg/reconciler/pipelinerun/resources/input_output_steps.go index 7405e1983ab..4acb3d31fe1 100644 --- a/pkg/reconciler/pipelinerun/resources/input_output_steps.go +++ b/pkg/reconciler/pipelinerun/resources/input_output_steps.go @@ -24,7 +24,7 @@ import ( ) // GetOutputSteps will add the correct `path` to the output resources for pt -func GetOutputSteps(outputs map[string]*resourcev1alpha1.PipelineResource, taskName, storageBasePath string) []v1beta1.TaskResourceBinding { +func GetOutputSteps(outputs map[string]*resourcev1alpha1.PipelineResource, taskName string) []v1beta1.TaskResourceBinding { var taskOutputResources []v1beta1.TaskResourceBinding for name, outputResource := range outputs { @@ -32,7 +32,7 @@ func GetOutputSteps(outputs map[string]*resourcev1alpha1.PipelineResource, taskN PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: name, }, - Paths: []string{filepath.Join(storageBasePath, taskName, name)}, + Paths: []string{filepath.Join(taskName, name)}, } // SelfLink is being checked there to determine if this PipelineResource is an instance that // exists in the cluster (in which case Kubernetes will populate this field) or is specified by Spec @@ -55,7 +55,7 @@ func GetOutputSteps(outputs map[string]*resourcev1alpha1.PipelineResource, taskN // GetInputSteps will add the correct `path` to the input resources for pt. If the resources are provided by // a previous task, the correct `path` will be used so that the resource provided by that task will be used. -func GetInputSteps(inputs map[string]*resourcev1alpha1.PipelineResource, inputResources []v1beta1.PipelineTaskInputResource, storageBasePath string) []v1beta1.TaskResourceBinding { +func GetInputSteps(inputs map[string]*resourcev1alpha1.PipelineResource, inputResources []v1beta1.PipelineTaskInputResource) []v1beta1.TaskResourceBinding { var taskInputResources []v1beta1.TaskResourceBinding for name, inputResource := range inputs { @@ -79,26 +79,13 @@ func GetInputSteps(inputs map[string]*resourcev1alpha1.PipelineResource, inputRe } } - // Determine if the value is meant to come `from` a previous Task - if so, add the path to the pvc - // that contains the data as the `path` the resulting TaskRun should get the data from. - var stepSourceNames []string - for _, pipelineTaskInput := range inputResources { - if pipelineTaskInput.Name == name { - for _, constr := range pipelineTaskInput.From { - stepSourceNames = append(stepSourceNames, filepath.Join(storageBasePath, constr, name)) - } - } - } - if len(stepSourceNames) > 0 { - taskInputResource.Paths = append(taskInputResource.Paths, stepSourceNames...) - } taskInputResources = append(taskInputResources, taskInputResource) } return taskInputResources } // WrapSteps will add the correct `paths` to all of the inputs and outputs for pt -func WrapSteps(tr *v1beta1.TaskRunSpec, pt *v1beta1.PipelineTask, inputs, outputs map[string]*resourcev1alpha1.PipelineResource, storageBasePath string) { +func WrapSteps(tr *v1beta1.TaskRunSpec, pt *v1beta1.PipelineTask, inputs, outputs map[string]*resourcev1alpha1.PipelineResource) { if pt == nil { return } @@ -107,9 +94,9 @@ func WrapSteps(tr *v1beta1.TaskRunSpec, pt *v1beta1.PipelineTask, inputs, output } if pt.Resources != nil { // Add presteps to setup updated input - tr.Resources.Inputs = append(tr.Resources.Inputs, GetInputSteps(inputs, pt.Resources.Inputs, storageBasePath)...) + tr.Resources.Inputs = append(tr.Resources.Inputs, GetInputSteps(inputs, pt.Resources.Inputs)...) } // Add poststeps to setup outputs - tr.Resources.Outputs = append(tr.Resources.Outputs, GetOutputSteps(outputs, pt.Name, storageBasePath)...) + tr.Resources.Outputs = append(tr.Resources.Outputs, GetOutputSteps(outputs, pt.Name)...) } diff --git a/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go b/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go index 12c8787e0ea..4710db68cdc 100644 --- a/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go +++ b/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go @@ -27,8 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -var pvcDir = "/pvc" - func TestGetOutputSteps(t *testing.T) { r1 := &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ @@ -42,16 +40,6 @@ func TestGetOutputSteps(t *testing.T) { SelfLink: "/apis/tekton.dev/pipelineresources/resource2", }, } - r3 := &resourcev1alpha1.PipelineResource{ - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "url", - Value: "https://github.com/tektoncd/pipeline.git", - }}, - SecretParams: nil, - }, - } tcs := []struct { name string outputs map[string]*resourcev1alpha1.PipelineResource @@ -65,7 +53,7 @@ func TestGetOutputSteps(t *testing.T) { Name: "test-output", ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, }, - Paths: []string{"/pvc/test-taskname/test-output"}, + Paths: []string{"test-taskname/test-output"}, }}, pipelineTaskName: "test-taskname", }, { @@ -79,50 +67,19 @@ func TestGetOutputSteps(t *testing.T) { Name: "test-output", ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, }, - Paths: []string{"/pvc/test-multiple-outputs/test-output"}, + Paths: []string{"test-multiple-outputs/test-output"}, }, { PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: "test-output-2", ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource2"}, }, - Paths: []string{"/pvc/test-multiple-outputs/test-output-2"}, + Paths: []string{"test-multiple-outputs/test-output-2"}, }}, pipelineTaskName: "test-multiple-outputs", - }, { - name: "single output with resource spec", - outputs: map[string]*resourcev1alpha1.PipelineResource{"test-output": r3}, - expectedtaskOuputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "test-output", - ResourceSpec: &r3.Spec, - }, - Paths: []string{"/pvc/test-taskname/test-output"}, - }}, - pipelineTaskName: "test-taskname", - }, { - name: "multiple-outputs-with-resource-spec", - outputs: map[string]*resourcev1alpha1.PipelineResource{ - "test-output-1": r3, - "test-output-2": r3, - }, - expectedtaskOuputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "test-output-1", - ResourceSpec: &r3.Spec, - }, - Paths: []string{"/pvc/test-multiple-outputs-with-resource-spec/test-output-1"}, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "test-output-2", - ResourceSpec: &r3.Spec, - }, - Paths: []string{"/pvc/test-multiple-outputs-with-resource-spec/test-output-2"}, - }}, - pipelineTaskName: "test-multiple-outputs-with-resource-spec", }} for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - postTasks := resources.GetOutputSteps(tc.outputs, tc.pipelineTaskName, pvcDir) + postTasks := resources.GetOutputSteps(tc.outputs, tc.pipelineTaskName) if d := cmp.Diff(tc.expectedtaskOuputResources, postTasks, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { t.Errorf("error comparing post steps %s", diff.PrintWantGot(d)) } @@ -137,16 +94,6 @@ func TestGetInputSteps(t *testing.T) { SelfLink: "/apis/tekton.dev/pipelineresources/resource1", }, } - r2 := &resourcev1alpha1.PipelineResource{ - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "url", - Value: "https://github.com/tektoncd/pipeline.git", - }}, - SecretParams: nil, - }, - } tcs := []struct { name string inputs map[string]*resourcev1alpha1.PipelineResource @@ -169,7 +116,6 @@ func TestGetInputSteps(t *testing.T) { ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, Name: "test-input", }, - Paths: []string{"/pvc/prev-task-1/test-input"}, }}, }, { name: "task-with-no-input-constraint", @@ -204,66 +150,12 @@ func TestGetInputSteps(t *testing.T) { ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, Name: "test-input", }, - Paths: []string{"/pvc/prev-task-1/test-input", "/pvc/prev-task-2/test-input"}, - }}, - }, { - name: "task-with-a-constraint-with-resource-spec", - inputs: map[string]*resourcev1alpha1.PipelineResource{"test-input": r2}, - pipelineTask: &v1beta1.PipelineTask{ - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "test-input", - From: []string{"prev-task-1"}, - }}, - }, - }, - expectedtaskInputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &r2.Spec, - Name: "test-input", - }, - Paths: []string{"/pvc/prev-task-1/test-input"}, - }}, - }, { - name: "task-with-no-input-constraint-but-with-resource-spec", - inputs: map[string]*resourcev1alpha1.PipelineResource{"test-input": r2}, - expectedtaskInputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &r2.Spec, - Name: "test-input", - }, - }}, - pipelineTask: &v1beta1.PipelineTask{ - Name: "sample-test-task", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "test-input", - }}, - }, - }, - }, { - name: "task-with-multiple-constraints-with-resource-spec", - inputs: map[string]*resourcev1alpha1.PipelineResource{"test-input": r2}, - pipelineTask: &v1beta1.PipelineTask{ - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "test-input", - From: []string{"prev-task-1", "prev-task-2"}, - }}, - }, - }, - expectedtaskInputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &r2.Spec, - Name: "test-input", - }, - Paths: []string{"/pvc/prev-task-1/test-input", "/pvc/prev-task-2/test-input"}, }}, }, } for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - taskInputResources := resources.GetInputSteps(tc.inputs, tc.pipelineTask.Resources.Inputs, pvcDir) + taskInputResources := resources.GetInputSteps(tc.inputs, tc.pipelineTask.Resources.Inputs) if d := cmp.Diff(tc.expectedtaskInputResources, taskInputResources, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { t.Errorf("error comparing task resource inputs %s", diff.PrintWantGot(d)) } @@ -278,24 +170,12 @@ func TestWrapSteps(t *testing.T) { SelfLink: "/apis/tekton.dev/pipelineresources/resource1", }, } - r2 := &resourcev1alpha1.PipelineResource{ - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "url", - Value: "https://github.com/tektoncd/pipeline.git", - }}, - SecretParams: nil, - }, - } inputs := map[string]*resourcev1alpha1.PipelineResource{ "test-input": r1, "test-input-2": r1, - "test-input-3": r2, } outputs := map[string]*resourcev1alpha1.PipelineResource{ - "test-output": r1, - "test-output-2": r2, + "test-output": r1, } pt := &v1beta1.PipelineTask{ @@ -309,37 +189,25 @@ func TestWrapSteps(t *testing.T) { } taskRunSpec := &v1beta1.TaskRunSpec{} - resources.WrapSteps(taskRunSpec, pt, inputs, outputs, pvcDir) + resources.WrapSteps(taskRunSpec, pt, inputs, outputs) expectedtaskInputResources := []v1beta1.TaskResourceBinding{{ PipelineResourceBinding: v1beta1.PipelineResourceBinding{ ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, Name: "test-input", }, - Paths: []string{"/pvc/prev-task/test-input"}, }, { PipelineResourceBinding: v1beta1.PipelineResourceBinding{ ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, Name: "test-input-2", }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &r2.Spec, - Name: "test-input-3", - }, }} expectedtaskOuputResources := []v1beta1.TaskResourceBinding{{ PipelineResourceBinding: v1beta1.PipelineResourceBinding{ ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, Name: "test-output", }, - Paths: []string{"/pvc/test-task/test-output"}, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &r2.Spec, - Name: "test-output-2", - }, - Paths: []string{"/pvc/test-task/test-output-2"}, + Paths: []string{"test-task/test-output"}, }} if d := cmp.Diff(taskRunSpec.Resources.Inputs, expectedtaskInputResources, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index d816283fc37..5e14b433ab9 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -241,11 +241,6 @@ var v1alpha1Runs = []v1alpha1.Run{{ Spec: v1alpha1.RunSpec{}, }} -var gitDeclaredResource = v1beta1.PipelineDeclaredResource{ - Name: "git-resource", - Type: resourcev1alpha1.PipelineResourceTypeGit, -} - var gitSweetResourceBinding = v1beta1.PipelineResourceBinding{ Name: "git-resource", ResourceRef: &v1beta1.PipelineResourceRef{Name: "sweet-resource"}, @@ -1969,7 +1964,7 @@ func TestResolvePipelineRun(t *testing.T) { p := &v1beta1.Pipeline{ ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{gitDeclaredResource}, + Resources: []v1beta1.PipelineDeclaredResource{}, Tasks: []v1beta1.PipelineTask{ { Name: "mytask1", @@ -2018,7 +2013,7 @@ func TestResolvePipelineRun(t *testing.T) { Name: "someresource", }, Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, }, } providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} @@ -2356,7 +2351,7 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { p := &v1beta1.Pipeline{ ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{gitDeclaredResource}, + Resources: []v1beta1.PipelineDeclaredResource{}, Tasks: []v1beta1.PipelineTask{{ Name: "mytask-with-a-really-long-name-to-trigger-truncation", TaskRef: &v1beta1.TaskRef{ @@ -2377,7 +2372,7 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { Name: "someresource", }, Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, }, } providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} @@ -2456,7 +2451,7 @@ func TestResolvedPipelineRun_PipelineTaskHasOptionalResources(t *testing.T) { Name: "someresource", }, Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, }, } providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} @@ -2496,32 +2491,11 @@ func TestResolvedPipelineRun_PipelineTaskHasOptionalResources(t *testing.T) { } } -func TestValidateResourceBindings(t *testing.T) { - p := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{gitDeclaredResource}, - }, - } - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{Name: "pipeline"}, - Resources: []v1beta1.PipelineResourceBinding{gitSweetResourceBinding}, - }, - } - err := ValidateResourceBindings(&p.Spec, pr) - if err != nil { - t.Fatalf("didn't expect error getting resources from bindings but got: %v", err) - } -} - func TestValidateResourceBindings_Missing(t *testing.T) { p := &v1beta1.Pipeline{ ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, Spec: v1beta1.PipelineSpec{ Resources: []v1beta1.PipelineDeclaredResource{ - gitDeclaredResource, { Name: "image-resource", Type: resourcev1alpha1.PipelineResourceTypeImage, @@ -2546,7 +2520,7 @@ func TestGetResourcesFromBindings_Extra(t *testing.T) { p := &v1beta1.Pipeline{ ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{gitDeclaredResource}, + Resources: []v1beta1.PipelineDeclaredResource{}, }, } pr := &v1beta1.PipelineRun{ diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go index c02a79b3c0b..45000f460bb 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go @@ -2584,7 +2584,7 @@ spec: inputs: - name: workspace type: %s -`, resourcev1alpha1.PipelineResourceTypeGit)) +`, resourcev1alpha1.PipelineResourceTypeImage)) taskrun := parse.MustParseV1beta1TaskRun(t, ` metadata: diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index 8ae622dde9d..3bbde91a5d5 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -516,21 +516,6 @@ var ( }, } - gcsTaskSpec = &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "foobar", - Image: "someImage", - Args: []string{"$(outputs.resources.bucket.path)"}, - }}, - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "bucket", - }, - }}, - }, - } - arrayParamTaskSpec = &v1beta1.TaskSpec{ Steps: []v1beta1.Step{{ Name: "simple-image", @@ -708,28 +693,10 @@ var ( }, } - inputs = map[string]v1beta1.PipelineResourceInterface{ - "workspace": gitResource, - } - outputs = map[string]v1beta1.PipelineResourceInterface{ "imageToUse": imageResource, - "bucket": gcsResource, } - gitResource, _ = resource.FromType("git-resource", &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "https://git-repo", - }}, - }, - }, images) - imageResource, _ = resource.FromType("image-resource", &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: "image-resource", @@ -742,22 +709,6 @@ var ( }}, }, }, images) - - gcsResource, _ = resource.FromType("gcs-resource", &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gcs-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "type", - Value: "gcs", - }, { - Name: "location", - Value: "theCloud?", - }}, - }, - }, images) ) func applyMutation(ts *v1beta1.TaskSpec, f func(*v1beta1.TaskSpec)) *v1beta1.TaskSpec { @@ -1103,19 +1054,6 @@ func TestApplyResources(t *testing.T) { spec.Steps[8].Image = "/foo/builtImage" spec.Steps[9].Image = "/workspace/foo/builtImage" }), - }, { - name: "input resource specified", - ts: simpleTaskSpec, - r: inputs, - rStr: "inputs", - want: applyMutation(simpleTaskSpec, func(spec *v1beta1.TaskSpec) { - spec.Steps[1].WorkingDir = "/workspace/workspace" - spec.Steps[1].Args = []string{"https://git-repo"} - spec.Steps[4].WorkingDir = "/workspace/workspace" - spec.Steps[4].Args = []string{"https://git-repo"} - spec.Steps[8].Image = "/foo/builtImage" - spec.Steps[9].Image = "/workspace/foo/builtImage" - }), }, { name: "output resource specified", ts: simpleTaskSpec, @@ -1129,14 +1067,6 @@ func TestApplyResources(t *testing.T) { spec.Steps[8].Image = "/foo/builtImage" spec.Steps[9].Image = "/workspace/foo/builtImage" }), - }, { - name: "output resource specified with path replacement", - ts: gcsTaskSpec, - r: outputs, - rStr: "outputs", - want: applyMutation(gcsTaskSpec, func(spec *v1beta1.TaskSpec) { - spec.Steps[0].Args = []string{"/workspace/output/bucket"} - }), }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/reconciler/taskrun/resources/input_resource_test.go b/pkg/reconciler/taskrun/resources/input_resource_test.go deleted file mode 100644 index 793a4273a19..00000000000 --- a/pkg/reconciler/taskrun/resources/input_resource_test.go +++ /dev/null @@ -1,1364 +0,0 @@ -/* -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 resources - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/test/diff" - "github.com/tektoncd/pipeline/test/names" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - fakek8s "k8s.io/client-go/kubernetes/fake" - "knative.dev/pkg/ptr" -) - -var ( - images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", - } - inputResourceInterfaces map[string]v1beta1.PipelineResourceInterface - - gitInputs = []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "gitspace", - Type: "git", - }}} - multipleGitInputs = []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "gitspace", - Type: "git", - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "git-duplicate-space", - Type: "git", - }}, - } - gcsInputs = []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace", - Type: "gcs", - TargetPath: "gcs-dir", - }}} - multipleGcsInputs = []v1beta1.TaskResource{ - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace", - Type: "gcs", - TargetPath: "gcs-dir", - }, - }, - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace2", - Type: "gcs", - TargetPath: "gcs-dir", - }, - }, - } - optionalGitInputs = []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "gitspace", - Type: "git", - Optional: false, - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "git-optional-space", - Type: "git", - Optional: true, - }}, - } - gitResourceSecurityContext = &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - } -) - -func setUp() { - rs := []*resourcev1alpha1.PipelineResource{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "the-git", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Url", - Value: "https://github.com/grafeas/kritis", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "the-git-with-branch", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Url", - Value: "https://github.com/grafeas/kritis", - }, { - Name: "Revision", - Value: "branch", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "the-git-with-sslVerify-false", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Url", - Value: "https://github.com/grafeas/kritis", - }, { - Name: "Revision", - Value: "branch", - }, { - Name: "SSLVerify", - Value: "false", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster2", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "cluster", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Name", - Value: "cluster2", - }, { - Name: "Url", - Value: "http://10.10.10.10", - }}, - SecretParams: []resourcev1alpha1.SecretParam{{ - FieldName: "cadata", - SecretKey: "cadatakey", - SecretName: "secret1", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster3", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "cluster", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "name", - Value: "cluster3", - }, { - Name: "Url", - Value: "http://10.10.10.10", - }, { - Name: "Namespace", - Value: "namespace1", - }, { - Name: "CAdata", - // echo "my-ca-cert" | base64 - Value: "bXktY2EtY2VydAo=", - }, { - Name: "clientKeyData", - // echo "my-ca-cert" | base64 - Value: "Y2xpZW50LWtleS1kYXRh", - }, { - Name: "clientCertificateData", - // echo "my-ca-cert" | base64 - Value: "Y2xpZW50LWNlcnRpZmljYXRlLWRhdGE=", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "storage1", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://fake-bucket/rules.zip", - }, { - Name: "Type", - Value: "gcs", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "storage2", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://fake-bucket/other.zip", - }, { - Name: "Type", - Value: "gcs", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "storage-gcs-keys", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://fake-bucket/rules.zip", - }, { - Name: "Type", - Value: "gcs", - }, { - Name: "Dir", - Value: "true", - }}, - SecretParams: []resourcev1alpha1.SecretParam{{ - SecretKey: "key.json", - SecretName: "secret-name", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - }, { - SecretKey: "token", - SecretName: "secret-name2", - FieldName: "GOOGLE_TOKEN", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "storage-gcs-invalid", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://fake-bucket/rules", - }, { - Name: "Type", - Value: "non-existent", - }}, - }, - }} - inputResourceInterfaces = make(map[string]v1beta1.PipelineResourceInterface) - for _, r := range rs { - ri, _ := resource.FromType(r.Name, r, images) - inputResourceInterfaces[r.Name] = ri - } -} - -func TestAddInputResourceToTask(t *testing.T) { - task := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - } - taskWithMultipleGitSources := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: multipleGitInputs, - }, - }, - } - taskWithTargetPath := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task-with-targetpath", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: gcsInputs, - }, - }, - } - taskWithOptionalGitSources := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-with-optional-source", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: optionalGitInputs, - }, - }, - } - - taskRun := &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git", - }, - Name: "gitspace", - }, - }}, - }, - }, - } - - for _, c := range []struct { - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - wantErr bool - want *v1beta1.TaskSpec - }{{ - desc: "simple with default revision", - task: task, - taskRun: taskRun, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - }, { - desc: "simple with branch", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-with-branch-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace", "-revision", "branch"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git-with-branch"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - }, { - desc: "reuse git input resource and verify order", - task: taskWithMultipleGitSources, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "git-duplicate-space", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-with-branch-mz4c7", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace", "-revision", "branch"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git-with-branch"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }, { - Name: "git-source-the-git-with-branch-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/git-duplicate-space", "-revision", "branch"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git-with-branch"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: multipleGitInputs, - }, - }, - }, { - desc: "set revision to default value 1", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git", - }, - Name: "gitspace", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - }, { - desc: "set revision to provided branch", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-with-branch-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace", "-revision", "branch"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git-with-branch"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - }, { - desc: "git resource as input from previous task", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-git", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git", - }, - Name: "gitspace", - }, - Paths: []string{"prev-task-path"}, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "create-dir-gitspace-mz4c7", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gitspace"}, - }, { - Name: "source-copy-gitspace-9l9zj", - Image: "busybox", - Command: []string{"cp", "-r", "prev-task-path/.", "/workspace/gitspace"}, - VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}}, - Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "gitspace"}}, - }}, - Volumes: []corev1.Volume{{ - Name: "pipelinerun-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ClaimName: "pipelinerun-pvc"}, - }, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - }, { - desc: "simple with sslVerify false", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-sslVerify-false", - }, - Name: "gitspace", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-with-sslVerify-false-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace", "-revision", "branch", "-sslVerify=false"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git-with-sslVerify-false"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - }, { - desc: "storage resource as input with target path", - task: taskWithTargetPath, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-gcs", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage1", - }, - Name: "workspace", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "create-dir-storage1-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-dir"}, - }, { - Script: `#!/usr/bin/env bash -if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then - echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account... - gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} -fi -gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-dir -`, - Name: "fetch-storage1-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: pipeline.HomeDir, - }}, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gcsInputs, - }, - }, - }, { - desc: "storage resource as input from previous task", - task: taskWithTargetPath, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-gcs", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage1", - }, - Name: "workspace", - }, - Paths: []string{"prev-task-path"}, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "create-dir-workspace-mz4c7", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-dir"}, - }, { - Name: "source-copy-workspace-9l9zj", - Image: "busybox", - Command: []string{"cp", "-r", "prev-task-path/.", "/workspace/gcs-dir"}, - VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}}, - Env: []corev1.EnvVar{{ - Name: "TEKTON_RESOURCE_NAME", - Value: "workspace", - }}, - }}, - Volumes: []corev1.Volume{{ - Name: "pipelinerun-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ClaimName: "pipelinerun-pvc"}, - }, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gcsInputs, - }, - }, - }, { - desc: "invalid gcs resource type name", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-invalid-gcs", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage-gcs-invalid", - }, - Name: "workspace", - }, - }}, - }, - }, - }, - wantErr: true, - }, { - desc: "invalid gcs resource type name", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-invalid-gcs", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage-gcs-invalid", - }, - Name: "workspace", - }, - }}, - }, - }, - }, - wantErr: true, - }, { - desc: "invalid resource name", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace-invalid", - Type: "git", - }}}, - }, - }, - }, - taskRun: taskRun, - wantErr: true, - }, { - desc: "optional git input resource", - task: taskWithOptionalGitSources, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo-with-optional-git", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "simpleTask", - }, - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "git-source-the-git-with-branch-9l9zj", - Image: "override-with-git:latest", - Command: []string{"/ko-app/git-init"}, - Args: []string{"-url", "https://github.com/grafeas/kritis", "-path", "/workspace/gitspace", "-revision", "branch"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "the-git-with-branch"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - SecurityContext: gitResourceSecurityContext, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: optionalGitInputs, - }, - }, - }} { - t.Run(c.desc, func(t *testing.T) { - setUp() - names.TestingSeed() - fakekubeclient := fakek8s.NewSimpleClientset() - got, err := AddInputResource(context.Background(), fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, mockResolveTaskResources(c.taskRun)) - if (err != nil) != c.wantErr { - t.Errorf("Test: %q; AddInputResource() error = %v, WantErr %v", c.desc, err, c.wantErr) - } - if got != nil { - if d := cmp.Diff(got, c.want); d != "" { - t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) - } - } - }) - } -} - -func TestStorageInputResource(t *testing.T) { - gcsStorageInputs := []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "gcs-input-resource", - Type: "storage", - }}, - } - optionalStorageInputs := []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "gcs-input-resource", - Type: "storage", - Optional: true, - }}, - } - - for _, c := range []struct { - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - wantErr bool - want *v1beta1.TaskSpec - }{{ - desc: "inputs with no resource spec and resource ref", - task: &v1beta1.Task{ - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "gcs-input-resource", - Type: "storage", - }}}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "gcs-input-resource", - }, - }}, - }, - }, - }, - wantErr: true, - }, { - desc: "inputs with resource spec and no resource ref", - task: &v1beta1.Task{ - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: gcsStorageInputs, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "gcs-input-resource", - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeStorage, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://fake-bucket/rules.zip", - }, { - Name: "Type", - Value: "gcs", - }}, - }, - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "create-dir-gcs-input-resource-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-input-resource"}, - }, { - Script: `#!/usr/bin/env bash -if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then - echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account... - gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} -fi -gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-input-resource -`, - Name: "fetch-gcs-input-resource-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Env: []corev1.EnvVar{{Name: "HOME", Value: pipeline.HomeDir}}, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gcsStorageInputs, - }, - }, - }, { - desc: "no inputs", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage", - Namespace: "marshmallow", - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage-run", - Namespace: "marshmallow", - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{}, - }, { - desc: "storage resource as input", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: gcsStorageInputs, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage-run", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "gcs-input-resource", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage-gcs-keys", - }, - }, - }}, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "create-dir-storage-gcs-keys-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-input-resource"}, - }, { - Script: `#!/usr/bin/env bash -if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then - echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account... - gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} -fi -gsutil rsync -d -r gs://fake-bucket/rules.zip /workspace/gcs-input-resource -`, - Name: "fetch-storage-gcs-keys-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: []corev1.VolumeMount{ - {Name: "volume-storage-gcs-keys-secret-name", MountPath: "/var/secret/secret-name"}, - }, - Env: []corev1.EnvVar{ - {Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/secret/secret-name/key.json"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gcsStorageInputs, - }, - Volumes: []corev1.Volume{{ - Name: "volume-storage-gcs-keys-secret-name", - VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "secret-name"}}, - }, { - Name: "volume-storage-gcs-keys-secret-name2", - VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "secret-name2"}}, - }}, - }, - }, { - desc: "optional inputs with no resource spec and no resource ref", - task: &v1beta1.Task{ - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: optionalStorageInputs, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-storage-run-with-optional-inputs", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Params: nil, - Resources: &v1beta1.TaskRunResources{ - Inputs: nil, - }, - }, - }, - wantErr: false, - want: &v1beta1.TaskSpec{ - Steps: nil, - Resources: &v1beta1.TaskResources{ - Inputs: optionalStorageInputs, - }, - }, - }} { - t.Run(c.desc, func(t *testing.T) { - names.TestingSeed() - setUp() - fakekubeclient := fakek8s.NewSimpleClientset() - got, err := AddInputResource(context.Background(), fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, mockResolveTaskResources(c.taskRun)) - if (err != nil) != c.wantErr { - t.Errorf("Test: %q; AddInputResource() error = %v, WantErr %v", c.desc, err, c.wantErr) - } - if d := cmp.Diff(c.want, got); d != "" { - t.Errorf("Didn't get expected Task spec %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestAddStepsToTaskWithBucketFromConfigMap(t *testing.T) { - task := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "build-from-repo", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - }, - } - taskWithTargetPath := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task-with-targetpath", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: gcsInputs, - }, - }, - } - taskWithMultipleGcsInputs := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task-with-multiple-gcs-inputs", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: multipleGcsInputs, - }, - }, - } - - gcsVolumes := []corev1.Volume{ - { - Name: "volume-bucket-gcs-config", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "gcs-config", - }, - }, - }, - } - gcsVolumeMounts := []corev1.VolumeMount{{Name: "volume-bucket-gcs-config", MountPath: "/var/bucketsecret/gcs-config"}} - gcsEnv := []corev1.EnvVar{ - { - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/bucketsecret/gcs-config/my-key", - }, - } - - for _, c := range []struct { - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - want *v1beta1.TaskSpec - }{{ - desc: "git resource as input from previous task - copy to bucket", - task: task, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-git", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git", - }, - Name: "gitspace", - }, - Paths: []string{"prev-task-path"}, - }}, - }, - }, - }, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "artifact-dest-mkdir-gitspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gitspace"}, - }, { - Name: "artifact-copy-from-gitspace-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "gs://fake-bucket/prev-task-path/*", "/workspace/gitspace"}, - Env: gcsEnv, - VolumeMounts: gcsVolumeMounts, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gitInputs, - }, - Volumes: gcsVolumes, - }, - }, { - desc: "storage resource as input from previous task - copy from bucket", - task: taskWithTargetPath, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-gcs", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage1", - }, - Name: "workspace", - }, - Paths: []string{"prev-task-path"}, - }}, - }, - }, - }, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "artifact-dest-mkdir-workspace-mssqb", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-dir"}, - }, { - Name: "artifact-copy-from-workspace-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "gs://fake-bucket/prev-task-path/*", "/workspace/gcs-dir"}, - Env: gcsEnv, - VolumeMounts: gcsVolumeMounts, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: gcsInputs, - }, - Volumes: gcsVolumes, - }, - }, { - desc: "storage resource with multiple inputs from previous task - copy from bucket", - task: taskWithMultipleGcsInputs, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "get-from-gcs", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage1", - }, - Name: "workspace", - }, - Paths: []string{"prev-task-path"}, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "storage2", - }, - Name: "workspace2", - }, - Paths: []string{"prev-task-path2"}, - }}, - }, - }, - }, - want: &v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "artifact-dest-mkdir-workspace-vr6ds", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-dir"}, - }, { - Name: "artifact-copy-from-workspace-l22wn", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "gs://fake-bucket/prev-task-path/*", "/workspace/gcs-dir"}, - Env: gcsEnv, - VolumeMounts: gcsVolumeMounts, - }, { - Name: "artifact-dest-mkdir-workspace2-6nl7g", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/gcs-dir"}, - }, { - Name: "artifact-copy-from-workspace2-j2tds", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "gs://fake-bucket/prev-task-path2/*", "/workspace/gcs-dir"}, - Env: gcsEnv, - VolumeMounts: gcsVolumeMounts, - }}, - Resources: &v1beta1.TaskResources{ - Inputs: multipleGcsInputs, - }, - Volumes: gcsVolumes, - }, - }} { - t.Run(c.desc, func(t *testing.T) { - setUp() - fakekubeclient := fakek8s.NewSimpleClientset() - bucketConfig, err := config.NewArtifactBucketFromMap(map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - config.BucketServiceAccountSecretNameKey: "gcs-config", - config.BucketServiceAccountSecretKeyKey: "my-key", - }) - if err != nil { - t.Fatalf("Test: %q; Error setting up bucket config = %v", c.desc, err) - } - configs := config.Config{ - ArtifactBucket: bucketConfig, - } - ctx := config.ToContext(context.Background(), &configs) - got, err := AddInputResource(ctx, fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, mockResolveTaskResources(c.taskRun)) - if err != nil { - t.Errorf("Test: %q; AddInputResource() error = %v", c.desc, err) - } - if d := cmp.Diff(c.want, got); d != "" { - t.Errorf("Didn't get expected TaskSpec %s", diff.PrintWantGot(d)) - } - }) - } -} - -func mockResolveTaskResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.PipelineResourceInterface { - resolved := make(map[string]v1beta1.PipelineResourceInterface) - if taskRun.Spec.Resources == nil { - return resolved - } - for _, r := range taskRun.Spec.Resources.Inputs { - var i v1beta1.PipelineResourceInterface - switch { - case r.ResourceRef != nil && r.ResourceRef.Name != "": - i = inputResourceInterfaces[r.ResourceRef.Name] - resolved[r.Name] = i - case r.ResourceSpec != nil: - i, _ = resource.FromType(r.Name, &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: r.Name, - }, - Spec: *r.ResourceSpec, - }, images) - resolved[r.Name] = i - default: - resolved[r.Name] = nil - } - } - return resolved -} diff --git a/pkg/reconciler/taskrun/resources/input_resources.go b/pkg/reconciler/taskrun/resources/input_resources.go deleted file mode 100644 index 24edfe14769..00000000000 --- a/pkg/reconciler/taskrun/resources/input_resources.go +++ /dev/null @@ -1,146 +0,0 @@ -/* -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 resources - -import ( - "context" - "fmt" - "path/filepath" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - "github.com/tektoncd/pipeline/pkg/artifacts" - corev1 "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes" -) - -func getBoundResource(resourceName string, boundResources []v1beta1.TaskResourceBinding) (*v1beta1.TaskResourceBinding, error) { - for _, br := range boundResources { - if br.Name == resourceName { - return &br, nil - } - } - return nil, fmt.Errorf("couldnt find resource named %q in bound resources %v", resourceName, boundResources) -} - -// AddInputResource reads the inputs resources and adds the corresponding container steps -// This function reads the `paths` to check if resource copies needs to be fetched from previous tasks output(from PVC) -// 1. If resource has paths declared then serially copies the resource from previous task output paths into current resource destination. -// 2. If resource has custom destination directory using targetPath then that directory is created and resource is fetched / copied -// from previous task -// 3. If resource has paths declared then fresh copy of resource is not fetched -func AddInputResource( - ctx context.Context, - kubeclient kubernetes.Interface, - images pipeline.Images, - taskName string, - taskSpec *v1beta1.TaskSpec, - taskRun *v1beta1.TaskRun, - inputResources map[string]v1beta1.PipelineResourceInterface, -) (*v1beta1.TaskSpec, error) { - if taskSpec == nil || taskSpec.Resources == nil || taskSpec.Resources.Inputs == nil { - return taskSpec, nil - } - taskSpec = taskSpec.DeepCopy() - - pvcName := taskRun.GetPipelineRunPVCName() - mountPVC := false - mountSecrets := false - - prNameFromLabel := taskRun.Labels[pipeline.PipelineRunLabelKey] - if prNameFromLabel == "" { - prNameFromLabel = pvcName - } - as := artifacts.GetArtifactStorage(ctx, images, prNameFromLabel, kubeclient) - - // Iterate in reverse through the list, each element prepends but we want the first one to remain first. - for i := len(taskSpec.Resources.Inputs) - 1; i >= 0; i-- { - input := taskSpec.Resources.Inputs[i] - if taskRun.Spec.Resources == nil { - if input.Optional { - continue - } - return nil, fmt.Errorf("couldnt find resource named %q, no bounded resources", input.Name) - } - boundResource, err := getBoundResource(input.Name, taskRun.Spec.Resources.Inputs) - // Continue if the declared resource is optional and not specified in TaskRun - // boundResource is nil if the declared resource in Task does not have any resource specified in the TaskRun - if input.Optional && boundResource == nil { - continue - } else if err != nil { - // throw an error for required resources, if not specified in the TaskRun - return nil, fmt.Errorf("failed to get bound resource: %w", err) - } - resource, ok := inputResources[boundResource.Name] - if !ok || resource == nil { - return nil, fmt.Errorf("failed to Get Pipeline Resource for task %s with boundResource %v", taskName, boundResource) - } - var copyStepsFromPrevTasks []v1beta1.Step - dPath := destinationPath(input.Name, input.TargetPath) - // if taskrun is fetching resource from previous task then execute copy step instead of fetching new copy - // to the desired destination directory, as long as the resource exports output to be copied - if v1beta1.AllowedOutputResources[resource.GetType()] && taskRun.HasPipelineRunOwnerReference() { - for _, path := range boundResource.Paths { - cpSteps := as.GetCopyFromStorageToSteps(boundResource.Name, path, dPath) - if as.GetType() == pipeline.ArtifactStoragePVCType { - mountPVC = true - for _, s := range cpSteps { - s.VolumeMounts = []corev1.VolumeMount{storage.GetPvcMount(pvcName)} - copyStepsFromPrevTasks = append(copyStepsFromPrevTasks, - storage.CreateDirStep(images.ShellImage, boundResource.Name, dPath), - s) - } - } else { - // bucket - copyStepsFromPrevTasks = append(copyStepsFromPrevTasks, cpSteps...) - } - } - } - // source is copied from previous task so skip fetching download container definition - if len(copyStepsFromPrevTasks) > 0 { - taskSpec.Steps = append(copyStepsFromPrevTasks, taskSpec.Steps...) - mountSecrets = true - } else { - // Allow the resource to mutate the task. - modifier, err := resource.GetInputTaskModifier(taskSpec, dPath) - if err != nil { - return nil, err - } - if err := v1beta1.ApplyTaskModifier(taskSpec, modifier); err != nil { - return nil, fmt.Errorf("unabled to apply Resource %s: %w", boundResource.Name, err) - } - } - } - - if mountPVC { - taskSpec.Volumes = append(taskSpec.Volumes, GetPVCVolume(pvcName)) - } - if mountSecrets { - taskSpec.Volumes = appendNewSecretsVolumes(taskSpec.Volumes, as.GetSecretsVolumes()...) - } - return taskSpec, nil -} - -const workspaceDir = "/workspace" - -func destinationPath(name, path string) string { - if path == "" { - return filepath.Join(workspaceDir, name) - } - return filepath.Join(workspaceDir, path) -} diff --git a/pkg/reconciler/taskrun/resources/output_resource.go b/pkg/reconciler/taskrun/resources/output_resource.go index 83a99092942..7ad8e480dbe 100644 --- a/pkg/reconciler/taskrun/resources/output_resource.go +++ b/pkg/reconciler/taskrun/resources/output_resource.go @@ -23,8 +23,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" - "github.com/tektoncd/pipeline/pkg/artifacts" "k8s.io/client-go/kubernetes" ) @@ -32,6 +30,15 @@ var ( outputDir = "/workspace/output/" ) +func getBoundResource(resourceName string, boundResources []v1beta1.TaskResourceBinding) (*v1beta1.TaskResourceBinding, error) { + for _, br := range boundResources { + if br.Name == resourceName { + return &br, nil + } + } + return nil, fmt.Errorf("couldnt find resource named %q in bound resources %v", resourceName, boundResources) +} + // AddOutputResources reads the output resources and adds the corresponding container steps // This function also reads the inputs to check if resources are redeclared in inputs and has any custom // target directory. @@ -60,11 +67,6 @@ func AddOutputResources( } taskSpec = taskSpec.DeepCopy() - - pvcName := taskRun.GetPipelineRunPVCName() - as := artifacts.GetArtifactStorage(ctx, images, pvcName, kubeclient) - - needsPvc := false for _, output := range taskSpec.Resources.Outputs { if taskRun.Spec.Resources == nil { if output.Optional { @@ -93,18 +95,9 @@ func AddOutputResources( sourcePath = output.TargetPath } - // Add containers to mkdir each output directory. This should run before the build steps themselves. - mkdirSteps := []v1beta1.Step{storage.CreateDirStep(images.ShellImage, boundResource.Name, sourcePath)} - taskSpec.Steps = append(mkdirSteps, taskSpec.Steps...) - if v1beta1.AllowedOutputResources[resource.GetType()] && taskRun.HasPipelineRunOwnerReference() { var newSteps []v1beta1.Step - for _, dPath := range boundResource.Paths { - newSteps = append(newSteps, as.GetCopyToStorageFromSteps(resource.GetName(), sourcePath, dPath)...) - needsPvc = true - } taskSpec.Steps = append(taskSpec.Steps, newSteps...) - taskSpec.Volumes = appendNewSecretsVolumes(taskSpec.Volumes, as.GetSecretsVolumes()...) } // Allow the resource to mutate the task. @@ -116,21 +109,5 @@ func AddOutputResources( return nil, fmt.Errorf("Unabled to apply Resource %s: %w", boundResource.Name, err) } } - // Attach the PVC that will be used for `from` copying. - if as.GetType() == pipeline.ArtifactStoragePVCType { - if pvcName == "" { - return taskSpec, nil - } - - // attach pvc volume only if it is not already attached - for _, buildVol := range taskSpec.Volumes { - if buildVol.Name == pvcName { - return taskSpec, nil - } - } - if needsPvc { - taskSpec.Volumes = append(taskSpec.Volumes, GetPVCVolume(pvcName)) - } - } return taskSpec, nil } diff --git a/pkg/reconciler/taskrun/resources/output_resource_test.go b/pkg/reconciler/taskrun/resources/output_resource_test.go index 27ddb5dcd8a..c3b8a91aabd 100644 --- a/pkg/reconciler/taskrun/resources/output_resource_test.go +++ b/pkg/reconciler/taskrun/resources/output_resource_test.go @@ -21,7 +21,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/resource" @@ -31,115 +30,22 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" - "knative.dev/pkg/ptr" ) var ( outputTestResources map[string]v1beta1.PipelineResourceInterface + images = pipeline.Images{ + EntrypointImage: "override-with-entrypoint:latest", + NopImage: "override-with-nop:latest", + GitImage: "override-with-git:latest", + ShellImage: "busybox", + GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", + ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + } ) func outputTestResourceSetup() { rs := []*resourcev1alpha1.PipelineResource{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "source-git", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Url", - Value: "https://github.com/grafeas/kritis", - }, { - Name: "Revision", - Value: "master", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "invalid-source-storage", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "source-gcs", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://some-bucket", - }, { - Name: "type", - Value: "gcs", - }, { - Name: "dir", - Value: "true", - }}, - SecretParams: []resourcev1alpha1.SecretParam{{ - SecretKey: "key.json", - SecretName: "sname", - FieldName: "GOOGLE_APPLICATION_CREDENTIALS", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "source-gcs-bucket", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://some-bucket", - }, { - Name: "Type", - Value: "gcs", - }, { - Name: "dir", - Value: "true", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "source-gcs-bucket-2", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://some-bucket-2", - }, { - Name: "Type", - Value: "gcs", - }, { - Name: "dir", - Value: "true", - }}, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "source-gcs-bucket-3", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "storage", - Params: []resourcev1alpha1.ResourceParam{{ - Name: "Location", - Value: "gs://some-bucket-3", - }, { - Name: "Type", - Value: "gcs", - }, { - Name: "dir", - Value: "true", - }}, - }, - }, { ObjectMeta: metav1.ObjectMeta{ Name: "source-image", Namespace: "marshmallow", @@ -162,11 +68,10 @@ func TestValidOutputResources(t *testing.T) { desc string task *v1beta1.Task taskRun *v1beta1.TaskRun - wantSteps []v1beta1.Step wantVolumes []corev1.Volume }{{ - name: "git resource in input and output", - desc: "git resource declared as both input and output with pipelinerun owner reference", + name: "image resource in output with pipelinerun with owner", + desc: "image resource declared as output with pipelinerun owner reference should not generate any steps", taskRun: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: "test-taskrun-run-output-steps", @@ -178,19 +83,11 @@ func TestValidOutputResources(t *testing.T) { }, Spec: v1beta1.TaskRunSpec{ Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", - }, - }, - }}, Outputs: []v1beta1.TaskResourceBinding{{ PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: "source-workspace", ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", + Name: "source-image", }, }, Paths: []string{"pipeline-task-name"}, @@ -205,64 +102,21 @@ func TestValidOutputResources(t *testing.T) { }, Spec: v1beta1.TaskSpec{ Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace", - Type: "git", + Type: "image", }}}, }, }, }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, { - Name: "source-mkdir-source-git-mz4c7", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"mkdir", "-p", "pipeline-task-name"}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "pipelinerun-pvc", - MountPath: "/pvc", - }}, - }, { - Name: "source-copy-source-git-mssqb", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-name"}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "pipelinerun-pvc", - MountPath: "/pvc", - }}, - Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-git"}}, - }}, - wantVolumes: []corev1.Volume{ - { - Name: "pipelinerun-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "pipelinerun-pvc", - ReadOnly: false, - }, - }, - }, - }, + wantVolumes: nil, }, { - name: "git resource in output only", - desc: "git resource declared as output with pipelinerun owner reference", + name: "image resource as output", + desc: "image resource defined only in output", taskRun: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", + Name: "test-taskrun-run-only-output-step", Namespace: "marshmallow", OwnerReferences: []metav1.OwnerReference{{ Kind: "PipelineRun", @@ -275,10 +129,9 @@ func TestValidOutputResources(t *testing.T) { PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: "source-workspace", ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", + Name: "source-image", }, }, - Paths: []string{"pipeline-task-name"}, }}, }, }, @@ -293,61 +146,17 @@ func TestValidOutputResources(t *testing.T) { Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace", - Type: "git", + Type: "image", }}}, }, }, }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, { - Name: "source-mkdir-source-git-mz4c7", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"mkdir", "-p", "pipeline-task-name"}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "pipelinerun-pvc", - MountPath: "/pvc", - }}, - }, { - Name: "source-copy-source-git-mssqb", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-name"}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "pipelinerun-pvc", - MountPath: "/pvc", - }}, - Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-git"}}, - }}, - wantVolumes: []corev1.Volume{ - { - Name: "pipelinerun-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "pipelinerun-pvc", - ReadOnly: false, - }, - }, - }, - }, }, { - name: "image resource in output with pipelinerun with owner", - desc: "image resource declared as output with pipelinerun owner reference should not generate any steps", + desc: "multiple image output resource with no steps", taskRun: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: "test-taskrun-run-output-steps", Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, }, Spec: v1beta1.TaskRunSpec{ Resources: &v1beta1.TaskRunResources{ @@ -358,7 +167,13 @@ func TestValidOutputResources(t *testing.T) { Name: "source-image", }, }, - Paths: []string{"pipeline-task-name"}, + }, { + PipelineResourceBinding: v1beta1.PipelineResourceBinding{ + Name: "source-workspace-1", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "source-image", + }, + }, }}, }, }, @@ -374,91 +189,61 @@ func TestValidOutputResources(t *testing.T) { ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace", Type: "image", + }}, { + ResourceDeclaration: v1beta1.ResourceDeclaration{ + Name: "source-workspace-1", + Type: "image", }}}, }, }, }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - wantVolumes: nil, - }, { - name: "git resource in output", - desc: "git resource declared in output without pipelinerun owner reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", - }, - }, - }}, - }, - }, - }, + }} { + t.Run(c.name, func(t *testing.T) { + names.TestingSeed() + outputTestResourceSetup() + fakekubeclient := fakek8s.NewSimpleClientset() + got, err := AddOutputResources(context.Background(), fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, resolveOutputResources(c.taskRun)) + if err != nil { + t.Fatalf("Failed to declare output resources for test name %q ; test description %q: error %v", c.name, c.desc, err) + } + + if got != nil { + if d := cmp.Diff(c.wantVolumes, got.Volumes); d != "" { + t.Fatalf("post build steps volumes mismatch %s", diff.PrintWantGot(d)) + } + } + }) + } +} + +func TestInvalidOutputResources(t *testing.T) { + for _, c := range []struct { + desc string + task *v1beta1.Task + taskRun *v1beta1.TaskRun + wantErr bool + }{{ + desc: "no outputs defined", task: &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{ Name: "task1", Namespace: "marshmallow", }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, - }, - }, + Spec: v1beta1.TaskSpec{}, }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - }, { - name: "storage resource as both input and output", - desc: "storage resource defined in both input and output with parents pipelinerun reference", taskRun: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", + Name: "test-taskrun-run-only-output-step", Namespace: "marshmallow", OwnerReferences: []metav1.OwnerReference{{ Kind: "PipelineRun", - Name: "pipelinerun-parent", + Name: "pipelinerun", }}, }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - Paths: []string{"pipeline-task-path"}, - }}, - }, - }, }, + wantErr: false, + }, { + desc: "no outputs defined in taskrun but defined in task", task: &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{ Name: "task1", @@ -466,105 +251,27 @@ func TestValidOutputResources(t *testing.T) { }, Spec: v1beta1.TaskSpec{ Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - TargetPath: "faraway-disk", - }}}, Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace", - Type: "storage", + Type: "image", }}}, }, }, }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, - { - Name: "source-mkdir-source-gcs-mz4c7", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"mkdir", "-p", "pipeline-task-path"}, - VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-parent-pvc", MountPath: "/pvc"}}, - }, - { - Name: "source-copy-source-gcs-mssqb", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-path"}, - VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-parent-pvc", MountPath: "/pvc"}}, - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "source-gcs"}, - }, - }, - { - Name: "upload-source-gcs-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-source-gcs-sname", - MountPath: "/var/secret/sname", - }}, - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"}, - Env: []corev1.EnvVar{ - {Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/secret/sname/key.json"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - }, - }, - - wantVolumes: []corev1.Volume{{ - Name: "volume-source-gcs-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }, - { - Name: "pipelinerun-parent-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "pipelinerun-parent-pvc", - ReadOnly: false, - }, - }, - }, - }, - }, { - name: "storage resource as output", - desc: "storage resource defined only in output with pipeline ownder reference", taskRun: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", + Namespace: "foo", OwnerReferences: []metav1.OwnerReference{{ Kind: "PipelineRun", Name: "pipelinerun", }}, }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - Paths: []string{"pipeline-task-path"}, - }}, - }, - }, }, + wantErr: true, + }, { + desc: "optional outputs declared", task: &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{ Name: "task1", @@ -572,92 +279,27 @@ func TestValidOutputResources(t *testing.T) { }, Spec: v1beta1.TaskSpec{ Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, - { - Name: "source-mkdir-source-gcs-mz4c7", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"mkdir", "-p", "pipeline-task-path"}, - VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-pvc", MountPath: "/pvc"}}, - }, - { - Name: "source-copy-source-gcs-mssqb", - Image: "busybox", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - }, - Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-path"}, - VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-pvc", MountPath: "/pvc"}}, - Env: []corev1.EnvVar{ - {Name: "TEKTON_RESOURCE_NAME", Value: "source-gcs"}, - }, - }, - { - Name: "upload-source-gcs-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-source-gcs-sname", MountPath: "/var/secret/sname", - }}, - Env: []corev1.EnvVar{ - {Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/secret/sname/key.json"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"}, - }, - }, - wantVolumes: []corev1.Volume{{ - Name: "volume-source-gcs-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }, - { - Name: "pipelinerun-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "pipelinerun-pvc", - }, + Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ + Name: "source-workspace", + Type: "git", + Optional: true, + }}}, }, }, }, - }, { - name: "storage resource as output with no owner", - desc: "storage resource defined only in output without pipelinerun reference", taskRun: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", + Name: "test-taskrun-run-optional-output", Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - Paths: []string{"pipeline-task-path"}, - }}, - }, + OwnerReferences: []metav1.OwnerReference{{ + Kind: "PipelineRun", + Name: "pipelinerun", + }}, }, }, + wantErr: false, + }, { + desc: "required outputs declared", task: &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{ Name: "task1", @@ -665,674 +307,11 @@ func TestValidOutputResources(t *testing.T) { }, Spec: v1beta1.TaskSpec{ Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, - { - Name: "upload-source-gcs-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-source-gcs-sname", MountPath: "/var/secret/sname", - }}, - Env: []corev1.EnvVar{ - {Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/secret/sname/key.json"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"}, - }, - }, - wantVolumes: []corev1.Volume{{ - Name: "volume-source-gcs-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }}, - }, { - name: "storage resource as output with matching build volumes", - desc: "storage resource defined only in output without pipelinerun reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, - { - Name: "upload-source-gcs-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: []corev1.VolumeMount{{ - Name: "volume-source-gcs-sname", MountPath: "/var/secret/sname", - }}, - Env: []corev1.EnvVar{ - {Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/secret/sname/key.json"}, - {Name: "HOME", Value: pipeline.HomeDir}, - }, - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"}, - }, - }, - wantVolumes: []corev1.Volume{{ - Name: "volume-source-gcs-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }}, - }, { - name: "image resource as output", - desc: "image resource defined only in output", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - }, { - name: "Resource with TargetPath as output", - desc: "Resource with TargetPath defined only in output", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - TargetPath: "/workspace", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace"}, - }}, - }, { - desc: "image output resource with no steps", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - }, { - desc: "multiple image output resource with no steps", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace-1", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace-1", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-1-mz4c7", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace-1"}, - }, { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - }} { - t.Run(c.name, func(t *testing.T) { - names.TestingSeed() - outputTestResourceSetup() - fakekubeclient := fakek8s.NewSimpleClientset() - got, err := AddOutputResources(context.Background(), fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, resolveOutputResources(c.taskRun)) - if err != nil { - t.Fatalf("Failed to declare output resources for test name %q ; test description %q: error %v", c.name, c.desc, err) - } - - if got != nil { - if d := cmp.Diff(c.wantSteps, got.Steps); d != "" { - t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) - } - if d := cmp.Diff(c.wantVolumes, got.Volumes); d != "" { - t.Fatalf("post build steps volumes mismatch %s", diff.PrintWantGot(d)) - } - } - }) - } -} - -func TestValidOutputResourcesWithBucketStorage(t *testing.T) { - for _, c := range []struct { - name string - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - wantSteps []v1beta1.Step - }{{ - name: "git resource in input and output with bucket storage", - desc: "git resource declared as both input and output with pipelinerun owner reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", - }, - }, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", - }, - }, - Paths: []string{"pipeline-task-name"}, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, { - Name: "artifact-copy-to-source-git-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "/workspace/output/source-workspace", "gs://fake-bucket/pipeline-task-name"}, - }}, - }, { - name: "git resource in output only with bucket storage", - desc: "git resource declared as output with pipelinerun owner reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", - }, - }, - Paths: []string{"pipeline-task-name"}, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, { - Name: "artifact-copy-to-source-git-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "/workspace/output/source-workspace", "gs://fake-bucket/pipeline-task-name"}, - }}, - }, { - name: "git resource in output", - desc: "git resource declared in output without pipelinerun owner reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-git", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - }} { - t.Run(c.name, func(t *testing.T) { - outputTestResourceSetup() - names.TestingSeed() - fakekubeclient := fakek8s.NewSimpleClientset() - bucketConfig, err := config.NewArtifactBucketFromMap(map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - }) - if err != nil { - t.Fatalf("Test: %q; Error setting up bucket config = %v", c.desc, err) - } - configs := config.Config{ - ArtifactBucket: bucketConfig, - } - ctx := config.ToContext(context.Background(), &configs) - got, err := AddOutputResources(ctx, fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, resolveOutputResources(c.taskRun)) - if err != nil { - t.Fatalf("Failed to declare output resources for test name %q ; test description %q: error %v", c.name, c.desc, err) - } - if got != nil { - if d := cmp.Diff(c.wantSteps, got.Steps); d != "" { - t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) - } - } - }) - } -} - -func TestInvalidOutputResources(t *testing.T) { - for _, c := range []struct { - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - wantErr bool - }{{ - desc: "no outputs defined", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{}, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - }, - wantErr: false, - }, { - desc: "no outputs defined in task but defined in taskrun", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - }}}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - Paths: []string{"test-path"}, - }}, - }, - }, - }, - wantErr: false, - }, { - desc: "no outputs defined in taskrun but defined in task", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "foo", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - }, - wantErr: true, - }, { - desc: "invalid storage resource", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "invalid-source-storage", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}}, - }, - }, - }, - wantErr: true, - }, { - desc: "optional outputs declared", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - Optional: true, - }}}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-optional-output", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - }, - wantErr: false, - }, { - desc: "required outputs declared", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "git", - Optional: false, - }}}, + Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ + Name: "source-workspace", + Type: "git", + Optional: false, + }}}, }, }, }, @@ -1359,29 +338,6 @@ func TestInvalidOutputResources(t *testing.T) { } } -func resolveInputResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.PipelineResourceInterface { - resolved := make(map[string]v1beta1.PipelineResourceInterface) - if taskRun.Spec.Resources == nil { - return resolved - } - for _, r := range taskRun.Spec.Resources.Inputs { - var i v1beta1.PipelineResourceInterface - if name := r.ResourceRef.Name; name != "" { - i = outputTestResources[name] - resolved[r.Name] = i - } else if r.ResourceSpec != nil { - i, _ = resource.FromType(name, &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: r.Name, - }, - Spec: *r.ResourceSpec, - }, images) - resolved[r.Name] = i - } - } - return resolved -} - func resolveOutputResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.PipelineResourceInterface { resolved := make(map[string]v1beta1.PipelineResourceInterface) if taskRun.Spec.Resources == nil { @@ -1404,388 +360,3 @@ func resolveOutputResources(taskRun *v1beta1.TaskRun) map[string]v1beta1.Pipelin } return resolved } - -// TestInputOutputBucketResources checks that gcs storage resources can be used as both inputs and -// outputs in the same tasks if a artifact bucket configmap exists. -func TestInputOutputBucketResources(t *testing.T) { - for _, c := range []struct { - name string - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - wantSteps []v1beta1.Step - wantVolumes []corev1.Volume - }{{ - name: "storage resource as both input and output", - desc: "storage resource defined in both input and output with parents pipelinerun reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun-parent", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket", - }, - }, - Paths: []string{"pipeline-task-path"}, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - TargetPath: "faraway-disk", - }}}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-mssqb", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }, - { - Name: "artifact-dest-mkdir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/faraway-disk"}, - VolumeMounts: nil, - }, - { - Name: "artifact-copy-from-source-workspace-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{ - "cp", - "-P", - "-r", - "gs://fake-bucket/pipeline-task-path/*", - "/workspace/faraway-disk", - }, - Env: []corev1.EnvVar{{ - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/bucketsecret/sname/key.json", - }}, - VolumeMounts: []corev1.VolumeMount{{Name: "volume-bucket-sname", MountPath: "/var/bucketsecret/sname"}}, - }, - { - Name: "upload-source-gcs-bucket-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: nil, - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"}, - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: pipeline.HomeDir, - }}, - }, - }, - wantVolumes: []corev1.Volume{{ - Name: "volume-bucket-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }}, - }, { - name: "two storage resource inputs and one output", - desc: "two storage resources defined in input and one in output with parents pipelinerun reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun-parent", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket", - }, - }, - Paths: []string{"pipeline-task-path"}, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace-2", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket-2", - }, - }, - Paths: []string{"pipeline-task-path-2"}, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace-3", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket-3", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - TargetPath: "faraway-disk", - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace-2", - Type: "storage", - TargetPath: "faraway-disk-2", - }}}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace-3", - Type: "storage", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-3-6nl7g", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace-3"}, - }, - { - Name: "artifact-dest-mkdir-source-workspace-mssqb", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/faraway-disk"}, - VolumeMounts: nil, - }, - { - Name: "artifact-copy-from-source-workspace-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{ - "cp", - "-P", - "-r", - "gs://fake-bucket/pipeline-task-path/*", - "/workspace/faraway-disk", - }, - Env: []corev1.EnvVar{ - { - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/bucketsecret/sname/key.json", - }, - }, - VolumeMounts: []corev1.VolumeMount{{Name: "volume-bucket-sname", MountPath: "/var/bucketsecret/sname"}}, - }, - { - Name: "artifact-dest-mkdir-source-workspace-2-9l9zj", - Image: "busybox", - VolumeMounts: nil, - Command: []string{"mkdir", "-p", "/workspace/faraway-disk-2"}, - Env: nil, - }, - { - Name: "artifact-copy-from-source-workspace-2-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"cp", "-P", "-r", "gs://fake-bucket/pipeline-task-path-2/*", "/workspace/faraway-disk-2"}, - Env: []corev1.EnvVar{ - { - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/bucketsecret/sname/key.json", - }, - }, - VolumeMounts: []corev1.VolumeMount{{Name: "volume-bucket-sname", MountPath: "/var/bucketsecret/sname"}}, - }, { - Name: "upload-source-gcs-bucket-3-j2tds", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace-3", "gs://some-bucket-3"}, - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: pipeline.HomeDir, - }}, - }, - }, - wantVolumes: []corev1.Volume{{ - Name: "volume-bucket-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }}, - }, { - name: "two storage resource outputs", - desc: "two storage resources defined in output with parents pipelinerun reference", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun-parent", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace-2", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs-bucket-2", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "storage", - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace-2", - Type: "storage", - }}, - }, - }, - }, - }, - wantSteps: []v1beta1.Step{ - { - Name: "create-dir-source-workspace-2-mssqb", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace-2"}, - }, - { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - VolumeMounts: nil, - }, - { - Name: "upload-source-gcs-bucket-mz4c7", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - Command: []string{"gsutil"}, - Args: []string{ - "rsync", - "-d", - "-r", - "/workspace/output/source-workspace", - "gs://some-bucket", - }, - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: pipeline.HomeDir, - }}, - }, - { - Name: "upload-source-gcs-bucket-2-78c5n", - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk", - VolumeMounts: nil, - Command: []string{"gsutil"}, - Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace-2", "gs://some-bucket-2"}, - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: pipeline.HomeDir, - }}, - }, - }, - wantVolumes: []corev1.Volume{{ - Name: "volume-bucket-sname", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, - }, - }}, - }} { - t.Run(c.name, func(t *testing.T) { - names.TestingSeed() - outputTestResourceSetup() - fakekubeclient := fakek8s.NewSimpleClientset() - bucketConfig, err := config.NewArtifactBucketFromMap(map[string]string{ - config.BucketLocationKey: "gs://fake-bucket", - config.BucketServiceAccountSecretNameKey: "sname", - config.BucketServiceAccountSecretKeyKey: "key.json", - }) - if err != nil { - t.Fatalf("Test: %q; Error setting up bucket config = %v", c.desc, err) - } - configs := config.Config{ - ArtifactBucket: bucketConfig, - } - ctx := config.ToContext(context.Background(), &configs) - inputs := resolveInputResources(c.taskRun) - ts, err := AddInputResource(ctx, fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, inputs) - if err != nil { - t.Fatalf("Failed to declare input resources for test name %q ; test description %q: error %v", c.name, c.desc, err) - } - - got, err := AddOutputResources(ctx, fakekubeclient, images, c.task.Name, ts, c.taskRun, resolveOutputResources(c.taskRun)) - if err != nil { - t.Fatalf("Failed to declare output resources for test name %q ; test description %q: error %v", c.name, c.desc, err) - } - - if got != nil { - if d := cmp.Diff(c.wantSteps, got.Steps); d != "" { - t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) - } - if d := cmp.Diff(c.wantVolumes, got.Volumes); d != "" { - t.Fatalf("post build steps volumes mismatch %s", diff.PrintWantGot(d)) - } - } - }) - } -} diff --git a/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go b/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go index b565eda553f..25eddf48575 100644 --- a/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go +++ b/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go @@ -57,13 +57,6 @@ func TestResolveTaskRun(t *testing.T) { Name: "another-git-repo", }, }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "gitspecToUse", - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, }} taskName := "orchestrate" @@ -127,7 +120,7 @@ func TestResolveTaskRun(t *testing.T) { t.Errorf("Expected 2 resolved inputs but instead had: %v", rtr.Inputs) } - if len(rtr.Outputs) == 3 { + if len(rtr.Outputs) == 2 { r, ok := rtr.Outputs["imageToBuild"] if !ok { t.Errorf("Expected value present in map for `imageToBuild' but it was missing") @@ -140,12 +133,6 @@ func TestResolveTaskRun(t *testing.T) { } else if r.Name != "another-git-repo" { t.Errorf("Expected to use resource `another-git-repo` for `gitRepoToUpdate` but used %s", r.Name) } - r, ok = rtr.Outputs["gitspecToUse"] - if !ok { - t.Errorf("Expected value present in map for `gitspecToUse' but it was missing") - } else if r.Spec.Type != resourcev1alpha1.PipelineResourceTypeGit { - t.Errorf("Expected to use resource type `git` for but got %s", r.Spec.Type) - } } else { t.Errorf("Expected 2 resolved outputs but instead had: %v", rtr.Outputs) } @@ -222,29 +209,6 @@ func TestResolveTaskRun_noResources(t *testing.T) { } } -func TestResolveTaskRun_InvalidBothSpecified(t *testing.T) { - inputs := []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "repoToBuildFrom", - // Can't specify both ResourceRef and ResourceSpec - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "git-repo", - }, - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - }} - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return &resourcev1alpha1.PipelineResource{}, nil - } - - _, err := ResolveTaskResources(&v1beta1.TaskSpec{}, "orchestrate", v1beta1.NamespacedTaskKind, inputs, []v1beta1.TaskResourceBinding{}, gr) - if err == nil { - t.Fatalf("Expected to get error because both ref and spec were used") - } -} - func TestResolveTaskRun_InvalidNeitherSpecified(t *testing.T) { inputs := []v1beta1.TaskResourceBinding{{ PipelineResourceBinding: v1beta1.PipelineResourceBinding{ @@ -288,9 +252,9 @@ func TestGetResourceFromBinding_Ref(t *testing.T) { func TestGetResourceFromBinding_Spec(t *testing.T) { binding := v1beta1.PipelineResourceBinding{ ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, Params: []resourcev1alpha1.ResourceParam{{ - Name: "url", + Name: "image", Value: "github.com/mycoolorg/mycoolrepo", }}, }, @@ -303,10 +267,10 @@ func TestGetResourceFromBinding_Spec(t *testing.T) { if err != nil { t.Fatalf("Did not expect error trying to get resource from binding: %s", err) } - if rr.Spec.Type != resourcev1alpha1.PipelineResourceTypeGit { + if rr.Spec.Type != resourcev1alpha1.PipelineResourceTypeImage { t.Errorf("Got %s instead of expected resource type", rr.Spec.Type) } - if len(rr.Spec.Params) != 1 || rr.Spec.Params[0].Name != "url" || rr.Spec.Params[0].Value != "github.com/mycoolorg/mycoolrepo" { + if len(rr.Spec.Params) != 1 || rr.Spec.Params[0].Name != "image" || rr.Spec.Params[0].Value != "github.com/mycoolorg/mycoolrepo" { t.Errorf("Got unexpected params %v", rr.Spec.Params) } } @@ -323,29 +287,6 @@ func TestGetResourceFromBinding_NoNameOrSpec(t *testing.T) { } } -func TestGetResourceFromBinding_NameAndSpec(t *testing.T) { - binding := v1beta1.PipelineResourceBinding{ - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "url", - Value: "github.com/mycoolorg/mycoolrepo", - }}, - }, - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "foo-resource", - }, - } - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return nil, nil - } - - _, err := GetResourceFromBinding(binding, gr) - if err == nil { - t.Fatalf("Expected error when no name or spec but got none") - } -} - func TestGetResourceFromBinding_ErrorGettingResource(t *testing.T) { binding := v1beta1.PipelineResourceBinding{ ResourceRef: &v1beta1.PipelineResourceRef{ diff --git a/pkg/reconciler/taskrun/resources/volume.go b/pkg/reconciler/taskrun/resources/volume.go deleted file mode 100644 index 08c3d732a10..00000000000 --- a/pkg/reconciler/taskrun/resources/volume.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -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 resources - -import ( - corev1 "k8s.io/api/core/v1" -) - -// GetPVCVolume gets pipelinerun pvc volume -func GetPVCVolume(name string) corev1.Volume { - return corev1.Volume{ - Name: name, - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ClaimName: name}, - }, - } -} - -// appendNewSecretsVolumes takes a variadic list of secret volumes and a list of volumes, and -// appends any secret volumes that aren't already present. The secret volumes are volumes whose -// VolumeSource is set to *corev1.SecretVolumeSource with only the SecretName field filled in. -// Specifically, they have the following structure as defined by -// (pkg/apis/resource/v1alpha1/storage.ArtifactBucket).GetSecretsVolumes(): -// -// corev1.Volume{ -// Name: fmt.Sprintf("volume-bucket-%s", sec.SecretName), -// VolumeSource: corev1.VolumeSource{ -// Secret: &corev1.SecretVolumeSource{ -// SecretName: sec.SecretName, -// }, -// }, -// } -// -// Any new volumes that don't match this structure are added regardless of whether they are already -// present in the list of volumes. -func appendNewSecretsVolumes(vols []corev1.Volume, newVols ...corev1.Volume) []corev1.Volume { - for _, newv := range newVols { - alreadyExists := false - for _, oldv := range vols { - if newv.Name != oldv.Name { - continue - } - if oldv.Secret == nil { - continue - } - if oldv.Secret.SecretName == newv.Secret.SecretName { - alreadyExists = true - break - } - } - if !alreadyExists { - vols = append(vols, newv) - } - } - return vols -} diff --git a/pkg/reconciler/taskrun/resources/volume_test.go b/pkg/reconciler/taskrun/resources/volume_test.go deleted file mode 100644 index aa5e65961d0..00000000000 --- a/pkg/reconciler/taskrun/resources/volume_test.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -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 resources_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" - "github.com/tektoncd/pipeline/test/diff" - corev1 "k8s.io/api/core/v1" -) - -func TestGetPVCVolume(t *testing.T) { - expectedVolume := corev1.Volume{ - Name: "test-pvc", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ClaimName: "test-pvc"}, - }, - } - if d := cmp.Diff(expectedVolume, resources.GetPVCVolume("test-pvc")); d != "" { - t.Fatalf("PVC volume mismatch: %s", diff.PrintWantGot(d)) - } -} diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 845de9e885e..0fbf14aa342 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -744,12 +744,6 @@ func (c *Reconciler) createPod(ctx context.Context, ts *v1beta1.TaskSpec, tr *v1 return nil, err } - ts, err = resources.AddInputResource(ctx, c.KubeClientSet, c.Images, rtr.TaskName, ts, tr, inputResources) - if err != nil { - logger.Errorf("Failed to create a pod for taskrun: %s due to input resource error %v", tr.Name, err) - return nil, err - } - ts, err = resources.AddOutputResources(ctx, c.KubeClientSet, c.Images, rtr.TaskName, ts, tr, outputResources) if err != nil { logger.Errorf("Failed to create a pod for taskrun: %s due to output resource error %v", tr.Name, err) diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 196b43cd928..6198da4ba0b 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -70,7 +70,6 @@ import ( "knative.dev/pkg/controller" "knative.dev/pkg/kmeta" "knative.dev/pkg/logging" - "knative.dev/pkg/ptr" pkgreconciler "knative.dev/pkg/reconciler" "knative.dev/pkg/system" @@ -185,35 +184,6 @@ var ( }, } - outputTask = &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "test-output-task"}, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{simpleStep}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{ - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: gitResource.Name, - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: anotherGitResource.Name, - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - }, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: gitResource.Name, - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }}, - }, - }, - } - saTask = &v1beta1.Task{ ObjectMeta: objectMeta("test-with-sa", "foo"), Spec: v1beta1.TaskSpec{ @@ -248,20 +218,6 @@ var ( Type: v1beta1.ParamTypeString, }, }, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace", - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "myimage", - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }}, - }, Steps: []v1beta1.Step{ { Image: "myimage", @@ -296,26 +252,6 @@ var ( }, } - gitResource = &resourcev1alpha1.PipelineResource{ - ObjectMeta: objectMeta("git-resource", "foo"), - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "https://foo.git", - }}, - }, - } - anotherGitResource = &resourcev1alpha1.PipelineResource{ - ObjectMeta: objectMeta("another-git-resource", "foo"), - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "https://foobar.git", - }}, - }, - } imageResource = &resourcev1alpha1.PipelineResource{ ObjectMeta: objectMeta("image-resource", "foo"), Spec: resourcev1alpha1.PipelineResourceSpec{ @@ -375,10 +311,6 @@ var ( EmptyDir: &corev1.EmptyDirVolumeSource{}, }, } - - gitResourceSecurityContext = &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - } ) const fakeVersion string = "unknown" @@ -696,60 +628,6 @@ spec: taskRef: apiVersion: a1 name: test-with-sa -`) - taskRunSubstitution := parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-taskrun-substitution - namespace: foo -spec: - params: - - name: myarg - value: foo - - name: myarghasdefault - value: bar - - name: configmapname - value: configbar - resources: - inputs: - - name: workspace - resourceRef: - name: git-resource - outputs: - - name: myimage - resourceRef: - name: image-resource - taskRef: - apiVersion: a1 - name: test-task-with-substitution -`) - taskRunInputOutput := parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-taskrun-input-output - namespace: foo - ownerReferences: - - kind: PipelineRun - name: test -spec: - resources: - inputs: - - name: git-resource - paths: - - source-folder - resourceRef: - name: git-resource - - name: another-git-resource - paths: - - source-folder - resourceRef: - name: another-git-resource - outputs: - - name: git-resource - paths: - - output-folder - resourceRef: - name: git-resource - taskRef: - name: test-output-task `) taskRunWithTaskSpec := parse.MustParseV1beta1TaskRun(t, ` metadata: @@ -759,56 +637,19 @@ spec: params: - name: myarg value: foo - resources: - inputs: - - name: workspace - resourceRef: - name: git-resource taskSpec: params: - default: mydefault name: myarg type: string - resources: - inputs: - - name: workspace - type: git steps: - args: - - --my-arg=$(inputs.params.myarg) command: - /mycmd image: myimage name: mycontainer `) - taskRunWithResourceSpecAndTaskSpec := parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-taskrun-with-resource-spec - namespace: foo -spec: - resources: - inputs: - - name: workspace - resourceSpec: - params: - - name: URL - value: github.com/foo/bar.git - - name: revision - value: rel-can - type: git - taskSpec: - resources: - inputs: - - name: workspace - type: git - steps: - - command: - - /mycmd - image: ubuntu - name: mystep -`) - taskRunWithClusterTask := parse.MustParseV1beta1TaskRun(t, ` metadata: name: test-taskrun-with-cluster-task @@ -892,17 +733,16 @@ spec: taskruns := []*v1beta1.TaskRun{ taskRunSuccess, taskRunWithSaSuccess, - taskRunSubstitution, taskRunInputOutput, - taskRunWithTaskSpec, taskRunWithClusterTask, taskRunWithResourceSpecAndTaskSpec, + taskRunWithTaskSpec, taskRunWithClusterTask, taskRunWithLabels, taskRunWithAnnotations, taskRunWithPod, taskRunWithCredentialsVariable, taskRunBundle, } d := test.Data{ TaskRuns: taskruns, - Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask, outputTask}, + Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask}, ClusterTasks: []*v1beta1.ClusterTask{clustertask}, - PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource, imageResource}, + PipelineResources: []*resourcev1alpha1.PipelineResource{imageResource}, } for _, tc := range []struct { name string @@ -933,71 +773,6 @@ spec: name: "sa-step", cmd: "/mycmd", }}), - }, { - name: "params", - taskRun: taskRunSubstitution, - wantEvents: []string{ - "Normal Started ", - "Normal Running Not all Steps", - }, - wantPod: expectedPod("test-taskrun-substitution-pod", "test-task-with-substitution", "test-taskrun-substitution", "foo", config.DefaultServiceAccountValue, false, []corev1.Volume{{ - Name: "volume-configmap", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "configbar", - }, - }, - }, - }}, []stepForExpectedPod{ - { - name: "create-dir-myimage-mssqb", - image: "busybox", - cmd: "mkdir", - args: []string{"-p", "/workspace/output/myimage"}, - }, - { - name: "git-source-workspace-mz4c7", - image: "override-with-git:latest", - cmd: "/ko-app/git-init", - args: []string{"-url", "https://foo.git", - "-path", "/workspace/workspace"}, - envVars: map[string]string{ - "TEKTON_RESOURCE_NAME": "workspace", - "HOME": "/tekton/home", - }, - workingDir: workspaceDir, - securityContext: gitResourceSecurityContext, - }, - { - name: "mycontainer", - image: "myimage", - cmd: "/mycmd", - args: []string{ - "--my-arg=foo", - "--my-arg-with-default=bar", - "--my-arg-with-default2=thedefault", - "--my-additional-arg=gcr.io/kristoff/sven", - "--my-taskname-arg=test-task-with-substitution", - "--my-taskrun-arg=test-taskrun-substitution", - }, - }, - { - name: "myothercontainer", - image: "myotherimage", - cmd: "/mycmd", - args: []string{"--my-other-arg=https://foo.git"}, - }, - { - name: "image-digest-exporter-9l9zj", - image: "override-with-imagedigest-exporter-image:latest", - cmd: "/ko-app/imagedigestexporter", - args: []string{ - "-images", - "[{\"name\":\"myimage\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/myimage\"}]", - }, - }, - }), }, { name: "taskrun-with-taskspec", taskRun: taskRunWithTaskSpec, @@ -1006,26 +781,10 @@ spec: "Normal Running Not all Steps", }, wantPod: expectedPod("test-taskrun-with-taskspec-pod", "", "test-taskrun-with-taskspec", "foo", config.DefaultServiceAccountValue, false, nil, []stepForExpectedPod{ - { - name: "git-source-workspace-9l9zj", - image: "override-with-git:latest", - cmd: "/ko-app/git-init", - args: []string{"-url", "https://foo.git", - "-path", "/workspace/workspace"}, - envVars: map[string]string{ - "TEKTON_RESOURCE_NAME": "workspace", - "HOME": "/tekton/home", - }, - workingDir: workspaceDir, - securityContext: gitResourceSecurityContext, - }, { name: "mycontainer", image: "myimage", cmd: "/mycmd", - args: []string{ - "--my-arg=foo", - }, }, }), }, { @@ -1040,35 +799,6 @@ spec: image: "foo", cmd: "/mycmd", }}), - }, { - name: "taskrun-with-resource-spec-task-spec", - taskRun: taskRunWithResourceSpecAndTaskSpec, - wantEvents: []string{ - "Normal Started ", - "Normal Running Not all Steps", - }, - wantPod: expectedPod("test-taskrun-with-resource-spec-pod", "", "test-taskrun-with-resource-spec", "foo", config.DefaultServiceAccountValue, false, nil, []stepForExpectedPod{ - { - name: "git-source-workspace-9l9zj", - image: "override-with-git:latest", - cmd: "/ko-app/git-init", - args: []string{"-url", "github.com/foo/bar.git", - "-path", "/workspace/workspace", - "-revision", "rel-can", - }, - envVars: map[string]string{ - "TEKTON_RESOURCE_NAME": "workspace", - "HOME": "/tekton/home", - }, - workingDir: workspaceDir, - securityContext: gitResourceSecurityContext, - }, - { - name: "mystep", - image: "ubuntu", - cmd: "/mycmd", - }, - }), }, { name: "taskrun-with-pod", taskRun: taskRunWithPod, @@ -1214,9 +944,9 @@ spec: d := test.Data{ ConfigMaps: cms, TaskRuns: taskruns, - Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask, outputTask}, + Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask}, ClusterTasks: []*v1beta1.ClusterTask{clustertask}, - PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource, imageResource}, + PipelineResources: []*resourcev1alpha1.PipelineResource{imageResource}, } for _, tc := range []struct { name string diff --git a/pkg/reconciler/taskrun/validate_resources_test.go b/pkg/reconciler/taskrun/validate_resources_test.go index 19db70401af..ab1406651ba 100644 --- a/pkg/reconciler/taskrun/validate_resources_test.go +++ b/pkg/reconciler/taskrun/validate_resources_test.go @@ -45,22 +45,6 @@ func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { Command: []string{"mycmd"}, }}, Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{ - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "resource-to-build", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: false, - }, - }, - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-resource-to-build", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: true, - }, - }, - }, Outputs: []v1beta1.TaskResource{ { ResourceDeclaration: v1beta1.ResourceDeclaration{ @@ -82,28 +66,7 @@ func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { } rtr := &resources.ResolvedTaskResources{ TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{ - "resource-to-build": { - ObjectMeta: metav1.ObjectMeta{Name: "example-resource"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []v1beta1.ResourceParam{{ - Name: "foo", - Value: "bar", - }}, - }, - }, - "optional-resource-to-build": { - ObjectMeta: metav1.ObjectMeta{Name: "example-resource"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []v1beta1.ResourceParam{{ - Name: "foo", - Value: "bar", - }}, - }, - }, - }, + Inputs: map[string]*resourcev1alpha1.PipelineResource{}, Outputs: map[string]*resourcev1alpha1.PipelineResource{ "resource-to-provide": { ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, @@ -345,9 +308,9 @@ func TestValidateResolvedTaskResources_InvalidParams(t *testing.T) { func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { ctx := context.Background() r := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{Name: "git-test-resource"}, + ObjectMeta: metav1.ObjectMeta{Name: "image-test-resource"}, Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, Params: []resourcev1alpha1.ResourceParam{{ Name: "foo", Value: "bar", @@ -361,7 +324,7 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { Inputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "testinput", - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, }, }}, }, @@ -380,14 +343,14 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, }, } - testrequiredgitinput := &v1beta1.Task{ + testrequiredimageinput := &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: v1beta1.TaskSpec{ Resources: &v1beta1.TaskResources{ Inputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredgitinput", - Type: resourcev1alpha1.PipelineResourceTypeGit, + Name: "requiredimageinput", + Type: resourcev1alpha1.PipelineResourceTypeImage, Optional: false, }, }}, @@ -401,7 +364,7 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "testoutput", - Type: resourcev1alpha1.PipelineResourceTypeGit, + Type: resourcev1alpha1.PipelineResourceTypeImage, }, }}, }, @@ -420,14 +383,14 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, }, } - testrequiredgitoutput := &v1beta1.Task{ + testrequiredimageoutput := &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: v1beta1.TaskSpec{ Resources: &v1beta1.TaskResources{ Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredgitoutput", - Type: resourcev1alpha1.PipelineResourceTypeGit, + Name: "requiredimageoutput", + Type: resourcev1alpha1.PipelineResourceTypeImage, Optional: false, }, }}, @@ -459,34 +422,10 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { name string rtr *resources.ResolvedTaskResources }{{ - name: "bad-inputkey", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testinput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{"wrong-resource-name": r}, - }, - }, { - name: "bad-outputkey", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testoutput.Spec, - Outputs: map[string]*resourcev1alpha1.PipelineResource{"wrong-resource-name": r}, - }, - }, { - name: "input-resource-mismatch", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageinput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{"testimageinput": r}, - }, - }, { name: "input-resource-missing", rtr: &resources.ResolvedTaskResources{ TaskSpec: &testimageinput.Spec, }, - }, { - name: "output-resource-mismatch", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageoutput.Spec, - Outputs: map[string]*resourcev1alpha1.PipelineResource{"testimageoutput": r}, - }, }, { name: "output-resource-missing", rtr: &resources.ResolvedTaskResources{ @@ -495,7 +434,7 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, { name: "extra-input-resource", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testinput.Spec, + TaskSpec: &testimageinput.Spec, Inputs: map[string]*resourcev1alpha1.PipelineResource{ "testinput": r, "someextrainput": r, @@ -527,12 +466,12 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, { name: "required-input-resource-missing", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testrequiredgitinput.Spec, + TaskSpec: &testrequiredimageinput.Spec, }, }, { name: "required-output-resource-missing", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testrequiredgitoutput.Spec, + TaskSpec: &testrequiredimageoutput.Spec, }, }, { name: "required-input-and-output-resource-missing", diff --git a/pkg/taskrunmetrics/metrics_test.go b/pkg/taskrunmetrics/metrics_test.go index 1dddb03c747..694ce23eafd 100644 --- a/pkg/taskrunmetrics/metrics_test.go +++ b/pkg/taskrunmetrics/metrics_test.go @@ -92,7 +92,7 @@ func TestMetricsOnStore(t *testing.T) { } // We check that there's no change when incorrect config is passed - MetricsOnStore(logger)(config.GetMetricsConfigName(), &config.ArtifactBucket{}) + MetricsOnStore(logger)(config.GetMetricsConfigName(), &config.Store{}) // Comparing function assign to struct with the one which should yield same value if reflect.ValueOf(metrics.insertTaskTag).Pointer() != reflect.ValueOf(taskrunInsertTag).Pointer() { t.Fatalf("metrics recorder shouldn't change during this OnStore call") diff --git a/test/artifact_bucket_test.go b/test/artifact_bucket_test.go deleted file mode 100644 index f5e8ee9cfae..00000000000 --- a/test/artifact_bucket_test.go +++ /dev/null @@ -1,358 +0,0 @@ -//go:build e2e -// +build e2e - -/* -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 test - -import ( - "context" - "fmt" - "os" - "testing" - "time" - - "github.com/tektoncd/pipeline/test/parse" - - "github.com/tektoncd/pipeline/pkg/apis/config" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -const ( - systemNamespace = "tekton-pipelines" - bucketSecretName = "bucket-secret" - bucketSecretKey = "bucket-secret-key" -) - -// TestStorageBucketPipelineRun is an integration test that will verify a pipeline -// can use a bucket for temporary storage of artifacts shared between tasks -func TestStorageBucketPipelineRun(t *testing.T) { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - configFilePath := os.Getenv("GCP_SERVICE_ACCOUNT_KEY_PATH") - if configFilePath == "" { - t.Skip("GCP_SERVICE_ACCOUNT_KEY_PATH variable is not set.") - } - c, namespace := setup(ctx, t) - // Bucket tests can't run in parallel without causing issues with other tests. - - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - helloworldResourceName := helpers.ObjectNameForTest(t) - addFileTaskName := helpers.ObjectNameForTest(t) - runFileTaskName := helpers.ObjectNameForTest(t) - bucketTestPipelineName := helpers.ObjectNameForTest(t) - bucketTestPipelineRunName := helpers.ObjectNameForTest(t) - - bucketName := fmt.Sprintf("build-pipeline-test-%s-%d", namespace, time.Now().Unix()) - - t.Logf("Creating Secret %s", bucketSecretName) - if _, err := c.KubeClient.CoreV1().Secrets(namespace).Create(ctx, getBucketSecret(t, configFilePath, namespace), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Secret %q: %v", bucketSecretName, err) - } - defer deleteBucketSecret(ctx, t, c, namespace) - - t.Logf("Creating GCS bucket %s", bucketName) - createbuckettask := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - steps: - - name: step1 - image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine - command: ['/bin/bash'] - args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil mb gs://%s'] - volumeMounts: - - name: bucket-secret-volume - mountPath: /var/secret/%s - env: - - name: CREDENTIALS - value: /var/secret/%s/%s - volumes: - - name: bucket-secret-volume - secret: - secretName: %s -`, helpers.ObjectNameForTest(t), namespace, bucketName, bucketSecretName, bucketSecretName, bucketSecretKey, bucketSecretName)) - - t.Logf("Creating Task %s", createbuckettask.Name) - if _, err := c.V1beta1TaskClient.Create(ctx, createbuckettask, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", createbuckettask.Name, err) - } - - createbuckettaskrun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - taskRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, createbuckettask.Name)) - - t.Logf("Creating TaskRun %s", createbuckettaskrun.Name) - if _, err := c.V1beta1TaskRunClient.Create(ctx, createbuckettaskrun, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", createbuckettaskrun.Name, err) - } - - if err := WaitForTaskRunState(ctx, c, createbuckettaskrun.Name, TaskRunSucceed(createbuckettaskrun.Name), "TaskRunSuccess", v1beta1Version); err != nil { - t.Errorf("Error waiting for TaskRun %s to finish: %s", createbuckettaskrun.Name, err) - } - - defer runTaskToDeleteBucket(ctx, t, c, namespace, bucketName, bucketSecretName, bucketSecretKey) - - originalConfigMap, err := c.KubeClient.CoreV1().ConfigMaps(systemNamespace).Get(ctx, config.GetArtifactBucketConfigName(), metav1.GetOptions{}) - if err != nil { - t.Fatalf("Failed to get ConfigMap `%s`: %s", config.GetArtifactBucketConfigName(), err) - } - originalConfigMapData := originalConfigMap.Data - - t.Logf("Creating ConfigMap %s", config.GetArtifactBucketConfigName()) - configMapData := map[string]string{ - config.BucketLocationKey: fmt.Sprintf("gs://%s", bucketName), - config.BucketServiceAccountSecretNameKey: bucketSecretName, - config.BucketServiceAccountSecretKeyKey: bucketSecretKey, - } - if err := updateConfigMap(ctx, c.KubeClient, systemNamespace, config.GetArtifactBucketConfigName(), configMapData); err != nil { - t.Fatal(err) - } - defer resetConfigMap(ctx, t, c, systemNamespace, config.GetArtifactBucketConfigName(), originalConfigMapData) - - t.Logf("Creating Git PipelineResource %s", helloworldResourceName) - helloworldResource := parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - params: - - name: Url - value: https://github.com/pivotal-nader-ziada/gohelloworld - - name: Revision - value: master - type: git -`, helloworldResourceName)) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, helloworldResource, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", helloworldResourceName, err) - } - - t.Logf("Creating Task %s", addFileTaskName) - addFileTask := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: %s - type: git - outputs: - - name: %s - type: git - steps: - - image: ubuntu - name: addfile - script: |- - echo '#!/bin/bash - echo hello' > /workspace/helloworldgit/newfile - - image: ubuntu - name: make-executable - script: chmod +x /workspace/helloworldgit/newfile -`, addFileTaskName, namespace, helloworldResourceName, helloworldResourceName)) - if _, err := c.V1beta1TaskClient.Create(ctx, addFileTask, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", addFileTaskName, err) - } - - t.Logf("Creating Task %s", runFileTaskName) - readFileTask := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: %s - type: git - steps: - - command: ['/workspace/hellowrld/newfile'] - image: ubuntu - name: runfile -`, runFileTaskName, namespace, helloworldResourceName)) - if _, err := c.V1beta1TaskClient.Create(ctx, readFileTask, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", runFileTaskName, err) - } - - t.Logf("Creating Pipeline %s", bucketTestPipelineName) - bucketTestPipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - - name: source-repo - type: git - tasks: - - name: addfile - resources: - inputs: - - name: helloworldgit - resource: source-repo - outputs: - - name: helloworldgit - resource: source-repo - taskRef: - name: %s - - name: runfile - resources: - inputs: - - name: helloworldgit - resource: source-repo - taskRef: - name: %s -`, bucketTestPipelineName, namespace, addFileTaskName, runFileTaskName)) - if _, err := c.V1beta1PipelineClient.Create(ctx, bucketTestPipeline, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", bucketTestPipelineName, err) - } - - t.Logf("Creating PipelineRun %s", bucketTestPipelineRunName) - bucketTestPipelineRun := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - pipelineRef: - name: %s - resources: - - name: source-repo - resourceRef: - name: %s -`, bucketTestPipelineRunName, namespace, bucketTestPipelineName, helloworldResourceName)) - if _, err := c.V1beta1PipelineRunClient.Create(ctx, bucketTestPipelineRun, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create PipelineRun `%s`: %s", bucketTestPipelineRunName, err) - } - - // Verify status of PipelineRun (wait for it) - if err := WaitForPipelineRunState(ctx, c, bucketTestPipelineRunName, timeout, PipelineRunSucceed(bucketTestPipelineRunName), "PipelineRunCompleted", v1beta1Version); err != nil { - t.Errorf("Error waiting for PipelineRun %s to finish: %s", bucketTestPipelineRunName, err) - t.Fatalf("PipelineRun execution failed") - } -} - -// updateConfigMap updates the config map for specified @name with values. We can't use the one from knativetest because -// it assumes that Data is already a non-nil map, and by default, it isn't! -func updateConfigMap(ctx context.Context, client kubernetes.Interface, name string, configName string, values map[string]string) error { - configMap, err := client.CoreV1().ConfigMaps(name).Get(ctx, configName, metav1.GetOptions{}) - if err != nil { - return err - } - - if configMap.Data == nil { - configMap.Data = make(map[string]string) - } - - for key, value := range values { - configMap.Data[key] = value - } - - _, err = client.CoreV1().ConfigMaps(name).Update(ctx, configMap, metav1.UpdateOptions{}) - return err -} - -func getBucketSecret(t *testing.T, configFilePath, namespace string) *corev1.Secret { - t.Helper() - f, err := os.ReadFile(configFilePath) - if err != nil { - t.Fatalf("Failed to read json key file %s at path %s", err, configFilePath) - } - return &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: bucketSecretName, - }, - StringData: map[string]string{ - bucketSecretKey: string(f), - }, - } -} - -func deleteBucketSecret(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - if err := c.KubeClient.CoreV1().Secrets(namespace).Delete(ctx, bucketSecretName, metav1.DeleteOptions{}); err != nil { - t.Fatalf("Failed to delete Secret `%s`: %s", bucketSecretName, err) - } -} - -func resetConfigMap(ctx context.Context, t *testing.T, c *clients, namespace, configName string, values map[string]string) { - t.Helper() - if err := updateConfigMap(ctx, c.KubeClient, namespace, configName, values); err != nil { - t.Log(err) - } -} - -func runTaskToDeleteBucket(ctx context.Context, t *testing.T, c *clients, namespace, bucketName, bucketSecretName, bucketSecretKey string) { - t.Helper() - deletelbuckettask := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - steps: - - args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil rm -r gs://%s'] - command: ['/bin/bash'] - env: - - name: CREDENTIALS - value: /var/secret/%s/%s - image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine - name: step1 - resources: {} - volumeMounts: - - mountPath: /var/secret/%s - name: bucket-secret-volume - volumes: - - name: bucket-secret-volume - secret: - secretName: %s -`, helpers.ObjectNameForTest(t), namespace, bucketName, bucketSecretName, bucketSecretKey, bucketSecretName, bucketSecretName)) - - t.Logf("Creating Task %s", deletelbuckettask.Name) - if _, err := c.V1beta1TaskClient.Create(ctx, deletelbuckettask, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", deletelbuckettask.Name, err) - } - - deletelbuckettaskrun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - taskRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, deletelbuckettask.Name)) - - t.Logf("Creating TaskRun %s", deletelbuckettaskrun.Name) - if _, err := c.V1beta1TaskRunClient.Create(ctx, deletelbuckettaskrun, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", deletelbuckettaskrun.Name, err) - } - - if err := WaitForTaskRunState(ctx, c, deletelbuckettaskrun.Name, TaskRunSucceed(deletelbuckettaskrun.Name), "TaskRunSuccess", v1beta1Version); err != nil { - t.Errorf("Error waiting for TaskRun %s to finish: %s", deletelbuckettaskrun.Name, err) - } -} diff --git a/test/controller.go b/test/controller.go index 32e09b34446..a5f8a612beb 100644 --- a/test/controller.go +++ b/test/controller.go @@ -354,7 +354,7 @@ func PrependResourceVersionReactor(f *ktesting.Fake) { // EnsureConfigurationConfigMapsExist makes sure all the configmaps exists. func EnsureConfigurationConfigMapsExist(d *Data) { - var defaultsExists, featureFlagsExists, artifactBucketExists, artifactPVCExists, metricsExists, trustedresourcesExists, spireconfigExists bool + var defaultsExists, featureFlagsExists, metricsExists, trustedresourcesExists, spireconfigExists bool for _, cm := range d.ConfigMaps { if cm.Name == config.GetDefaultsConfigName() { defaultsExists = true @@ -362,12 +362,6 @@ func EnsureConfigurationConfigMapsExist(d *Data) { if cm.Name == config.GetFeatureFlagsConfigName() { featureFlagsExists = true } - if cm.Name == config.GetArtifactBucketConfigName() { - artifactBucketExists = true - } - if cm.Name == config.GetArtifactPVCConfigName() { - artifactPVCExists = true - } if cm.Name == config.GetMetricsConfigName() { metricsExists = true } @@ -390,18 +384,6 @@ func EnsureConfigurationConfigMapsExist(d *Data) { Data: map[string]string{}, }) } - if !artifactBucketExists { - d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.Namespace()}, - Data: map[string]string{}, - }) - } - if !artifactPVCExists { - d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.Namespace()}, - Data: map[string]string{}, - }) - } if !metricsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{Name: config.GetMetricsConfigName(), Namespace: system.Namespace()}, diff --git a/test/controller_test.go b/test/controller_test.go index 63ce5d8b45f..92c245382b6 100644 --- a/test/controller_test.go +++ b/test/controller_test.go @@ -141,14 +141,6 @@ func TestEnsureConfigurationConfigMapsExist(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) - expected.ConfigMaps = append(expected.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.Namespace()}, - Data: map[string]string{}, - }) - expected.ConfigMaps = append(expected.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.Namespace()}, - Data: map[string]string{}, - }) expected.ConfigMaps = append(expected.ConfigMaps, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{Name: config.GetMetricsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, diff --git a/test/conversion_test.go b/test/conversion_test.go index dc92ab4a86b..afd7530c8f6 100644 --- a/test/conversion_test.go +++ b/test/conversion_test.go @@ -153,26 +153,12 @@ spec: mountPath: /foo readOnly: true optional: true - resources: - inputs: - - name: git-repo - type: git - description: "The input is code from a git repository" - optional: true - outputs: - - name: optionalimage - type: image - description: "The output is a Docker image" - optional: true ` v1TaskYaml = ` metadata: name: %s namespace: %s - annotations: { - tekton.dev/v1beta1Resources: '{"inputs":[{"name":"git-repo","type":"git","description":"The input is code from a git repository","optional":true}],"outputs":[{"name":"optionalimage","type":"image","description":"The output is a Docker image","optional":true}]}' - } spec: steps: - name: step @@ -309,18 +295,12 @@ spec: then echo " Good night! echoed successfully" fi - resources: - - name: source-repo - type: git ` v1PipelineYaml = ` metadata: name: %s namespace: %s - annotations: { - tekton.dev/v1beta1Resources: '[{"name":"source-repo","type":"git"}]' - } spec: description: foo tasks: @@ -382,13 +362,6 @@ spec: type: string serviceAccountName: default taskSpec: - resources: - inputs: - - name: skaffold - type: git - outputs: - - name: skaffoldout - type: git steps: - name: echo image: ubuntu @@ -404,25 +377,6 @@ spec: podTemplate: securityContext: fsGroup: 65532 - resources: - inputs: - - name: skaffold - resourceSpec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold - outputs: - - name: skaffoldout - resourceSpec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ` v1beta1TaskRunExpectedYaml = ` @@ -511,10 +465,7 @@ spec: metadata: name: %s namespace: %s - annotations: { - tekton.dev/v1beta1Resources: '{"inputs":[{"name":"skaffold","resourceSpec":{"type":"git","params":[{"name":"revision","value":"v0.32.0"},{"name":"url","value":"https://github.com/GoogleContainerTools/skaffold"}]}}],"outputs":[{"name":"skaffoldout","resourceSpec":{"type":"git","params":[{"name":"revision","value":"v0.32.0"},{"name":"url","value":"https://github.com/GoogleContainerTools/skaffold"}]}}]}', - tekton.dev/v1beta1ResourcesResult: '[{"key":"commit","value":"6ed7aad5e8a36052ee5f6079fc91368e362121f7","resourceName":"skaffold"},{"key":"url","value":"https://github.com/GoogleContainerTools/skaffold","resourceName":"skaffold"}]', - } + annotations: {} spec: params: - name: STRING_LENGTH @@ -555,14 +506,6 @@ status: workspaces: - name: output steps: - - container: step-create-dir-skaffoldout - name: create-dir-skaffoldout - terminated: - reason: Completed - - container: git-source-skaffold - name: git-source-skaffold - terminated: - reason: Completed - container: step-echo name: step-echo terminated: @@ -592,18 +535,6 @@ spec: - name: fetch-and-write-secure image: ubuntu script: echo hello - resources: - - name: pipeline-git - type: git - resources: - - name: pipeline-git - resourceSpec: - type: git - params: - - name: revision - value: main - - name: url - value: https://github.com/tektoncd/pipeline ` v1beta1PipelineRunExpectedYaml = ` @@ -683,9 +614,6 @@ spec: metadata: name: %s namespace: %s - annotations: { - tekton.dev/v1beta1Resources: '[{"name":"pipeline-git","resourceSpec":{"type":"git","params":[{"name":"revision","value":"main"},{"name":"url","value":"https://github.com/tektoncd/pipeline"}]}}]', - } spec: params: - name: STRING_LENGTH diff --git a/test/custom_task_test.go b/test/custom_task_test.go index d00b3a27229..7f00bb80a47 100644 --- a/test/custom_task_test.go +++ b/test/custom_task_test.go @@ -40,6 +40,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/kubernetes" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" v1 "knative.dev/pkg/apis/duck/v1" @@ -1204,3 +1205,30 @@ func tearDownV1Beta1CustomTask(ctx context.Context, t *testing.T, c *clients, na tearDown(ctx, t, c, namespace) } + +// updateConfigMap updates the config map for specified @name with values. We can't use the one from knativetest because +// it assumes that Data is already a non-nil map, and by default, it isn't! +func updateConfigMap(ctx context.Context, client kubernetes.Interface, name string, configName string, values map[string]string) error { + configMap, err := client.CoreV1().ConfigMaps(name).Get(ctx, configName, metav1.GetOptions{}) + if err != nil { + return err + } + + if configMap.Data == nil { + configMap.Data = make(map[string]string) + } + + for key, value := range values { + configMap.Data[key] = value + } + + _, err = client.CoreV1().ConfigMaps(name).Update(ctx, configMap, metav1.UpdateOptions{}) + return err +} + +func resetConfigMap(ctx context.Context, t *testing.T, c *clients, namespace, configName string, values map[string]string) { + t.Helper() + if err := updateConfigMap(ctx, c.KubeClient, namespace, configName, values); err != nil { + t.Log(err) + } +} diff --git a/test/dag_test.go b/test/dag_test.go index 731e41a3e05..86561a30a79 100644 --- a/test/dag_test.go +++ b/test/dag_test.go @@ -64,13 +64,6 @@ metadata: name: %s namespace: %s spec: - resources: - inputs: - - name: repo - type: git - outputs: - - name: repo - type: git params: - name: text type: string @@ -82,27 +75,11 @@ spec: # Sleep for N seconds so that we can check that tasks that # should be run in parallel have overlap. script: 'sleep %d' - - image: busybox - script: 'ln -s $(resources.inputs.repo.path) $(resources.outputs.repo.path)' `, helpers.ObjectNameForTest(t), namespace, int(sleepDuration.Seconds()))) if _, err := c.V1beta1TaskClient.Create(ctx, echoTask, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create echo Task: %s", err) } - // Create the repo PipelineResource (doesn't really matter which repo we use) - repoResource := parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: git - params: - - name: Url - value: https://github.com/githubtraining/example-basic -`, helpers.ObjectNameForTest(t))) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, repoResource, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create simple repo PipelineResource: %s", err) - } - // Intentionally declaring Tasks in a mixed up order to ensure the order // of execution isn't at all dependent on the order they are declared in pipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` @@ -110,82 +87,44 @@ metadata: name: %s namespace: %s spec: - resources: - - name: repo - type: git tasks: - name: pipeline-task-3 params: - name: text value: wow - resources: - inputs: - - from: - - pipeline-task-2-parallel-1 - - pipeline-task-2-parallel-2 - name: repo - resource: repo - outputs: - - name: repo - resource: repo taskRef: name: %s + runAfter: + - pipeline-task-2-parallel-1 + - pipeline-task-2-parallel-2 - name: pipeline-task-2-parallel-2 params: - name: text value: such parallel - resources: - inputs: - - from: - - pipeline-task-1 - name: repo - resource: repo - outputs: - - name: repo - resource: repo taskRef: name: %s + runAfter: + - pipeline-task-1 - name: pipeline-task-4 params: - name: text value: very cloud native - resources: - inputs: - - name: repo - resource: repo - outputs: - - name: repo - resource: repo - runAfter: - - pipeline-task-3 taskRef: name: %s + runAfter: + - pipeline-task-3 - name: pipeline-task-2-parallel-1 params: - name: text value: much graph - resources: - inputs: - - from: - - pipeline-task-1 - name: repo - resource: repo - outputs: - - name: repo - resource: repo taskRef: name: %s + runAfter: + - pipeline-task-1 - name: pipeline-task-1 params: - name: text value: how to ci/cd? - resources: - inputs: - - name: repo - resource: repo - outputs: - - name: repo - resource: repo taskRef: name: %s `, helpers.ObjectNameForTest(t), namespace, echoTask.Name, echoTask.Name, echoTask.Name, echoTask.Name, echoTask.Name)) @@ -199,11 +138,7 @@ metadata: spec: pipelineRef: name: %s - resources: - - name: repo - resourceRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, pipeline.Name, repoResource.Name)) +`, helpers.ObjectNameForTest(t), namespace, pipeline.Name)) if _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create dag-pipeline-run PipelineRun: %s", err) } diff --git a/test/embed_test.go b/test/embed_test.go deleted file mode 100644 index 24d9dc8cf44..00000000000 --- a/test/embed_test.go +++ /dev/null @@ -1,115 +0,0 @@ -//go:build e2e -// +build e2e - -/* -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 test - -import ( - "context" - "fmt" - "strings" - "testing" - - "github.com/tektoncd/pipeline/test/parse" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -const ( - // TODO(#127) Currently not reliable to retrieve this output - taskOutput = "do you want to build a snowman" -) - -// TestTaskRun_EmbeddedResource is an integration test that will verify a very simple "hello world" TaskRun can be -// executed with an embedded resource spec. -func TestTaskRun_EmbeddedResource(t *testing.T) { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setup(ctx, t) - t.Parallel() - - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - embedTaskName := helpers.ObjectNameForTest(t) - embedTaskRunName := helpers.ObjectNameForTest(t) - - t.Logf("Creating Task and TaskRun in namespace %s", namespace) - if _, err := c.V1beta1TaskClient.Create(ctx, getEmbeddedTask(t, embedTaskName, namespace, []string{"/bin/sh", "-c", fmt.Sprintf("echo %s", taskOutput)}), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", embedTaskName, err) - } - if _, err := c.V1beta1TaskRunClient.Create(ctx, getEmbeddedTaskRun(t, embedTaskRunName, namespace, embedTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", embedTaskRunName, err) - } - - t.Logf("Waiting for TaskRun %s in namespace %s to complete", embedTaskRunName, namespace) - if err := WaitForTaskRunState(ctx, c, embedTaskRunName, TaskRunSucceed(embedTaskRunName), "TaskRunSuccess", v1beta1Version); err != nil { - t.Errorf("Error waiting for TaskRun %s to finish: %s", embedTaskRunName, err) - } - - // TODO(#127) Currently we have no reliable access to logs from the TaskRun so we'll assume successful - // completion of the TaskRun means the TaskRun did what it was intended. -} - -func getEmbeddedTask(t *testing.T, taskName, namespace string, args []string) *v1beta1.Task { - t.Helper() - var argsForYaml []string - for _, s := range args { - argsForYaml = append(argsForYaml, fmt.Sprintf("'%s'", s)) - } - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: docs - type: git - steps: - - image: ubuntu - command: ['/bin/bash'] - args: ['-c', 'cat /workspace/docs/LICENSE'] - - image: busybox - command: %s -`, taskName, namespace, fmt.Sprintf("[%s]", strings.Join(argsForYaml, ", ")))) -} - -func getEmbeddedTaskRun(t *testing.T, trName, namespace, taskName string) *v1beta1.TaskRun { - t.Helper() - return parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: docs - resourceSpec: - type: git - params: - - name: URL - value: https://github.com/knative/docs - taskRef: - name: %s -`, trName, namespace, taskName)) -} diff --git a/test/git_checkout_test.go b/test/git_checkout_test.go deleted file mode 100644 index 97cbf029d8a..00000000000 --- a/test/git_checkout_test.go +++ /dev/null @@ -1,278 +0,0 @@ -//go:build e2e -// +build e2e - -/* -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 test - -import ( - "context" - "fmt" - "strings" - "testing" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/test/parse" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -// TestGitPipelineRun is an integration test that will verify the source code -// is either fetched or pulled successfully under different resource -// parameters. -func TestGitPipelineRun(t *testing.T) { - skipIfExcluded(t) - - for _, tc := range []struct { - name string - repo string - revision string - refspec string - sslVerify string - }{{ - name: "tekton @ main", - repo: "https://github.com/tektoncd/pipeline", - revision: "main", - }, { - name: "tekton @ commit", - repo: "https://github.com/tektoncd/pipeline", - revision: "c15aced0e5aaee6456fbe6f7a7e95e0b5b3b2b2f", - }, { - name: "tekton @ release", - repo: "https://github.com/tektoncd/pipeline", - revision: "release-0.1", - }, { - name: "tekton @ tag", - repo: "https://github.com/tektoncd/pipeline", - revision: "v0.1.0", - }, { - name: "tekton @ PR ref", - repo: "https://github.com/tektoncd/pipeline", - revision: "refs/pull/347/head", - }, { - name: "tekton @ main with refspec", - repo: "https://github.com/tektoncd/pipeline", - revision: "main", - refspec: "refs/tags/v0.1.0:refs/tags/v0.1.0 refs/heads/main:refs/heads/main", - }, { - name: "tekton @ commit with PR refspec", - repo: "https://github.com/tektoncd/pipeline", - revision: "968d5d37a61bfb85426c885dc1090c1cc4b33436", - refspec: "refs/pull/1009/head", - }, { - name: "tekton @ main with PR refspec", - repo: "https://github.com/tektoncd/pipeline", - revision: "main", - refspec: "refs/pull/1009/head:refs/heads/main", - }, { - name: "tekton @ main with sslverify=false", - repo: "https://github.com/tektoncd/pipeline", - revision: "main", - sslVerify: "false", - }, { - name: "non-master repo with default revision", - repo: "https://github.com/tektoncd/results", - revision: "", - }, { - name: "non-master repo with main revision", - repo: "https://github.com/tektoncd/results", - revision: "main", - }} { - tc := tc // capture range variable - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setup(ctx, t) - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - gitSourceResourceName := helpers.ObjectNameForTest(t) - gitTestPipelineRunName := helpers.ObjectNameForTest(t) - - t.Logf("Creating Git PipelineResource %s", gitSourceResourceName) - // Still using the struct here rather than YAML because we'd have to conditionally determine which fields to set in the YAML. - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{Name: gitSourceResourceName}, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{ - {Name: "Url", Value: tc.repo}, - {Name: "Revision", Value: tc.revision}, - {Name: "Refspec", Value: tc.refspec}, - {Name: "sslVerify", Value: tc.sslVerify}, - }, - }, - }, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", gitSourceResourceName, err) - } - - t.Logf("Creating PipelineRun %s", gitTestPipelineRunName) - if _, err := c.V1beta1PipelineRunClient.Create(ctx, parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: %s -spec: - pipelineSpec: - resources: - - name: git-repo - type: git - tasks: - - name: git-check - resources: - inputs: - - name: gitsource - resource: git-repo - taskSpec: - resources: - inputs: - - name: gitsource - type: git - steps: - - args: ['--git-dir=/workspace/gitsource/.git', 'show'] - image: alpine/git - resources: - - name: git-repo - resourceRef: - name: %s -`, gitTestPipelineRunName, gitSourceResourceName)), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create PipelineRun %q: %s", gitTestPipelineRunName, err) - } - - if err := WaitForPipelineRunState(ctx, c, gitTestPipelineRunName, timeout, PipelineRunSucceed(gitTestPipelineRunName), "PipelineRunCompleted", v1beta1Version); err != nil { - t.Errorf("Error waiting for PipelineRun %s to finish: %s", gitTestPipelineRunName, err) - t.Fatalf("PipelineRun execution failed") - } - }) - } -} - -// TestGitPipelineRunFail is a test to ensure that the code extraction from -// github fails as expected when an invalid revision or https proxy is passed -// on the pipelineresource. -func TestGitPipelineRunFail(t *testing.T) { - for _, tc := range []struct { - name string - revision string - httpsproxy string - }{{ - name: "invalid revision", - revision: "Idontexistrabbitmonkeydonkey", - }, { - name: "invalid httpsproxy", - httpsproxy: "invalid.https.proxy.example.com", - }} { - tc := tc // capture range variable - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setup(ctx, t) - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - gitSourceResourceName := helpers.ObjectNameForTest(t) - gitTestPipelineRunName := helpers.ObjectNameForTest(t) - - t.Logf("Creating Git PipelineResource %s", gitSourceResourceName) - // Still using the struct here rather than YAML because we'd have to conditionally determine which fields to set in the YAML. - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{Name: gitSourceResourceName}, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{ - {Name: "Url", Value: "https://github.com/tektoncd/pipeline"}, - {Name: "Revision", Value: tc.revision}, - {Name: "httpsProxy", Value: tc.httpsproxy}, - }, - }, - }, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", gitSourceResourceName, err) - } - - t.Logf("Creating PipelineRun %s", gitTestPipelineRunName) - if _, err := c.V1beta1PipelineRunClient.Create(ctx, parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: %s -spec: - pipelineSpec: - resources: - - name: git-repo - type: git - tasks: - - name: git-check - resources: - inputs: - - name: gitsource - resource: git-repo - taskSpec: - resources: - inputs: - - name: gitsource - type: git - steps: - - args: ['--git-dir=/workspace/gitsource/.git', 'show'] - image: alpine/git - resources: - - name: git-repo - resourceRef: - name: %s -`, gitTestPipelineRunName, gitSourceResourceName)), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create PipelineRun %q: %s", gitTestPipelineRunName, err) - } - - if err := WaitForPipelineRunState(ctx, c, gitTestPipelineRunName, timeout, PipelineRunSucceed(gitTestPipelineRunName), "PipelineRunCompleted", v1beta1Version); err != nil { - taskruns, err := c.V1beta1TaskRunClient.List(ctx, metav1.ListOptions{}) - if err != nil { - t.Errorf("Error getting TaskRun list for PipelineRun %s %s", gitTestPipelineRunName, err) - } - for _, tr := range taskruns.Items { - if tr.Status.PodName != "" { - p, err := c.KubeClient.CoreV1().Pods(namespace).Get(ctx, tr.Status.PodName, metav1.GetOptions{}) - if err != nil { - t.Fatalf("Error getting pod `%s` in namespace `%s`", tr.Status.PodName, namespace) - } - - for _, stat := range p.Status.ContainerStatuses { - if strings.HasPrefix(stat.Name, "step-git-source-"+gitSourceResourceName) { - if stat.State.Terminated != nil { - req := c.KubeClient.CoreV1().Pods(namespace).GetLogs(p.Name, &corev1.PodLogOptions{Container: stat.Name}) - logContent, err := req.Do(ctx).Raw() - if err != nil { - t.Fatalf("Error getting pod logs for pod `%s` and container `%s` in namespace `%s`", tr.Status.PodName, stat.Name, namespace) - } - // Check for failure messages from fetch and pull in the log file - if strings.Contains(strings.ToLower(string(logContent)), "couldn't find remote ref idontexistrabbitmonkeydonkey") { - t.Logf("Found exepected errors when retrieving non-existent git revision") - } else { - t.Logf("Container `%s` log File: %s", stat.Name, logContent) - t.Fatalf("The git code extraction did not fail as expected. Expected errors not found in log file.") - } - } - } - } - } - } - } else { - t.Fatal("PipelineRun succeeded when should have failed") - } - }) - } -} diff --git a/test/helm_task_test.go b/test/helm_task_test.go deleted file mode 100644 index 2c13fee478b..00000000000 --- a/test/helm_task_test.go +++ /dev/null @@ -1,371 +0,0 @@ -//go:build e2e -// +build e2e - -/* -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 test - -import ( - "context" - "fmt" - "testing" - - "github.com/tektoncd/pipeline/test/parse" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/names" - rbacv1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -var clusterRoleBindings [1]*rbacv1.ClusterRoleBinding - -// TestHelmDeployPipelineRun is an integration test that will verify a pipeline build an image -// and then using helm to deploy it -func TestHelmDeployPipelineRun(t *testing.T) { - repo := ensureDockerRepo(t) - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setup(ctx, t) - setupClusterBindingForHelm(ctx, t, c, namespace) - - var ( - sourceResourceName = helpers.ObjectNameForTest(t) - sourceImageName = helpers.ObjectNameForTest(t) - createImageTaskName = helpers.ObjectNameForTest(t) - helmDeployTaskName = helpers.ObjectNameForTest(t) - checkServiceTaskName = helpers.ObjectNameForTest(t) - helmDeployPipelineName = helpers.ObjectNameForTest(t) - helmDeployPipelineRunName = helpers.ObjectNameForTest(t) - ) - - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - t.Logf("Creating Git PipelineResource %s", sourceResourceName) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, getGoHelloworldGitResource(t, sourceResourceName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", sourceResourceName, err) - } - - t.Logf("Creating Image PipelineResource %s", sourceImageName) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, getHelmImageResource(t, repo, sourceImageName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", sourceImageName, err) - } - - t.Logf("Creating Task %s", createImageTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, getCreateImageTask(t, namespace, createImageTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", createImageTaskName, err) - } - - t.Logf("Creating Task %s", helmDeployTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, getHelmDeployTask(t, namespace, helmDeployTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", helmDeployTaskName, err) - } - - t.Logf("Creating Task %s", checkServiceTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, getCheckServiceTask(t, namespace, checkServiceTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", checkServiceTaskName, err) - } - - t.Logf("Creating Pipeline %s", helmDeployPipelineName) - if _, err := c.V1beta1PipelineClient.Create(ctx, getHelmDeployPipeline(t, namespace, createImageTaskName, helmDeployTaskName, checkServiceTaskName, helmDeployPipelineName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", helmDeployPipelineName, err) - } - - t.Logf("Creating PipelineRun %s", helmDeployPipelineRunName) - if _, err := c.V1beta1PipelineRunClient.Create(ctx, getHelmDeployPipelineRun(t, namespace, sourceResourceName, sourceImageName, helmDeployPipelineRunName, helmDeployPipelineName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", helmDeployPipelineRunName, err) - } - - // Verify status of PipelineRun (wait for it) - if err := WaitForPipelineRunState(ctx, c, helmDeployPipelineRunName, timeout, PipelineRunSucceed(helmDeployPipelineRunName), "PipelineRunCompleted", v1beta1Version); err != nil { - t.Errorf("Error waiting for PipelineRun %s to finish: %s", helmDeployPipelineRunName, err) - t.Fatalf("PipelineRun execution failed; helm may or may not have been installed :(") - } - - // cleanup task to remove helm releases from cluster and cluster role bindings, will not fail the test if it fails, just log - knativetest.CleanupOnInterrupt(func() { helmCleanup(ctx, t, c, namespace) }, t.Logf) - defer helmCleanup(ctx, t, c, namespace) -} - -func getGoHelloworldGitResource(t *testing.T, sourceResourceName string) *v1alpha1.PipelineResource { - t.Helper() - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline -`, sourceResourceName)) -} - -func getHelmImageResource(t *testing.T, dockerRepo, sourceImageName string) *v1alpha1.PipelineResource { - t.Helper() - imageName := fmt.Sprintf("%s/%s", dockerRepo, names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(sourceImageName)) - - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: image - params: - - name: url - value: %s -`, sourceImageName, imageName)) -} - -func getCreateImageTask(t *testing.T, namespace, createImageTaskName string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: gitsource - type: git - outputs: - - name: builtimage - type: image - steps: - - name: kaniko - image: %s - args: ['--dockerfile=/workspace/gitsource/test/gohelloworld/Dockerfile', - '--context=/workspace/gitsource/', - '--destination=$(outputs.resources.builtimage.url)'] -`, createImageTaskName, namespace, getTestImage(kanikoImage))) -} - -func getHelmDeployTask(t *testing.T, namespace, helmDeployTaskName string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: gitsource - type: git - - name: image - type: image - params: - - name: pathToHelmCharts - type: string - description: 'Path to the helm charts' - - name: chartname - type: string - default: "" - steps: - - image: alpine/helm:3.5.4 - args: ['upgrade', - '--wait', - '--debug', - '--install', - '--namespace', - '%s', - '$(inputs.params.chartname)', - '$(inputs.params.pathToHelmCharts)', - '--set', - 'image.repository=$(inputs.resources.image.url)', - '--set', - 'service.type=ClusterIP'] - - image: lachlanevenson/k8s-kubectl - command: ['kubectl'] - args: ['get', - 'all', - '--namespace', - '%s'] -`, helmDeployTaskName, namespace, namespace, namespace)) -} - -func getCheckServiceTask(t *testing.T, namespace, checkServiceTaskName string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - params: - - name: serviceUrl - type: string - description: 'Service url' - steps: - - image: %s - args: ['-wait', '$(inputs.params.serviceUrl)', '-timeout', '1m'] -`, checkServiceTaskName, namespace, getTestImage(dockerizeImage))) -} - -func getHelmDeployPipeline(t *testing.T, namespace, createImageTaskName, helmDeployTaskName, checkServiceTaskName, helmDeployPipelineName string) *v1beta1.Pipeline { - t.Helper() - return parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - params: - - name: chartname - type: string - resources: - - name: git-repo - type: git - - name: the-image - type: image - tasks: - - name: push-image - taskRef: - name: %s - resources: - inputs: - - name: gitsource - resource: git-repo - outputs: - - name: builtimage - resource: the-image - - name: helm-deploy - taskRef: - name: %s - resources: - inputs: - - name: gitsource - resource: git-repo - - name: image - resource: the-image - params: - - name: pathToHelmCharts - value: /workspace/gitsource/test/gohelloworld/gohelloworld-chart - - name: chartname - value: '$(params.chartname)' - - name: check-service - taskRef: - name: %s - params: - - name: serviceUrl - value: http://gohelloworld-chart:8080 - runAfter: ['helm-deploy'] -`, helmDeployPipelineName, namespace, createImageTaskName, helmDeployTaskName, checkServiceTaskName)) -} - -func getHelmDeployPipelineRun(t *testing.T, namespace, sourceResourceName, sourceImageName, helmDeployPipelineRunName, helmDeployPipelineName string) *v1beta1.PipelineRun { - t.Helper() - return parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - pipelineRef: - name: %s - params: - - name: chartname - value: gohelloworld - resources: - - name: git-repo - resourceRef: - name: %s - - name: the-image - resourceRef: - name: %s -`, helmDeployPipelineRunName, namespace, helmDeployPipelineName, sourceResourceName, sourceImageName)) -} - -func setupClusterBindingForHelm(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - clusterRoleBindings[0] = &rbacv1.ClusterRoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("default-tiller"), - }, - RoleRef: rbacv1.RoleRef{ - APIGroup: "rbac.authorization.k8s.io", - Kind: "ClusterRole", - Name: "cluster-admin", - }, - Subjects: []rbacv1.Subject{{ - Kind: "ServiceAccount", - Name: "default", - Namespace: namespace, - }}, - } - - for _, crb := range clusterRoleBindings { - t.Logf("Creating Cluster Role binding %s for helm", crb.Name) - if _, err := c.KubeClient.RbacV1().ClusterRoleBindings().Create(ctx, crb, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create cluster role binding for Helm %s", err) - } - } -} - -func helmCleanup(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - t.Logf("Cleaning up helm from cluster...") - - removeAllHelmReleases(ctx, t, c, namespace) - - for _, crb := range clusterRoleBindings { - t.Logf("Deleting Cluster Role binding %s for helm", crb.Name) - if err := c.KubeClient.RbacV1().ClusterRoleBindings().Delete(ctx, crb.Name, metav1.DeleteOptions{}); err != nil { - t.Fatalf("Failed to delete cluster role binding for Helm %s", err) - } - } -} - -func removeAllHelmReleases(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - helmRemoveAllTaskName := "helm-remove-all-task" - helmRemoveAllTask := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - steps: - - name: helm-remove-all - image: alpine/helm:3.5.4 - command: ['/bin/sh'] - args: ['-c', 'helm ls --short --all --namespace %s | xargs -n1 helm delete --namespace %s'] -`, helmRemoveAllTaskName, namespace, namespace, namespace)) - - helmRemoveAllTaskRunName := "helm-remove-all-taskrun" - helmRemoveAllTaskRun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - taskRef: - name: %s -`, helmRemoveAllTaskRunName, namespace, helmRemoveAllTaskName)) - - t.Logf("Creating Task %s", helmRemoveAllTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, helmRemoveAllTask, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", helmRemoveAllTaskName, err) - } - - t.Logf("Creating TaskRun %s", helmRemoveAllTaskRunName) - if _, err := c.V1beta1TaskRunClient.Create(ctx, helmRemoveAllTaskRun, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", helmRemoveAllTaskRunName, err) - } - - t.Logf("Waiting for TaskRun %s in namespace %s to complete", helmRemoveAllTaskRunName, namespace) - if err := WaitForTaskRunState(ctx, c, helmRemoveAllTaskRunName, TaskRunSucceed(helmRemoveAllTaskRunName), "TaskRunSuccess", v1beta1Version); err != nil { - t.Logf("TaskRun %s failed to finish: %s", helmRemoveAllTaskRunName, err) - } -} diff --git a/test/kaniko_task_test.go b/test/kaniko_task_test.go deleted file mode 100644 index 94e89fb638f..00000000000 --- a/test/kaniko_task_test.go +++ /dev/null @@ -1,256 +0,0 @@ -//go:build e2e -// +build e2e - -/* -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 test - -import ( - "context" - "fmt" - "strings" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/test/parse" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -const ( - // This is a random revision chosen on 2020/10/09 - revision = "a310cc6d1cd449f95cedd23393de766fdc649651" -) - -// TestTaskRun is an integration test that will verify a TaskRun using kaniko -func TestKanikoTaskRun(t *testing.T) { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - if skipRootUserTests { - t.Skip("Skip test as skipRootUserTests set to true") - } - - c, namespace := setup(ctx, t, withRegistry) - t.Parallel() - - repo := fmt.Sprintf("registry.%s:5000/kanikotasktest", namespace) - - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - git := getGitResource(t) - t.Logf("Creating Git PipelineResource %s", git.Name) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, git, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", git.Name, err) - } - - image := getImageResource(t, repo) - t.Logf("Creating Image PipelineResource %s", repo) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, image, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", git.Name, err) - } - - task := getTask(t, repo, namespace) - t.Logf("Creating Task %s", task.Name) - if _, err := c.V1beta1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", task.Name, err) - } - - tr := getTaskRun(t, namespace, task.Name, git.Name, image.Name) - t.Logf("Creating TaskRun %s", tr.Name) - if _, err := c.V1beta1TaskRunClient.Create(ctx, tr, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", tr.Name, err) - } - - // Verify status of TaskRun (wait for it) - - if err := WaitForTaskRunState(ctx, c, tr.Name, Succeed(tr.Name), "TaskRunCompleted", v1beta1Version); err != nil { - t.Errorf("Error waiting for TaskRun %s to finish: %s", tr.Name, err) - } - - tr, err := c.V1beta1TaskRunClient.Get(ctx, tr.Name, metav1.GetOptions{}) - if err != nil { - t.Errorf("Error retrieving taskrun: %s", err) - } - digest := "" - commit := "" - url := "" - for _, rr := range tr.Status.ResourcesResult { - switch rr.Key { - case "digest": - digest = rr.Value - case "commit": - commit = rr.Value - case "url": - url = rr.Value - } - // Every resource should have a resource name - if rr.ResourceName == "" { - t.Errorf("Resource ref not set for %v in TaskRun: %v", rr, tr) - } - } - if digest == "" { - t.Errorf("Digest not found in TaskRun.Status: %v", tr.Status) - } - if commit == "" { - t.Errorf("Commit not found in TaskRun.Status: %v", tr.Status) - } - if url == "" { - t.Errorf("Url not found in TaskRun.Status: %v", tr.Status) - } - - if revision != commit { - t.Fatalf("Expected remote commit to match local revision: %s, %s", commit, revision) - } - - // match the local digest, which is first capture group against the remote image - remoteDigest, err := getRemoteDigest(t, c, namespace, repo) - if err != nil { - t.Fatalf("Expected to get digest for remote image %s: %v", repo, err) - } - if d := cmp.Diff(digest, remoteDigest); d != "" { - t.Fatalf("Expected local digest %s to match remote digest %s: %s", digest, remoteDigest, d) - } -} - -func getGitResource(t *testing.T) *v1alpha1.PipelineResource { - t.Helper() - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: git - params: - - name: Url - value: https://github.com/GoogleContainerTools/kaniko - - name: Revision - value: %s -`, helpers.ObjectNameForTest(t), revision)) -} - -func getImageResource(t *testing.T, repo string) *v1alpha1.PipelineResource { - t.Helper() - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: image - params: - - name: url - value: %s -`, helpers.ObjectNameForTest(t), repo)) -} - -func getTask(t *testing.T, repo, namespace string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: gitsource - type: git - outputs: - - name: builtImage - type: image - steps: - - name: kaniko - image: %s - args: ['--dockerfile=/workspace/gitsource/integration/dockerfiles/Dockerfile_test_label', - '--destination=%s', - '--context=/workspace/gitsource', - '--oci-layout-path=/workspace/output/builtImage', - '--insecure', - '--insecure-pull', - '--insecure-registry=registry.%s:5000/'] - securityContext: - runAsUser: 0 - sidecars: - - name: registry - image: %s -`, helpers.ObjectNameForTest(t), namespace, getTestImage(kanikoImage), repo, namespace, getTestImage(registryImage))) -} - -func getTaskRun(t *testing.T, namespace, task, git, image string) *v1beta1.TaskRun { - t.Helper() - return parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - taskRef: - name: %s - timeout: 5m - resources: - inputs: - - name: gitsource - resourceRef: - name: %s - outputs: - - name: builtImage - resourceRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, task, git, image)) -} - -// getRemoteDigest starts a pod to query the registry from the namespace itself, using skopeo (and jq). -// The reason we have to do that is because the image is pushed on a local registry that is not exposed -// to the "outside" of the test, this means it can be query by the test itself. It can only be query from -// a pod in the namespace. skopeo is able to do that query and we use jq to extract the digest from its -// output. The image used for this pod is build in the tektoncd/plumbing repository. -func getRemoteDigest(t *testing.T, c *clients, namespace, image string) (string, error) { - t.Helper() - podName := "skopeo-jq" - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - if _, err := c.KubeClient.CoreV1().Pods(namespace).Create(ctx, &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: podName, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Name: "skopeo", - Image: "gcr.io/tekton-releases/dogfooding/skopeo:latest", - Command: []string{"/bin/sh", "-c"}, - Args: []string{"skopeo inspect --tls-verify=false docker://" + image + ":latest| jq '.Digest'"}, - }}, - RestartPolicy: corev1.RestartPolicyNever, - }, - }, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create the skopeo-jq pod: %v", err) - } - if err := WaitForPodState(ctx, c, podName, namespace, func(pod *corev1.Pod) (bool, error) { - return pod.Status.Phase == "Succeeded" || pod.Status.Phase == "Failed", nil - }, "PodContainersTerminated"); err != nil { - t.Fatalf("Error waiting for Pod %q to terminate: %v", podName, err) - } - logs, err := getContainerLogsFromPod(ctx, c.KubeClient, podName, "skopeo", namespace) - if err != nil { - t.Fatalf("Could not get logs for pod %s: %s", podName, err) - } - return strings.TrimSpace(strings.ReplaceAll(logs, "\"", "")), nil -} diff --git a/test/ko_test.go b/test/ko_test.go deleted file mode 100644 index 1a364ebb66d..00000000000 --- a/test/ko_test.go +++ /dev/null @@ -1,53 +0,0 @@ -//go:build e2e -// +build e2e - -/* -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 test - -import ( - "errors" - "fmt" - "os" - "testing" -) - -// missingKoFatal makes missing KO_DOCKER_REPO envvar fatal or optional -var missingKoFatal = "true" - -func ensureDockerRepo(t *testing.T) string { - t.Helper() - repo, err := getDockerRepo() - if err != nil { - if missingKoFatal == "false" { - t.Skip("KO_DOCKER_REPO env variable is required") - } - t.Fatal("KO_DOCKER_REPO env variable is required") - } - return repo -} - -func getDockerRepo() (string, error) { - // according to knative/test-infra readme (https://github.com/knative/test-infra/blob/13055d769cc5e1756e605fcb3bcc1c25376699f1/scripts/README.md) - // the KO_DOCKER_REPO will be set with according to the project where the cluster is created - // it is used here to dynamically get the docker registry to push the image to - dockerRepo := os.Getenv("KO_DOCKER_REPO") - if dockerRepo == "" { - return "", errors.New("KO_DOCKER_REPO env variable is required") - } - return fmt.Sprintf("%s/kanikotasktest", dockerRepo), nil -} diff --git a/test/pipelinerun_test.go b/test/pipelinerun_test.go index d12a3dc9b53..9ea855fe6ef 100644 --- a/test/pipelinerun_test.go +++ b/test/pipelinerun_test.go @@ -30,13 +30,10 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/artifacts" "github.com/tektoncd/pipeline/test/parse" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" k8sres "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" "knative.dev/pkg/apis" knativetest "knative.dev/pkg/test" @@ -186,35 +183,6 @@ func TestPipelineRun(t *testing.T) { } tds := []tests{{ - name: "fan-in and fan-out", - testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, _ int) (map[string]*v1alpha1.PipelineResource, *v1beta1.Pipeline) { - t.Helper() - tasks := getFanInFanOutTasks(t, namespace) - for _, task := range tasks { - if _, err := c.V1beta1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", task.Name, err) - } - } - - resources := getFanInFanOutGitResources(t) - for _, res := range resources { - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, res, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", res.Name, err) - } - } - - p := getFanInFanOutPipeline(t, namespace, tasks) - if _, err := c.V1beta1PipelineClient.Create(ctx, p, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", p.Name, err) - } - - return resources, p - }, - pipelineRunFunc: getFanInFanOutPipelineRun, - expectedTaskRuns: []string{"create-file-kritis", "create-fan-out-1", "create-fan-out-2", "check-fan-in"}, - // 1 from PipelineRun and 4 from Tasks defined in pipelinerun - expectedNumberOfEvents: 5, - }, { name: "service account propagation and pipeline param", testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) (map[string]*v1alpha1.PipelineResource, *v1beta1.Pipeline) { t.Helper() @@ -382,22 +350,6 @@ spec: t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of receieved events : %#v", td.expectedNumberOfEvents, len(events), collectedEvents) } - // Wait for up to 10 minutes and restart every second to check if - // the PersistentVolumeClaims has the DeletionTimestamp - if err := wait.PollImmediate(interval, timeout, func() (bool, error) { - // Check to make sure the PipelineRun's artifact storage PVC has been "deleted" at the end of the run. - pvc, errWait := c.KubeClient.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, artifacts.GetPVCName(pipelineRun), metav1.GetOptions{}) - if errWait != nil && !errors.IsNotFound(errWait) { - return true, fmt.Errorf("error looking up PVC %s for PipelineRun %s: %s", artifacts.GetPVCName(pipelineRun), prName, errWait) - } - // If we are not found then we are okay since it got cleaned up - if errors.IsNotFound(errWait) { - return true, nil - } - return pvc.DeletionTimestamp != nil, nil - }); err != nil { - t.Fatalf("Error while waiting for the PVC to be set as deleted: %s: %s: %s", artifacts.GetPVCName(pipelineRun), err, prName) - } t.Logf("Successfully finished test %q", td.name) }) } @@ -604,174 +556,6 @@ spec: } } -func getFanInFanOutTasks(t *testing.T, namespace string) map[string]*v1beta1.Task { - t.Helper() - return map[string]*v1beta1.Task{ - "create-file": parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: workspace - targetPath: brandnewspace - type: git - outputs: - - name: workspace - type: git - steps: - - args: ['-c', 'echo stuff > $(resources.outputs.workspace.path)/stuff'] - command: ['/bin/bash'] - image: ubuntu - name: write-data-task-0-step-0 - - args: ['-c', 'echo other > $(resources.outputs.workspace.path)/other'] - command: ['/bin/bash'] - image: ubuntu - name: write-data-task-0-step-1 -`, helpers.ObjectNameForTest(t), namespace)), - "check-create-files-exists": parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: workspace - type: git - outputs: - - name: workspace - type: git - steps: - - args: ['-c', '[[ stuff == $(cat $(inputs.resources.workspace.path)/stuff) ]]'] - command: ['/bin/bash'] - image: ubuntu - name: read-from-task-0 - - args: ['-c', 'echo something > $(outputs.resources.workspace.path)/something'] - command: ['/bin/bash'] - image: ubuntu - name: write-data-task-1 -`, helpers.ObjectNameForTest(t), namespace)), - "check-create-files-exists-2": parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: workspace - type: git - outputs: - - name: workspace - type: git - steps: - - args: ['-c', '[[ other == $(cat $(inputs.resources.workspace.path)/other) ]]'] - command: ['/bin/bash'] - image: ubuntu - name: read-from-task-0 - - args: ['-c', 'echo else > $(outputs.resources.workspace.path)/else'] - command: ['/bin/bash'] - image: ubuntu - name: write-data-task-1 -`, helpers.ObjectNameForTest(t), namespace)), - "read-files": parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: workspace - type: git - targetPath: readingspace - steps: - - args: ['-c', '[[ something == $(cat $(inputs.resources.workspace.path)/something) ]]'] - command: ['/bin/bash'] - image: ubuntu - name: read-from-task-0 - - args: ['-c', '[[ else == $(cat $(inputs.resources.workspace.path)/else) ]]'] - command: ['/bin/bash'] - image: ubuntu - name: read-from-task-1 -`, helpers.ObjectNameForTest(t), namespace)), - } -} - -func getFanInFanOutPipeline(t *testing.T, namespace string, tasks map[string]*v1beta1.Task) *v1beta1.Pipeline { - t.Helper() - return parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - - name: git-repo - type: git - tasks: - - name: create-file-kritis - resources: - inputs: - - name: workspace - resource: git-repo - outputs: - - name: workspace - resource: git-repo - taskRef: - name: %s - - name: create-fan-out-1 - resources: - inputs: - - from: - - create-file-kritis - name: workspace - resource: git-repo - outputs: - - name: workspace - resource: git-repo - taskRef: - name: %s - - name: create-fan-out-2 - resources: - inputs: - - from: - - create-file-kritis - name: workspace - resource: git-repo - outputs: - - name: workspace - resource: git-repo - taskRef: - name: %s - - name: check-fan-in - resources: - inputs: - - from: - - create-fan-out-2 - - create-fan-out-1 - name: workspace - resource: git-repo - taskRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, tasks["create-file"].Name, tasks["check-create-files-exists"].Name, - tasks["check-create-files-exists-2"].Name, tasks["read-files"].Name)) -} - -func getFanInFanOutGitResources(t *testing.T) map[string]*v1alpha1.PipelineResource { - t.Helper() - return map[string]*v1alpha1.PipelineResource{ - "kritis-resource-git": parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: git - params: - - name: Url - value: https://github.com/grafeas/kritis - - name: Revision - value: master -`, helpers.ObjectNameForTest(t)))} -} - func getPipelineRunServiceAccount(suffix int, namespace string) *corev1.ServiceAccount { return &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ @@ -783,21 +567,6 @@ func getPipelineRunServiceAccount(suffix int, namespace string) *corev1.ServiceA }}, } } -func getFanInFanOutPipelineRun(t *testing.T, _ int, namespace string, pipelineName string, resources map[string]*v1alpha1.PipelineResource) *v1beta1.PipelineRun { - t.Helper() - return parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - pipelineRef: - name: %s - resources: - - name: git-repo - resourceRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, pipelineName, resources["kritis-resource-git"].Name)) -} func getPipelineRunSecret(suffix int, namespace string) *corev1.Secret { // Generated by: diff --git a/test/resolvers_test.go b/test/resolvers_test.go index d92cea9e7fc..122b67dfa45 100644 --- a/test/resolvers_test.go +++ b/test/resolvers_test.go @@ -55,6 +55,7 @@ const ( scmRemoteUserPassword = "ab_d1234HIJKL" // Defined in git-resolver/gitea.yaml's "gitea" StatefulSet, in the env for the "configure-gitea" init container scmGiteaAdminPassword = "giteaPassword1234" + systemNamespace = "tekton-pipelines" ) var (