From ac7af5522970da93d43f4cd29417818087b21c7b Mon Sep 17 00:00:00 2001 From: Jerome Ju Date: Tue, 14 Feb 2023 20:31:19 +0000 Subject: [PATCH 1/2] Remove Git, Storage and Generic 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 It also removes the generic pipelineResources including: - input and output resources - from type - pipelineResourceRef --- cmd/controller/main.go | 2 - cmd/webhook/main.go | 2 - config/300-resource.yaml | 52 - config/config-artifact-bucket.yaml | 33 - config/config-artifact-pvc.yaml | 28 - config/controller.yaml | 4 - docs/additional-configs.md | 123 -- docs/pipeline-api.md | 1161 +----------- docs/pipelineruns.md | 5 +- docs/resources.md | 523 ------ docs/taskruns.md | 49 - docs/variables.md | 37 - .../pipelineruns/output-pipelinerun.yaml | 106 -- .../pipelinerun-with-resourcespec.yaml | 65 - examples/v1beta1/taskruns/gcs-resource.yaml | 26 - examples/v1beta1/taskruns/git-resource.yaml | 80 - hack/update-codegen.sh | 19 - hack/update-openapigen.sh | 2 +- 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 - pkg/apis/pipeline/images.go | 6 - pkg/apis/pipeline/images_test.go | 6 +- pkg/apis/pipeline/v1/param_types.go | 5 - .../pipeline/v1beta1/openapi_generated.go | 1030 +--------- pkg/apis/pipeline/v1beta1/param_types.go | 5 - .../pipeline/v1beta1/pipeline_conversion.go | 27 - .../v1beta1/pipeline_conversion_test.go | 68 - pkg/apis/pipeline/v1beta1/pipeline_types.go | 78 - .../pipeline/v1beta1/pipeline_types_test.go | 213 --- .../pipeline/v1beta1/pipeline_validation.go | 110 -- .../v1beta1/pipeline_validation_test.go | 442 ----- .../v1beta1/pipelinerun_conversion.go | 27 - .../v1beta1/pipelinerun_conversion_test.go | 36 - .../pipeline/v1beta1/pipelinerun_types.go | 5 - pkg/apis/pipeline/v1beta1/resource_paths.go | 40 - .../pipeline/v1beta1/resource_paths_test.go | 81 - pkg/apis/pipeline/v1beta1/resource_types.go | 200 -- .../pipeline/v1beta1/resource_types_test.go | 82 - .../v1beta1/resource_types_validation.go | 101 - pkg/apis/pipeline/v1beta1/swagger.json | 507 ----- pkg/apis/pipeline/v1beta1/task_conversion.go | 29 - .../pipeline/v1beta1/task_conversion_test.go | 78 - pkg/apis/pipeline/v1beta1/task_types.go | 6 - pkg/apis/pipeline/v1beta1/task_validation.go | 21 - .../pipeline/v1beta1/task_validation_test.go | 110 -- .../pipeline/v1beta1/taskrun_conversion.go | 25 - .../v1beta1/taskrun_conversion_test.go | 80 - pkg/apis/pipeline/v1beta1/taskrun_types.go | 19 - .../pipeline/v1beta1/taskrun_validation.go | 1 - .../v1beta1/taskrun_validation_test.go | 233 --- .../pipeline/v1beta1/zz_generated.deepcopy.go | 336 ---- pkg/apis/resource/resource.go | 40 - pkg/apis/resource/v1alpha1/doc.go | 23 - .../resource/v1alpha1/git/git_resource.go | 212 --- .../v1alpha1/git/git_resource_test.go | 912 --------- .../v1alpha1/pipeline_resource_defaults.go | 34 - .../v1alpha1/pipeline_resource_types.go | 146 -- .../v1alpha1/pipelineresource_validation.go | 81 - .../pipelineresource_validation_test.go | 151 -- pkg/apis/resource/v1alpha1/register.go | 54 - .../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 | 455 ----- pkg/apis/resource/v1alpha1/storage/secret.go | 60 - pkg/apis/resource/v1alpha1/storage/storage.go | 92 - .../v1alpha1/storage/zz_generated.deepcopy.go | 69 - pkg/apis/resource/v1alpha1/types_test.go | 29 - .../v1alpha1/zz_generated.deepcopy.go | 181 -- pkg/artifacts/artifact_storage_test.go | 619 ------ pkg/artifacts/artifacts_storage.go | 244 --- .../resource/clientset/versioned/clientset.go | 121 -- .../resource/clientset/versioned/doc.go | 20 - .../versioned/fake/clientset_generated.go | 85 - .../resource/clientset/versioned/fake/doc.go | 20 - .../clientset/versioned/fake/register.go | 56 - .../clientset/versioned/scheme/doc.go | 20 - .../clientset/versioned/scheme/register.go | 56 - .../versioned/typed/resource/v1alpha1/doc.go | 20 - .../typed/resource/v1alpha1/fake/doc.go | 20 - .../v1alpha1/fake/fake_pipelineresource.go | 130 -- .../v1alpha1/fake/fake_resource_client.go | 40 - .../resource/v1alpha1/generated_expansion.go | 21 - .../resource/v1alpha1/pipelineresource.go | 178 -- .../resource/v1alpha1/resource_client.go | 107 -- .../informers/externalversions/factory.go | 180 -- .../informers/externalversions/generic.go | 62 - .../internalinterfaces/factory_interfaces.go | 40 - .../externalversions/resource/interface.go | 46 - .../resource/v1alpha1/interface.go | 45 - .../resource/v1alpha1/pipelineresource.go | 90 - .../resource/injection/client/client.go | 243 --- .../resource/injection/client/fake/fake.go | 57 - .../injection/informers/factory/factory.go | 56 - .../injection/informers/factory/fake/fake.go | 45 - .../filtered/fake/fake_filtered_factory.go | 59 - .../factory/filtered/filtered_factory.go | 77 - .../v1alpha1/pipelineresource/fake/fake.go | 40 - .../pipelineresource/filtered/fake/fake.go | 52 - .../filtered/pipelineresource.go | 136 -- .../pipelineresource/pipelineresource.go | 116 -- .../resource/v1alpha1/expansion_generated.go | 27 - .../resource/v1alpha1/pipelineresource.go | 99 - pkg/pipelinerunmetrics/metrics_test.go | 2 +- pkg/reconciler/pipeline/dag/dag_test.go | 192 +- pkg/reconciler/pipelinerun/controller.go | 3 - pkg/reconciler/pipelinerun/pipelinerun.go | 64 +- .../pipelinerun/pipelinerun_test.go | 346 +--- .../resources/input_output_steps.go | 115 -- .../resources/input_output_steps_test.go | 355 ---- .../resources/pipelinerunresolution.go | 92 +- .../resources/pipelinerunresolution_test.go | 600 +----- pkg/reconciler/taskrun/controller.go | 3 - pkg/reconciler/taskrun/resources/apply.go | 31 - .../taskrun/resources/apply_test.go | 125 -- .../taskrun/resources/input_resource_test.go | 1363 -------------- .../taskrun/resources/input_resources.go | 146 -- .../taskrun/resources/output_resource.go | 136 -- .../taskrun/resources/output_resource_test.go | 1651 ----------------- .../resources/taskresourceresolution.go | 66 - .../resources/taskresourceresolution_test.go | 362 ---- pkg/reconciler/taskrun/resources/volume.go | 70 - .../taskrun/resources/volume_test.go | 38 - pkg/reconciler/taskrun/taskrun.go | 68 +- pkg/reconciler/taskrun/taskrun_test.go | 481 +---- pkg/reconciler/taskrun/validate_resources.go | 53 - .../taskrun/validate_resources_test.go | 274 --- pkg/spire/spire_mock_test.go | 3 - pkg/taskrunmetrics/metrics_test.go | 2 +- test/artifact_bucket_test.go | 356 ---- test/clients.go | 8 - test/controller.go | 37 +- test/controller_test.go | 8 - test/conversion_test.go | 69 +- test/custom_task_test.go | 28 + test/dag_test.go | 85 +- test/embed_test.go | 114 -- test/git_checkout_test.go | 278 --- test/hermetic_taskrun_test.go | 4 +- test/init_test.go | 9 - test/larger_results_sidecar_logs_test.go | 1 - test/parse/yaml.go | 12 - test/pipelinerun_test.go | 264 +-- test/propagated_params_test.go | 4 - test/resolvers_test.go | 1 + 158 files changed, 344 insertions(+), 20881 deletions(-) delete mode 100644 config/300-resource.yaml delete mode 100644 config/config-artifact-bucket.yaml delete mode 100644 config/config-artifact-pvc.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 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/pipeline/v1beta1/resource_paths.go delete mode 100644 pkg/apis/pipeline/v1beta1/resource_paths_test.go delete mode 100644 pkg/apis/pipeline/v1beta1/resource_types_validation.go delete mode 100644 pkg/apis/resource/resource.go delete mode 100644 pkg/apis/resource/v1alpha1/doc.go 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/pipeline_resource_defaults.go delete mode 100644 pkg/apis/resource/v1alpha1/pipeline_resource_types.go delete mode 100644 pkg/apis/resource/v1alpha1/pipelineresource_validation.go delete mode 100644 pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go delete mode 100644 pkg/apis/resource/v1alpha1/register.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/apis/resource/v1alpha1/types_test.go delete mode 100644 pkg/apis/resource/v1alpha1/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/client/resource/clientset/versioned/clientset.go delete mode 100644 pkg/client/resource/clientset/versioned/doc.go delete mode 100644 pkg/client/resource/clientset/versioned/fake/clientset_generated.go delete mode 100644 pkg/client/resource/clientset/versioned/fake/doc.go delete mode 100644 pkg/client/resource/clientset/versioned/fake/register.go delete mode 100644 pkg/client/resource/clientset/versioned/scheme/doc.go delete mode 100644 pkg/client/resource/clientset/versioned/scheme/register.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/doc.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/doc.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_resource_client.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/generated_expansion.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go delete mode 100644 pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/resource_client.go delete mode 100644 pkg/client/resource/informers/externalversions/factory.go delete mode 100644 pkg/client/resource/informers/externalversions/generic.go delete mode 100644 pkg/client/resource/informers/externalversions/internalinterfaces/factory_interfaces.go delete mode 100644 pkg/client/resource/informers/externalversions/resource/interface.go delete mode 100644 pkg/client/resource/informers/externalversions/resource/v1alpha1/interface.go delete mode 100644 pkg/client/resource/informers/externalversions/resource/v1alpha1/pipelineresource.go delete mode 100644 pkg/client/resource/injection/client/client.go delete mode 100644 pkg/client/resource/injection/client/fake/fake.go delete mode 100644 pkg/client/resource/injection/informers/factory/factory.go delete mode 100644 pkg/client/resource/injection/informers/factory/fake/fake.go delete mode 100644 pkg/client/resource/injection/informers/factory/filtered/fake/fake_filtered_factory.go delete mode 100644 pkg/client/resource/injection/informers/factory/filtered/filtered_factory.go delete mode 100644 pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/fake/fake.go delete mode 100644 pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/fake/fake.go delete mode 100644 pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/pipelineresource.go delete mode 100644 pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/pipelineresource.go delete mode 100644 pkg/client/resource/listers/resource/v1alpha1/expansion_generated.go delete mode 100644 pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go delete mode 100644 pkg/reconciler/pipelinerun/resources/input_output_steps.go delete mode 100644 pkg/reconciler/pipelinerun/resources/input_output_steps_test.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/output_resource.go delete mode 100644 pkg/reconciler/taskrun/resources/output_resource_test.go delete mode 100644 pkg/reconciler/taskrun/resources/taskresourceresolution_test.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 diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 657712342d2..c282155a8c4 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -68,10 +68,8 @@ func main() { flag.StringVar(&opts.Images.EntrypointImage, "entrypoint-image", "", "The container image containing our entrypoint binary.") flag.StringVar(&opts.Images.SidecarLogResultsImage, "sidecarlogresults-image", "", "The container image containing the binary for accessing results.") flag.StringVar(&opts.Images.NopImage, "nop-image", "", "The container image used to stop sidecars") - flag.StringVar(&opts.Images.GitImage, "git-image", "", "The container image containing our Git binary.") flag.StringVar(&opts.Images.ShellImage, "shell-image", "", "The container image containing a shell") flag.StringVar(&opts.Images.ShellImageWin, "shell-image-win", "", "The container image containing a windows shell") - flag.StringVar(&opts.Images.GsutilImage, "gsutil-image", "", "The container image containing gsutil") flag.StringVar(&opts.Images.WorkingDirInitImage, "workingdirinit-image", "", "The container image containing our working dir init binary.") // This parses flags. diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 6eef0a10186..91c2034bd18 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -31,7 +31,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/resolution" resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" @@ -52,7 +51,6 @@ import ( var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ // v1alpha1 - v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &resourcev1alpha1.PipelineResource{}, v1alpha1.SchemeGroupVersion.WithKind("Run"): &v1alpha1.Run{}, v1alpha1.SchemeGroupVersion.WithKind("VerificationPolicy"): &v1alpha1.VerificationPolicy{}, // v1beta1 diff --git a/config/300-resource.yaml b/config/300-resource.yaml deleted file mode 100644 index 4760db76d39..00000000000 --- a/config/300-resource.yaml +++ /dev/null @@ -1,52 +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: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: pipelineresources.tekton.dev - labels: - app.kubernetes.io/instance: default - app.kubernetes.io/part-of: tekton-pipelines - pipeline.tekton.dev/release: "devel" - version: "devel" -spec: - group: tekton.dev - versions: - - name: v1alpha1 - served: true - storage: true - schema: - openAPIV3Schema: - type: object - # One can use x-kubernetes-preserve-unknown-fields: true - # at the root of the schema (and inside any properties, additionalProperties) - # to get the traditional CRD behaviour that nothing is pruned, despite - # setting spec.preserveUnknownProperties: false. - # - # See https://kubernetes.io/blog/2019/06/20/crd-structural-schema/ - # See issue: https://github.com/knative/serving/issues/912 - x-kubernetes-preserve-unknown-fields: true - # Opt into the status subresource so metadata.generation - # starts to increment - subresources: - status: {} - names: - kind: PipelineResource - plural: pipelineresources - singular: pipelineresource - categories: - - tekton - - tekton-pipelines - scope: Namespaced 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/config/config-artifact-pvc.yaml b/config/config-artifact-pvc.yaml deleted file mode 100644 index f3ca3b1c0ca..00000000000 --- a/config/config-artifact-pvc.yaml +++ /dev/null @@ -1,28 +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-pvc - namespace: tekton-pipelines - labels: - app.kubernetes.io/instance: default - app.kubernetes.io/part-of: tekton-pipelines -# data: -# # size of the PVC volume -# size: 5Gi -# -# # storage class of the PVC volume -# storageClassName: storage-class-name diff --git a/config/controller.yaml b/config/controller.yaml index 2cada57d46f..67e71284564 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -65,15 +65,11 @@ spec: args: [ # These images are built on-demand by `ko resolve` and are replaced # by image references by digest. - "-git-image", "ko://github.com/tektoncd/pipeline/cmd/git-init", "-entrypoint-image", "ko://github.com/tektoncd/pipeline/cmd/entrypoint", "-nop-image", "ko://github.com/tektoncd/pipeline/cmd/nop", "-sidecarlogresults-image", "ko://github.com/tektoncd/pipeline/cmd/sidecarlogresults", "-workingdirinit-image", "ko://github.com/tektoncd/pipeline/cmd/workingdirinit", - # This is gcr.io/google.com/cloudsdktool/cloud-sdk:302.0.0-slim - "-gsutil-image", "gcr.io/google.com/cloudsdktool/cloud-sdk@sha256:27b2c22bf259d9bc1a291e99c63791ba0c27a04d2db0a43241ba0f1f20f4067f", - # The shell image must allow root in order to create directories and copy files to PVCs. # cgr.dev/chainguard/busybox as of April 14 2022 # image shall not contains tag, so it will be supported on a runtime like cri-o diff --git a/docs/additional-configs.md b/docs/additional-configs.md index 9b901dfe3f7..ed0644e8bb4 100644 --- a/docs/additional-configs.md +++ b/docs/additional-configs.md @@ -13,11 +13,6 @@ installation. ## Table of Contents - - [Configuring PipelineResource storage](#configuring-pipelineresource-storage) - - [Configuring a persistent volume](#configuring-a-persistent-volume) - - [Configuring a cloud storage bucket](#configuring-a-cloud-storage-bucket) - - [Example configuration for an S3 bucket](#example-configuration-for-an-s3-bucket) - - [Example configuration for a GCS bucket](#example-configuration-for-a-gcs-bucket) - [Configuring built-in remote Task and Pipeline resolution](#configuring-built-in-remote-task-and-pipeline-resolution) - [Configuring CloudEvents notifications](#configuring-cloudevents-notifications) - [Configuring self-signed cert for private registry](#configuring-self-signed-cert-for-private-registry) @@ -37,124 +32,6 @@ installation. - [Verify Tekton Resources](#verify-tekton-resources) - [Next steps](#next-steps) -## Configuring PipelineResource storage - -> :warning: **`PipelineResources` are [deprecated](deprecations.md#deprecation-table).** -> -> For storage, consider using [`Workspaces`](workspaces.md) with [`VolumeClaimTemplates`](https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md#volumeclaimtemplate) -> to automatically provision and manage Persistent Volume Claims (PVCs). Read more in [TEP-0074](https://github.com/tektoncd/community/blob/main/teps/0074-deprecate-pipelineresources.md). - -PipelineResources are one of the ways that Tekton passes data between Tasks. If you intend to -use PipelineResources in your Pipelines then you'll need to configure a storage location -for that data to be put so that it can be shared between Tasks in the Pipeline. - -The storage options available for sharing PipelineResources between Tasks in a Pipeline are: - - * [A persistent volume](#configuring-a-persistent-volume) - * [A cloud storage bucket](#configuring-a-cloud-storage-bucket) - -Either option provides the same functionality to Tekton Pipelines. Choose the option that -best suits your business needs. For example: - - - In some environments, creating a persistent volume could be slower than transferring files to/from a cloud storage bucket. - - If the cluster is running in multiple zones, accessing a persistent volume could be unreliable. - -**Note:** To customize the names of the `ConfigMaps` for artifact persistence (e.g. to avoid collisions with other services), rename the `ConfigMap` and update the env value defined [controller.yaml](https://github.com/tektoncd/pipeline/blob/e153c6f2436130e95f6e814b4a792fb2599c57ef/config/controller.yaml#L66-L75). - -### Configuring a persistent volume - -To configure a [persistent volume](https://kubernetes.io/docs/concepts/storage/persistent-volumes/), use a `ConfigMap` with the name `config-artifact-pvc` and the following attributes: - -- `size`: the size of the volume. Default is 5GiB. -- `storageClassName`: the [storage class](https://kubernetes.io/docs/concepts/storage/storage-classes/) of the volume. The possible values depend on the cluster configuration and the underlying infrastructure provider. Default is the default storage class. - -### Configuring a cloud storage bucket - -To configure either an [S3 bucket](https://aws.amazon.com/s3/) or a [GCS bucket](https://cloud.google.com/storage/), -use a `ConfigMap` with the name `config-artifact-bucket` and the following attributes: - -- `location` - the address of the bucket, for example `gs://mybucket` or `s3://mybucket`. -- `bucket.service.account.secret.name` - the name of the secret containing the credentials for the service account with access to the bucket. -- `bucket.service.account.secret.key` - the key in the secret with the required - service account JSON file. -- `bucket.service.account.field.name` - the name of the environment variable to use when specifying the - secret path. Defaults to `GOOGLE_APPLICATION_CREDENTIALS`. Set to `BOTO_CONFIG` if using S3 instead of GCS. - -**Important:** Configure your bucket's retention policy to delete all files after your `Tasks` finish running. - -**Note:** You can only use an S3 bucket located in the `us-east-1` region. This is a limitation of [`gsutil`](https://cloud.google.com/storage/docs/gsutil) running a `boto` configuration behind the scenes to access the S3 bucket. - - -#### Example configuration for an S3 bucket - -Below is an example configuration that uses an S3 bucket: - -```yaml -apiVersion: v1 -kind: Secret -metadata: - name: tekton-storage - namespace: tekton-pipelines -type: kubernetes.io/opaque -stringData: - boto-config: | - [Credentials] - aws_access_key_id = AWS_ACCESS_KEY_ID - aws_secret_access_key = AWS_SECRET_ACCESS_KEY - [s3] - host = s3.us-east-1.amazonaws.com - [Boto] - https_validate_certificates = True ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-bucket - namespace: tekton-pipelines -data: - location: s3://mybucket - bucket.service.account.secret.name: tekton-storage - bucket.service.account.secret.key: boto-config - bucket.service.account.field.name: BOTO_CONFIG -``` - -#### Example configuration for a GCS bucket - -Below is an example configuration that uses a GCS bucket: - -```yaml -apiVersion: v1 -kind: Secret -metadata: - name: tekton-storage - namespace: tekton-pipelines -type: kubernetes.io/opaque -stringData: - gcs-config: | - { - "type": "service_account", - "project_id": "gproject", - "private_key_id": "some-key-id", - "private_key": "-----BEGIN PRIVATE KEY-----\nME[...]dF=\n-----END PRIVATE KEY-----\n", - "client_email": "tekton-storage@gproject.iam.gserviceaccount.com", - "client_id": "1234567890", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/tekton-storage%40gproject.iam.gserviceaccount.com" - } ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: config-artifact-bucket - namespace: tekton-pipelines -data: - location: gs://mybucket - bucket.service.account.secret.name: tekton-storage - bucket.service.account.secret.key: gcs-config - bucket.service.account.field.name: GOOGLE_APPLICATION_CREDENTIALS -``` ## Configuring built-in remote Task and Pipeline resolution diff --git a/docs/pipeline-api.md b/docs/pipeline-api.md index 6bbb60e8b6c..2078211c85f 100644 --- a/docs/pipeline-api.md +++ b/docs/pipeline-api.md @@ -5823,8 +5823,6 @@ Resource Types: Run
  • VerificationPolicy -
  • -PipelineResource
  • Run

    @@ -6136,136 +6134,6 @@ Then the ResourcesPattern should be valid regex. E.g. If using gitresolver, and -

    PipelineResource -

    -
    -

    PipelineResource describes a resource that is an input to or output from a -Task.

    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -apiVersion
    -string
    - -tekton.dev/v1alpha1 - -
    -kind
    -string -
    PipelineResource
    -metadata
    - - -Kubernetes meta/v1.ObjectMeta - - -
    -(Optional) -Refer to the Kubernetes API documentation for the fields of the -metadata field. -
    -spec
    - - -PipelineResourceSpec - - -
    -

    Spec holds the desired state of the PipelineResource from the client

    -
    -
    - - - - - - - - - - - - - - - - - -
    -description
    - -string - -
    -(Optional) -

    Description is a user-facing description of the resource that may be -used to populate a UI.

    -
    -type
    - -string - -
    -
    -params
    - - -[]ResourceParam - - -
    -
    -secrets
    - - -[]SecretParam - - -
    -(Optional) -

    Secrets to fetch to populate some of resource fields

    -
    -
    -status
    - - -PipelineResourceStatus - - -
    -(Optional) -

    Status is used to communicate the observed state of the PipelineResource from -the controller, but was unused as there is no controller for PipelineResource.

    -

    Deprecated: Deprecated in v0.30.0.

    -

    Authority

    @@ -6719,256 +6587,6 @@ Then the ResourcesPattern should be valid regex. E.g. If using gitresolver, and -

    PipelineResourceSpec -

    -

    -(Appears on:PipelineResource, PipelineResourceBinding) -

    -
    -

    PipelineResourceSpec defines an individual resources used in the pipeline.

    -
    - - - - - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -description
    - -string - -
    -(Optional) -

    Description is a user-facing description of the resource that may be -used to populate a UI.

    -
    -type
    - -string - -
    -
    -params
    - - -[]ResourceParam - - -
    -
    -secrets
    - - -[]SecretParam - - -
    -(Optional) -

    Secrets to fetch to populate some of resource fields

    -
    -

    PipelineResourceStatus -

    -

    -(Appears on:PipelineResource) -

    -
    -

    PipelineResourceStatus does not contain anything because PipelineResources on their own -do not have a status

    -

    Deprecated: Deprecated in v0.30.0.

    -
    -

    ResourceDeclaration -

    -

    -(Appears on:TaskResource) -

    -
    -

    ResourceDeclaration defines an input or output PipelineResource declared as a requirement -by another type such as a Task or Condition. The Name field will be used to refer to these -PipelineResources within the type’s definition, and when provided as an Input, the Name will be the -path to the volume mounted containing this PipelineResource as an input (e.g. -an input Resource named workspace will be mounted at /workspace).

    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -

    Name declares the name by which a resource is referenced in the -definition. Resources may be referenced by name in the definition of a -Task’s steps.

    -
    -type
    - -string - -
    -

    Type is the type of this resource;

    -
    -description
    - -string - -
    -(Optional) -

    Description is a user-facing description of the declared resource that may be -used to populate a UI.

    -
    -targetPath
    - -string - -
    -(Optional) -

    TargetPath is the path in workspace directory where the resource -will be copied.

    -
    -optional
    - -bool - -
    -

    Optional declares the resource as optional. -By default optional is set to false which makes a resource required. -optional: true - the resource is considered optional -optional: false - the resource is considered required (equivalent of not specifying it)

    -
    -

    ResourceParam -

    -

    -(Appears on:PipelineResourceSpec) -

    -
    -

    ResourceParam declares a string value to use for the parameter called Name, and is used in -the specific context of PipelineResources.

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -
    -value
    - -string - -
    -
    -

    SecretParam -

    -

    -(Appears on:PipelineResourceSpec) -

    -
    -

    SecretParam indicates which secret can be used to populate a field of the resource

    -
    - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -fieldName
    - -string - -
    -
    -secretKey
    - -string - -
    -
    -secretName
    - -string - -
    -

    RunResult

    @@ -7231,22 +6849,6 @@ TaskSpec - - - - - - - - - - - -
    -resources
    - - -TaskResources - - -
    -(Optional) -

    Resources is a list input and output resource to run the task -Resources are represented in TaskRuns as bindings to instances of -PipelineResources.

    -
    params
    @@ -7634,20 +7236,6 @@ used to populate a UI.

    -resources
    - - -[]PipelineDeclaredResource - - -
    -

    Resources declares the names and types of the resources given to the -Pipeline’s tasks as inputs and outputs.

    -
    tasks
    @@ -7813,21 +7401,6 @@ PipelineSpec
    -resources
    - - -[]PipelineResourceBinding - - -
    -

    Resources is a list of bindings specifying which actual instances of -PipelineResources to use for the resources the Pipeline has declared -it needs.

    -
    params
    @@ -8023,22 +7596,6 @@ TaskSpec - - - - - - - - - - - - - - - -
    -resources
    - - -TaskResources - - -
    -(Optional) -

    Resources is a list input and output resource to run the task -Resources are represented in TaskRuns as bindings to instances of -PipelineResources.

    -
    params
    @@ -8242,19 +7799,6 @@ TaskRunDebug
    -resources
    - - -TaskRunResources - - -
    -(Optional) -
    serviceAccountName
    string @@ -8961,80 +8505,29 @@ structs.

    metadata
    -PipelineTaskMetadata - - -
    -(Optional) -
    -TaskSpec
    - - -TaskSpec - - -
    -

    -(Members of TaskSpec are embedded into this type.) -

    -(Optional) -

    TaskSpec is a specification of a task

    -
    -

    InternalTaskModifier -

    -
    -

    InternalTaskModifier implements TaskModifier for resources that are built-in to Tekton Pipelines.

    -
    - - - - - - - - - - - - - - @@ -9143,7 +8636,11 @@ The names of the params must match the names of the paramsParam

    +<<<<<<< HEAD (Appears on:RunSpec, CustomRunSpec, PipelineRunSpec, ResolverRef, TaskRunInputs, TaskRunSpec, ResolutionRequestSpec) +======= +(Appears on:RunSpec, CustomRunSpec, Matrix, MatrixInclude, PipelineRunSpec, PipelineTask, ResolverRef, TaskRunSpec, ResolutionRequestSpec) +>>>>>>> 88e27b27f (Remove Git, Storage and Generic PipelineResources)

    Param declares an ParamValues to use for the parameter called name.

    @@ -9344,6 +8841,7 @@ map[string]string
    FieldDescription
    -stepsToPrepend
    - - -[]Step - - -
    -
    -stepsToAppend
    - - -[]Step +PipelineTaskMetadata
    +(Optional)
    -volumes
    +TaskSpec
    - -[]Kubernetes core/v1.Volume + +TaskSpec
    +

    +(Members of TaskSpec are embedded into this type.) +

    +(Optional) +

    TaskSpec is a specification of a task

    +<<<<<<< HEAD

    Params ([]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param alias)

    @@ -9410,6 +8908,8 @@ optional: false - the resource is considered required (default/equivalent of not

    +======= +>>>>>>> 88e27b27f (Remove Git, Storage and Generic PipelineResources)

    PipelineObject

    @@ -9485,112 +8985,6 @@ feature gate is enabled.

    -

    PipelineResourceBinding -

    -

    -(Appears on:PipelineRunSpec, TaskResourceBinding) -

    -
    -

    PipelineResourceBinding connects a reference to an instance of a PipelineResource -with a PipelineResource dependency that the Pipeline has declared

    -
    - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -

    Name is the name of the PipelineResource in the Pipeline’s declaration

    -
    -resourceRef
    - - -PipelineResourceRef - - -
    -(Optional) -

    ResourceRef is a reference to the instance of the actual PipelineResource -that should be used

    -
    -resourceSpec
    - - -PipelineResourceSpec - - -
    -(Optional) -

    ResourceSpec is specification of a resource that should be created and -consumed by the task

    -
    -

    PipelineResourceInterface -

    -
    -

    PipelineResourceInterface interface to be implemented by different PipelineResource types

    -
    -

    PipelineResourceRef -

    -

    -(Appears on:PipelineResourceBinding) -

    -
    -

    PipelineResourceRef can be used to refer to a specific instance of a Resource

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -

    Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names

    -
    -apiVersion
    - -string - -
    -(Optional) -

    API version of the referent

    -

    PipelineResourceResult

    @@ -9865,21 +9259,6 @@ PipelineSpec -resources
    - - -[]PipelineResourceBinding - - - - -

    Resources is a list of bindings specifying which actual instances of -PipelineResources to use for the resources the Pipeline has declared -it needs.

    - - - - params
    @@ -10276,20 +9655,6 @@ used to populate a UI.

    -resources
    - -
    -[]PipelineDeclaredResource - - - - -

    Resources declares the names and types of the resources given to the -Pipeline’s tasks as inputs and outputs.

    - - - - tasks
    @@ -10460,21 +9825,6 @@ this Task executes. (Used to force a specific ordering in graph execution.)

    -resources
    - -
    -PipelineTaskResources - - - - -(Optional) -

    Resources declares the resources given to this task as inputs and -outputs.

    - - - - params
    @@ -10513,168 +9863,34 @@ Matrix (Optional)

    Workspaces maps workspaces from the pipeline spec to the workspaces -declared in the Task.

    - - - - -timeout
    - -
    -Kubernetes meta/v1.Duration - - - - -(Optional) -

    Time after which the TaskRun times out. Defaults to 1 hour. -Specified TaskRun timeout should be less than 24h. -Refer Go’s ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration

    - - - - -

    PipelineTaskInputResource -

    -

    -(Appears on:PipelineTaskResources) -

    -
    -

    PipelineTaskInputResource maps the name of a declared PipelineResource input -dependency in a Task to the resource in the Pipeline’s DeclaredPipelineResources -that should be used. This input may come from a previous task.

    -
    - - - - - - - - - - - - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -

    Name is the name of the PipelineResource as declared by the Task.

    -
    -resource
    - -string - -
    -

    Resource is the name of the DeclaredPipelineResource to use.

    -
    -from
    - -[]string - -
    -(Optional) -

    From is the list of PipelineTask names that the resource has to come from. -(Implies an ordering in the execution graph.)

    -
    -

    PipelineTaskMetadata -

    -

    -(Appears on:EmbeddedRunSpec, EmbeddedCustomRunSpec, EmbeddedTask, PipelineTaskRunSpec) -

    -
    -

    PipelineTaskMetadata contains the labels or annotations for an EmbeddedTask

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -labels
    - -map[string]string - -
    -(Optional) -
    -annotations
    - -map[string]string - -
    -(Optional) -
    -

    PipelineTaskOutputResource -

    -

    -(Appears on:PipelineTaskResources) -

    -
    -

    PipelineTaskOutputResource maps the name of a declared PipelineResource output -dependency in a Task to the resource in the Pipeline’s DeclaredPipelineResources -that should be used.

    -
    - - - - - - - - - - -
    FieldDescription
    -name
    - -string - -
    -

    Name is the name of the PipelineResource as declared by the Task.

    +declared in the Task.

    -resource
    +timeout
    -string + +Kubernetes meta/v1.Duration +
    -

    Resource is the name of the DeclaredPipelineResource to use.

    +(Optional) +

    Time after which the TaskRun times out. Defaults to 1 hour. +Specified TaskRun timeout should be less than 24h. +Refer Go’s ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration

    -

    PipelineTaskParam +

    PipelineTaskMetadata

    +

    +(Appears on:EmbeddedRunSpec, EmbeddedCustomRunSpec, EmbeddedTask, PipelineTaskRunSpec) +

    -

    PipelineTaskParam is used to provide arbitrary string parameters to a Task.

    +

    PipelineTaskMetadata contains the labels or annotations for an EmbeddedTask

    @@ -10686,34 +9902,32 @@ string
    -name
    +labels
    -string +map[string]string
    +(Optional)
    -value
    +annotations
    -string +map[string]string
    +(Optional)
    -

    PipelineTaskResources +

    PipelineTaskParam

    -

    -(Appears on:PipelineTask) -

    -

    PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources -should be provided to a Task as its inputs and outputs.

    +

    PipelineTaskParam is used to provide arbitrary string parameters to a Task.

    @@ -10725,30 +9939,22 @@ should be provided to a Task as its inputs and outputs.

    @@ -11703,7 +10909,7 @@ SkippingReason

    Step

    -(Appears on:InternalTaskModifier, TaskSpec) +(Appears on:TaskSpec)

    Step runs a subcomponent of a Task

    @@ -12648,11 +11854,6 @@ Default is false.

    TaskKind defines the type of Task used by the pipeline.

    -

    TaskModifier -

    -
    -

    TaskModifier is an interface to be implemented by different PipelineResources

    -

    TaskObject

    @@ -12741,138 +11942,6 @@ feature gate is enabled.

    -inputs
    +name
    - -[]PipelineTaskInputResource - +string
    -

    Inputs holds the mapping from the PipelineResources declared in -DeclaredPipelineResources to the input PipelineResources required by the Task.

    -outputs
    +value
    - -[]PipelineTaskOutputResource - +string
    -

    Outputs holds the mapping from the PipelineResources declared in -DeclaredPipelineResources to the input PipelineResources required by the Task.

    -

    TaskResource -

    -

    -(Appears on:TaskResources) -

    -
    -

    TaskResource defines an input or output Resource declared as a requirement -by a Task. The Name field will be used to refer to these Resources within -the Task definition, and when provided as an Input, the Name will be the -path to the volume mounted containing this Resource as an input (e.g. -an input Resource named workspace will be mounted at /workspace).

    -
    - - - - - - - - - - - - - -
    FieldDescription
    -ResourceDeclaration
    - - -ResourceDeclaration - - -
    -

    -(Members of ResourceDeclaration are embedded into this type.) -

    -
    -

    TaskResourceBinding -

    -

    -(Appears on:TaskRunInputs, TaskRunOutputs, TaskRunResources) -

    -
    -

    TaskResourceBinding points to the PipelineResource that -will be used for the Task input or output called Name.

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -PipelineResourceBinding
    - - -PipelineResourceBinding - - -
    -

    -(Members of PipelineResourceBinding are embedded into this type.) -

    -
    -paths
    - -[]string - -
    -(Optional) -

    Paths will probably be removed in #1284, and then PipelineResourceBinding can be used instead. -The optional Path field corresponds to a path on disk at which the Resource can be found -(used when providing the resource via mounted volume, overriding the default logic to fetch the Resource).

    -
    -

    TaskResources -

    -

    -(Appears on:TaskSpec) -

    -
    -

    TaskResources allows a Pipeline to declare how its DeclaredPipelineResources -should be provided to a Task as its inputs and outputs.

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -inputs
    - - -[]TaskResource - - -
    -

    Inputs holds the mapping from the PipelineResources declared in -DeclaredPipelineResources to the input PipelineResources required by the Task.

    -
    -outputs
    - - -[]TaskResource - - -
    -

    Outputs holds the mapping from the PipelineResources declared in -DeclaredPipelineResources to the input PipelineResources required by the Task.

    -

    TaskResult

    @@ -12978,75 +12047,6 @@ conditions such as one used in spire results verification

    -

    TaskRunInputs -

    -
    -

    TaskRunInputs holds the input values that this task was invoked with.

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -resources
    - - -[]TaskResourceBinding - - -
    -(Optional) -
    -params
    - - -[]Param - - -
    -(Optional) -
    -

    TaskRunOutputs -

    -
    -

    TaskRunOutputs holds the output values that this task was invoked with.

    -
    - - - - - - - - - - - - - -
    FieldDescription
    -resources
    - - -[]TaskResourceBinding - - -
    -(Optional) -

    TaskRunReason (string alias)

    @@ -13054,50 +12054,6 @@ conditions such as one used in spire results verification

    the Succeeded condition that are controlled by the TaskRun itself. Failure reasons that emerge from underlying resources are not included here

    -

    TaskRunResources -

    -

    -(Appears on:TaskRunSpec) -

    -
    -

    TaskRunResources allows a TaskRun to declare inputs and outputs TaskResourceBinding

    -
    - - - - - - - - - - - - - - - - - -
    FieldDescription
    -inputs
    - - -[]TaskResourceBinding - - -
    -

    Inputs holds the inputs resources this task was invoked with

    -
    -outputs
    - - -[]TaskResourceBinding - - -
    -

    Outputs holds the inputs resources this task was invoked with

    -

    TaskRunResult

    @@ -13241,19 +12197,6 @@ TaskRunDebug -resources
    - - -TaskRunResources - - - - -(Optional) - - - - serviceAccountName
    string @@ -13730,22 +12673,6 @@ Kubernetes core/v1.ResourceRequirements -resources
    - - -TaskResources - - - - -(Optional) -

    Resources is a list input and output resource to run the task -Resources are represented in TaskRuns as bindings to instances of -PipelineResources.

    - - - - params
    diff --git a/docs/pipelineruns.md b/docs/pipelineruns.md index 48a9b15ef8f..6d3c521f66a 100644 --- a/docs/pipelineruns.md +++ b/docs/pipelineruns.md @@ -690,8 +690,7 @@ spec: - --commit=$(params.gitrepo.commit) - --branch=$(params.gitrepo.branch) image: bash - name: write-result - resources: {} + name: write-result status: completionTime: "2022-09-08T17:22:01Z" conditions: @@ -719,7 +718,6 @@ status: - --branch=main image: bash name: write-result - resources: {} startTime: "2022-09-08T17:21:57Z" childReferences: - name: pipelinerun-object-param-resultpxp59-task1 @@ -735,7 +733,6 @@ status: - --branch=main image: bash name: write-result - resources: {} ``` ### Specifying custom `ServiceAccount` credentials diff --git a/docs/resources.md b/docs/resources.md index ec18e319a71..2c23d7cdf8e 100644 --- a/docs/resources.md +++ b/docs/resources.md @@ -12,18 +12,6 @@ weight: 208 > Consider using replacement features instead. Read more in [documentation](migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks) > and [TEP-0074](https://github.com/tektoncd/community/blob/main/teps/0074-deprecate-pipelineresources.md). -`PipelineResources` in a pipeline are the set of objects that are going to be -used as inputs to a [`Task`](tasks.md) and can be output by a `Task`. - -A `Task` can have multiple inputs and outputs. - -For example: - -- A `Task`'s input could be a GitHub source which contains your application - code. -- A `Task`'s output can be your application container image which can be then - deployed in a cluster. -- A `Task`'s output can be a jar file to be uploaded to a storage bucket. > **Note**: `PipelineResources` have not been promoted to Beta in tandem with Pipeline's other CRDs. > This means that the level of support for `PipelineResources` remains Alpha. @@ -37,519 +25,8 @@ For example: > of their problems, along with next steps, below](#why-aren-t-pipelineresources-in-beta). -------------------------------------------------------------------------------- - -- [Syntax](#syntax) -- [Using Resources](#using-resources) - - [Variable substitution](#variable-substitution) - - [Controlling where resources are mounted](#controlling-where-resources-are-mounted) - - [Overriding where resources are copied from](#overriding-where-resources-are-copied-from) - - [Resource Status](#resource-status) - - [Optional Resources](#optional-resources) -- [Resource types](#resource-types) - - [Git Resource](#git-resource) - - [Storage Resource](#storage-resource) - - [GCS Storage Resource](#gcs-storage-resource) - [Why Aren't PipelineResources in Beta?](#why-aren-t-pipelineresources-in-beta) -## Syntax - -To define a configuration file for a `PipelineResource`, you can specify the -following fields: - -- Required: - - [`apiVersion`][kubernetes-overview] - Specifies the API version, for - example `tekton.dev/v1alpha1`. - - [`kind`][kubernetes-overview] - Specify the `PipelineResource` resource - object. - - [`metadata`][kubernetes-overview] - Specifies data to uniquely identify - the `PipelineResource` object, for example a `name`. - - [`spec`][kubernetes-overview] - Specifies the configuration information - for your `PipelineResource` resource object. - - [`type`](#resource-types) - Specifies the `type` of the - `PipelineResource` -- Optional: - - [`description`](#description) - Description of the Resource. - - [`params`](#resource-types) - Parameters which are specific to each type - of `PipelineResource` - - [`optional`](#optional-resources) - Boolean flag to mark a resource - optional (by default, `optional` is set to `false` making resources - mandatory). - -[kubernetes-overview]: - https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields - -## Using Resources - -> :warning: **`PipelineResources` are [deprecated](deprecations.md#deprecation-table).** -> -> Consider using replacement features instead. Read more in [documentation](migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks) -> and [TEP-0074](https://github.com/tektoncd/community/blob/main/teps/0074-deprecate-pipelineresources.md). - -Resources can be used in [Tasks](./tasks.md). - -Input resources, like source code (git) or artifacts, are dumped at path -`/workspace/task_resource_name` within a mounted -[volume](https://kubernetes.io/docs/concepts/storage/volumes/) and are available -to all [`steps`](#steps) of your `Task`. The path that the resources are mounted -at can be -[overridden with the `targetPath` field](./resources.md#controlling-where-resources-are-mounted). -Steps can use the `path`[variable substitution](#variable-substitution) key to -refer to the local path to the mounted resource. - -### Variable substitution - -`Task` specs can refer resource params as well as predefined -variables such as `path` using the variable substitution syntax below where -`` is the resource's `name` and `` is one of the resource's `params`: - -#### In Task Spec: - -For an input resource in a `Task` spec: `shell $(resources.inputs..)` - -Or for an output resource: - -```shell -$(outputs.resources..) -``` - -#### Accessing local path to resource - -The `path` key is predefined and refers to the local path to a resource on the -mounted volume `shell $(resources.inputs..path)` - -### Controlling where resources are mounted - -The optional field `targetPath` can be used to initialize a resource in a -specific directory. If `targetPath` is set, the resource will be initialized -under `/workspace/targetPath`. If `targetPath` is not specified, the resource -will be initialized under `/workspace`. The following example demonstrates how -git input repository could be initialized in `$GOPATH` to run tests: - -```yaml -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: task-with-input - namespace: default -spec: - resources: - inputs: - - name: workspace - type: git - targetPath: go/src/github.com/tektoncd/pipeline - steps: - - name: unit-tests - image: golang - command: ["go"] - args: - - "test" - - "./..." - workingDir: "/workspace/go/src/github.com/tektoncd/pipeline" - env: - - name: GOPATH - value: /workspace/go -``` - -### Overriding where resources are copied from - -When specifying input and output `PipelineResources`, you can optionally specify -`paths` for each resource. `paths` will be used by `TaskRun` as the resource's -new source paths i.e., copy the resource from a specified list of paths. -`TaskRun` expects the folder and contents to be already present in specified -paths. The `paths` feature could be used to provide extra files or altered -version of existing resources before the execution of steps. - -The output resource includes the name and reference to the pipeline resource and -optionally `paths`. `paths` will be used by `TaskRun` as the resource's new -destination paths i.e., copy the resource entirely to specified paths. `TaskRun` -will be responsible for the creation of required directories and content -transition. The `paths` feature could be used to inspect the results of -`TaskRun` after the execution of steps. - -`paths` feature for input and output resources is heavily used to pass the same -version of resources across tasks in context of `PipelineRun`. - -In the following example, `Task` and `TaskRun` are defined with an input -resource, output resource and step, which builds a war artifact. After the -execution of `TaskRun`(`volume-taskrun`), `custom` volume will have the entire -resource `java-git-resource` (including the war artifact) copied to the -destination path `/custom/workspace/`. - -```yaml -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: volume-task - namespace: default -spec: - resources: - inputs: - - name: workspace - type: git - outputs: - - name: workspace - steps: - - name: build-war - image: objectuser/run-java-jar #https://hub.docker.com/r/objectuser/run-java-jar/ - command: jar - args: ["-cvf", "projectname.war", "*"] - volumeMounts: - - name: custom-volume - mountPath: /custom -``` - -```yaml -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: volume-taskrun - namespace: default -spec: - taskRef: - name: volume-task - resources: - inputs: - - name: workspace - resourceRef: - name: java-git-resource - outputs: - - name: workspace - paths: - - /custom/workspace/ - resourceRef: - name: java-git-resource - podTemplate: - volumes: - - name: custom-volume - 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. - -### Optional Resources - -By default, a resource is declared as mandatory unless `optional` is set to `true` -for that resource. Resources declared as `optional` in a `Task` does not have be -specified in `TaskRun`. - -```yaml -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: task-check-optional-resources -spec: - resources: - inputs: - - name: git-repo - type: git - optional: true -``` - -Similarly, resources declared as `optional` in a `Pipeline` does not have to be -specified in `PipelineRun`. - -```yaml -apiVersion: tekton.dev/v1beta1 -kind: Pipeline -metadata: - name: pipeline-build-image -spec: - resources: - - name: workspace - type: git - optional: true - tasks: - - name: check-workspace -# ... -``` - -You can refer to different examples demonstrating usage of optional resources in -`Task` and `Pipeline`: - -- [Task](../examples/v1beta1/taskruns/optional-resources.yaml) -- [Cluster Task](../examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml) - -## 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. -### 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 - ``` - --------------------------------------------------------------------------------- - ## Why Aren't PipelineResources in Beta? The short answer is that they're not ready to be given a Beta level of support by Tekton's developers. The long answer is, well, longer: diff --git a/docs/taskruns.md b/docs/taskruns.md index 5747908b5a3..14c18b9456f 100644 --- a/docs/taskruns.md +++ b/docs/taskruns.md @@ -17,7 +17,6 @@ weight: 202 - [Propagated Parameters](#propagated-parameters) - [Propagated Object Parameters](#propagated-object-parameters) - [Extra Parameters](#extra-parameters) - - [Specifying `Resources`](#specifying-resources) - [Specifying `Resource` limits](#specifying-resource-limits) - [Specifying Task-level `ComputeResources`](#specifying-task-level-computeresources) - [Specifying a `Pod` template](#specifying-a-pod-template) @@ -242,7 +241,6 @@ spec: steps: - image: ubuntu name: default - resources: {} script: | echo $(params.message) status: @@ -260,7 +258,6 @@ status: steps: - image: ubuntu name: default - resources: {} script: | echo "hello world!" ``` @@ -320,7 +317,6 @@ spec: - --commit=$(params.gitrepo.commit) image: bash name: echo-object-params - resources: {} status: completionTime: "2022-09-08T17:09:37Z" conditions: @@ -341,7 +337,6 @@ status: - --commit=sha123 image: bash name: echo-object-params - resources: {} ``` #### Extra Parameters @@ -353,50 +348,6 @@ case is when your CI system autogenerates `TaskRuns` and it has `Parameters` it provide to all `TaskRuns`. Because you can pass in extra `Parameters`, you don't have to go through the complexity of checking each `Task` and providing only the required params. -### Specifying `Resources` - -> :warning: **`PipelineResources` are [deprecated](deprecations.md#deprecation-table).** -> -> Consider using replacement features instead. Read more in [documentation](migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks) -> and [TEP-0074](https://github.com/tektoncd/community/blob/main/teps/0074-deprecate-pipelineresources.md). - -If a `Task` requires [`Resources`](tasks.md#specifying-resources) (that is, `inputs` and `outputs`) you must -specify them in your `TaskRun` definition. You can specify `Resources` by reference to existing -[`PipelineResource` objects](resources.md) or embed their definitions directly in the `TaskRun`. - -**Note:** A `TaskRun` can use *either* a referenced *or* an embedded `Resource` but not both simultaneously. - -Below is an example of specifying `Resources` by reference: - -```yaml -spec: - resources: - inputs: - - name: workspace - resourceRef: - name: java-git-resource - outputs: - - name: image - resourceRef: - name: my-app-image -``` - -And here is an example of specifying `Resources` by embedding their definitions: - -```yaml -spec: - resources: - inputs: - - name: workspace - resourceSpec: - type: git - params: - - name: url - value: https://github.com/pivotal-nader-ziada/gohelloworld -``` - -**Note:** You can use the `paths` field to [override the paths to a `Resource`](resources.md#overriding-where-resources-are-copied-from). - ### Specifying `Resource` limits Each Step in a Task can specify its resource requirements. See diff --git a/docs/variables.md b/docs/variables.md index 96b262531d2..7a831c08921 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -55,8 +55,6 @@ For instructions on using variable substitutions see the relevant section of [th | `params[''][i]` | (see above) | | `params[""][i]` | (see above) | | `params..` | Get the value of an individual child of an object param. This is alpha feature, set `enable-api-fields` to `alpha` to use it. | -| `resources.inputs..path` | The path to the input resource's directory. | -| `resources.outputs..path` | The path to the output resource's directory. | | `results..path` | The path to the file where the `Task` writes its results data. | | `results[''].path` | (see above) | | `results[""].path` | (see above) | @@ -73,41 +71,6 @@ For instructions on using variable substitutions see the relevant section of [th | `steps.step-.exitCode.path` | The path to the file where a Step's exit code is stored. | | `steps.step-unnamed-.exitCode.path` | The path to the file where a Step's exit code is stored for a step without any name. | -### `PipelineResource` variables available in a `Task` - -> :warning: **`PipelineResources` are [deprecated](deprecations.md#deprecation-table).** -> -> Consider using replacement features instead. Read more in [documentation](migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks) -> and [TEP-0074](https://github.com/tektoncd/community/blob/main/teps/0074-deprecate-pipelineresources.md). - -Each supported type of `PipelineResource` specified within a `Task` exposes a unique set -of variables. This section lists the variables exposed by each type. You can access a -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 `GCS` type - -| Variable | Description | -| -------- | ----------- | -| `name` | The name of the resource. | -| `type` | Type value of `"gcs"`. | -| `location` | The fully qualified address of the blob storage. | - ## Fields that accept variable substitutions | CRD | Field | 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/hack/update-codegen.sh b/hack/update-codegen.sh index 5336a86826d..83bb68d4788 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -32,14 +32,6 @@ GOFLAGS="-mod=vendor" # --output-base because this script should also be able to run inside the vendor dir of # k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir # instead of the $GOPATH directly. For normal projects this can be dropped. -# This generates deepcopy,client,informer and lister for the resource package (v1alpha1) -# This is separate from the pipeline package as resource are staying in v1alpha1 and they -# need to be separated (at least in terms of go package) from the pipeline's packages to -# not having dependency cycle. -bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \ - github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \ - "resource:v1alpha1" \ - --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt # This generates deepcopy,client,informer and lister for the pipeline package (v1alpha1, v1beta1, and v1) bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \ @@ -72,23 +64,12 @@ ${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 \ -i github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1 # Knative Injection -# This generates the knative injection packages for the resource package (v1alpha1). -# This is separate from the pipeline package for the same reason as client and all (see above). -bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \ - github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \ - "resource:v1alpha1" \ - --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt # This generates the knative inject packages for the pipeline package (v1alpha1, v1beta1, v1). bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \ github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \ diff --git a/hack/update-openapigen.sh b/hack/update-openapigen.sh index f47748b9b1c..2b1a5274955 100755 --- a/hack/update-openapigen.sh +++ b/hack/update-openapigen.sh @@ -39,7 +39,7 @@ do input_dirs=./pkg/apis/pipeline/${APIVERSION},./pkg/apis/pipeline/pod,knative.dev/pkg/apis,knative.dev/pkg/apis/duck/v1beta1 if [ ${APIVERSION} = "v1beta1" ] then - input_dirs=${input_dirs},./pkg/apis/resource/v1alpha1,./pkg/apis/resolution/v1beta1 + input_dirs=${input_dirs},./pkg/apis/resolution/v1beta1 fi echo "Generating OpenAPI specification for ${APIVERSION} ..." 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/images.go b/pkg/apis/pipeline/images.go index 0e904183ba5..ae3127ca734 100644 --- a/pkg/apis/pipeline/images.go +++ b/pkg/apis/pipeline/images.go @@ -30,14 +30,10 @@ type Images struct { SidecarLogResultsImage string // NopImage is the container image used to kill sidecars. NopImage string - // GitImage is the container image with Git that we use to implement the Git source step. - GitImage string // ShellImage is the container image containing bash shell. ShellImage string // ShellImageWin is the container image containing powershell. ShellImageWin string - // GsutilImage is the container image containing gsutil. - GsutilImage string // WorkingDirInitImage is the container image containing our working dir init binary. WorkingDirInitImage string @@ -53,10 +49,8 @@ func (i Images) Validate() error { {i.EntrypointImage, "entrypoint-image"}, {i.SidecarLogResultsImage, "sidecarlogresults-image"}, {i.NopImage, "nop-image"}, - {i.GitImage, "git-image"}, {i.ShellImage, "shell-image"}, {i.ShellImageWin, "shell-image-win"}, - {i.GsutilImage, "gsutil-image"}, {i.WorkingDirInitImage, "workingdirinit-image"}, } { if f.v == "" { diff --git a/pkg/apis/pipeline/images_test.go b/pkg/apis/pipeline/images_test.go index 109c95528e1..0f383a96a56 100644 --- a/pkg/apis/pipeline/images_test.go +++ b/pkg/apis/pipeline/images_test.go @@ -11,10 +11,8 @@ func TestValidate(t *testing.T) { EntrypointImage: "set", SidecarLogResultsImage: "set", NopImage: "set", - GitImage: "set", ShellImage: "set", ShellImageWin: "set", - GsutilImage: "set", WorkingDirInitImage: "set", } if err := valid.Validate(); err != nil { @@ -25,12 +23,10 @@ func TestValidate(t *testing.T) { EntrypointImage: "set", SidecarLogResultsImage: "set", NopImage: "set", - GitImage: "", // unset! ShellImage: "", // unset! ShellImageWin: "set", - GsutilImage: "set", } - wantErr := "found unset image flags: [git-image shell-image workingdirinit-image]" + wantErr := "found unset image flags: [shell-image workingdirinit-image]" if err := invalid.Validate(); err == nil { t.Error("invalid Images expected error, got nil") } else if err.Error() != wantErr { diff --git a/pkg/apis/pipeline/v1/param_types.go b/pkg/apis/pipeline/v1/param_types.go index 9a4666aeb29..185402b5d9b 100644 --- a/pkg/apis/pipeline/v1/param_types.go +++ b/pkg/apis/pipeline/v1/param_types.go @@ -23,7 +23,6 @@ import ( "regexp" "strings" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/substitution" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -111,10 +110,6 @@ func (pp *ParamSpec) setDefaultsForProperties() { } } -// ResourceParam declares a string value to use for the parameter called Name, and is used in -// the specific context of PipelineResources. -type ResourceParam = resource.ResourceParam - // Param declares an ParamValues to use for the parameter called name. type Param struct { Name string `json:"name"` diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index 0e1a5093f08..9aa3a56b0cf 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -43,18 +43,14 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.CustomRunSpec": schema_pkg_apis_pipeline_v1beta1_CustomRunSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.EmbeddedCustomRunSpec": schema_pkg_apis_pipeline_v1beta1_EmbeddedCustomRunSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.EmbeddedTask": schema_pkg_apis_pipeline_v1beta1_EmbeddedTask(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.InternalTaskModifier": schema_pkg_apis_pipeline_v1beta1_InternalTaskModifier(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Matrix": schema_pkg_apis_pipeline_v1beta1_Matrix(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.MatrixInclude": schema_pkg_apis_pipeline_v1beta1_MatrixInclude(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param": schema_pkg_apis_pipeline_v1beta1_Param(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec": schema_pkg_apis_pipeline_v1beta1_ParamSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamValue": schema_pkg_apis_pipeline_v1beta1_ParamValue(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Pipeline": schema_pkg_apis_pipeline_v1beta1_Pipeline(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineDeclaredResource": schema_pkg_apis_pipeline_v1beta1_PipelineDeclaredResource(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineList": schema_pkg_apis_pipeline_v1beta1_PipelineList(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRef": schema_pkg_apis_pipeline_v1beta1_PipelineRef(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceBinding": schema_pkg_apis_pipeline_v1beta1_PipelineResourceBinding(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceRef": schema_pkg_apis_pipeline_v1beta1_PipelineResourceRef(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceResult": schema_pkg_apis_pipeline_v1beta1_PipelineResourceResult(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResult": schema_pkg_apis_pipeline_v1beta1_PipelineResult(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRun": schema_pkg_apis_pipeline_v1beta1_PipelineRun(ref), @@ -67,11 +63,8 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunTaskRunStatus": schema_pkg_apis_pipeline_v1beta1_PipelineRunTaskRunStatus(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec": schema_pkg_apis_pipeline_v1beta1_PipelineSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTask": schema_pkg_apis_pipeline_v1beta1_PipelineTask(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskInputResource": schema_pkg_apis_pipeline_v1beta1_PipelineTaskInputResource(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata": schema_pkg_apis_pipeline_v1beta1_PipelineTaskMetadata(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskOutputResource": schema_pkg_apis_pipeline_v1beta1_PipelineTaskOutputResource(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskParam": schema_pkg_apis_pipeline_v1beta1_PipelineTaskParam(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskResources": schema_pkg_apis_pipeline_v1beta1_PipelineTaskResources(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskRun": schema_pkg_apis_pipeline_v1beta1_PipelineTaskRun(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskRunSpec": schema_pkg_apis_pipeline_v1beta1_PipelineTaskRunSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineWorkspaceDeclaration": schema_pkg_apis_pipeline_v1beta1_PipelineWorkspaceDeclaration(ref), @@ -89,16 +82,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Task": schema_pkg_apis_pipeline_v1beta1_Task(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskList": schema_pkg_apis_pipeline_v1beta1_TaskList(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef": schema_pkg_apis_pipeline_v1beta1_TaskRef(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResource": schema_pkg_apis_pipeline_v1beta1_TaskResource(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding": schema_pkg_apis_pipeline_v1beta1_TaskResourceBinding(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResources": schema_pkg_apis_pipeline_v1beta1_TaskResources(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResult": schema_pkg_apis_pipeline_v1beta1_TaskResult(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRun": schema_pkg_apis_pipeline_v1beta1_TaskRun(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunDebug": schema_pkg_apis_pipeline_v1beta1_TaskRunDebug(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunInputs": schema_pkg_apis_pipeline_v1beta1_TaskRunInputs(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunList": schema_pkg_apis_pipeline_v1beta1_TaskRunList(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunOutputs": schema_pkg_apis_pipeline_v1beta1_TaskRunOutputs(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunResources": schema_pkg_apis_pipeline_v1beta1_TaskRunResources(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunResult": schema_pkg_apis_pipeline_v1beta1_TaskRunResult(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride": schema_pkg_apis_pipeline_v1beta1_TaskRunSidecarOverride(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSpec": schema_pkg_apis_pipeline_v1beta1_TaskRunSpec(ref), @@ -117,13 +104,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1.ResolutionRequestSpec": schema_pkg_apis_resolution_v1beta1_ResolutionRequestSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1.ResolutionRequestStatus": schema_pkg_apis_resolution_v1beta1_ResolutionRequestStatus(ref), "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1.ResolutionRequestStatusFields": schema_pkg_apis_resolution_v1beta1_ResolutionRequestStatusFields(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResource": schema_pkg_apis_resource_v1alpha1_PipelineResource(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceList": schema_pkg_apis_resource_v1alpha1_PipelineResourceList(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec": schema_pkg_apis_resource_v1alpha1_PipelineResourceSpec(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceStatus": schema_pkg_apis_resource_v1alpha1_PipelineResourceStatus(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.ResourceDeclaration": schema_pkg_apis_resource_v1alpha1_ResourceDeclaration(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.ResourceParam": schema_pkg_apis_resource_v1alpha1_ResourceParam(ref), - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.SecretParam": schema_pkg_apis_resource_v1alpha1_SecretParam(ref), } } @@ -944,12 +924,6 @@ func schema_pkg_apis_pipeline_v1beta1_EmbeddedTask(ref common.ReferenceCallback) Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata"), }, }, - "resources": { - SchemaProps: spec.SchemaProps{ - Description: "Resources is a list input and output resource to run the task Resources are represented in TaskRuns as bindings to instances of PipelineResources.", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResources"), - }, - }, "params": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -1081,77 +1055,7 @@ func schema_pkg_apis_pipeline_v1beta1_EmbeddedTask(ref common.ReferenceCallback) }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Sidecar", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.StepTemplate", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResources", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceDeclaration", "k8s.io/api/core/v1.Volume", "k8s.io/apimachinery/pkg/runtime.RawExtension"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_InternalTaskModifier(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "InternalTaskModifier implements TaskModifier for resources that are built-in to Tekton Pipelines.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "stepsToPrepend": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step"), - }, - }, - }, - }, - }, - "stepsToAppend": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step"), - }, - }, - }, - }, - }, - "volumes": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/api/core/v1.Volume"), - }, - }, - }, - }, - }, - }, - Required: []string{"stepsToPrepend", "stepsToAppend", "volumes"}, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step", "k8s.io/api/core/v1.Volume"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Sidecar", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.StepTemplate", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceDeclaration", "k8s.io/api/core/v1.Volume", "k8s.io/apimachinery/pkg/runtime.RawExtension"}, } } @@ -1442,43 +1346,6 @@ func schema_pkg_apis_pipeline_v1beta1_Pipeline(ref common.ReferenceCallback) com } } -func schema_pkg_apis_pipeline_v1beta1_PipelineDeclaredResource(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineDeclaredResource is used by a Pipeline to declare the types of the PipelineResources that it will required to run and names which can be used to refer to these PipelineResources in PipelineTaskResourceBindings.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name is the name that will be used by the Pipeline to refer to this resource. It does not directly correspond to the name of any PipelineResources Task inputs or outputs, and it does not correspond to the actual names of the PipelineResources that will be bound in the PipelineRun.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Description: "Type is the type of the PipelineResource.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "optional": { - SchemaProps: spec.SchemaProps{ - Description: "Optional declares the resource as optional. optional: true - the resource is considered optional optional: false - the resource is considered required (default/equivalent of not specifying it)", - Type: []string{"boolean"}, - Format: "", - }, - }, - }, - Required: []string{"name", "type"}, - }, - }, - } -} - func schema_pkg_apis_pipeline_v1beta1_PipelineList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -1562,67 +1429,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRef(ref common.ReferenceCallback) } } -func schema_pkg_apis_pipeline_v1beta1_PipelineResourceBinding(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineResourceBinding connects a reference to an instance of a PipelineResource with a PipelineResource dependency that the Pipeline has declared", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name is the name of the PipelineResource in the Pipeline's declaration", - Type: []string{"string"}, - Format: "", - }, - }, - "resourceRef": { - SchemaProps: spec.SchemaProps{ - Description: "ResourceRef is a reference to the instance of the actual PipelineResource that should be used", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceRef"), - }, - }, - "resourceSpec": { - SchemaProps: spec.SchemaProps{ - Description: "ResourceSpec is specification of a resource that should be created and consumed by the task", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec"), - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceRef", "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_PipelineResourceRef(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineResourceRef can be used to refer to a specific instance of a Resource", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "API version of the referent", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - } -} - func schema_pkg_apis_pipeline_v1beta1_PipelineResourceResult(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -1899,25 +1705,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRunSpec(ref common.ReferenceCallba Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec"), }, }, - "resources": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Resources is a list of bindings specifying which actual instances of PipelineResources to use for the resources the Pipeline has declared it needs.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceBinding"), - }, - }, - }, - }, - }, "params": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -2010,7 +1797,7 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRunSpec(ref common.ReferenceCallba }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceBinding", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskRunSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TimeoutFields", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceBinding", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskRunSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TimeoutFields", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceBinding", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, } } @@ -2354,25 +2141,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineSpec(ref common.ReferenceCallback) Format: "", }, }, - "resources": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Resources declares the names and types of the resources given to the Pipeline's tasks as inputs and outputs.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineDeclaredResource"), - }, - }, - }, - }, - }, "tasks": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -2472,7 +2240,7 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineSpec(ref common.ReferenceCallback) }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineDeclaredResource", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTask", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineWorkspaceDeclaration"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTask", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineWorkspaceDeclaration"}, } } @@ -2543,12 +2311,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineTask(ref common.ReferenceCallback) }, }, }, - "resources": { - SchemaProps: spec.SchemaProps{ - Description: "Resources declares the resources given to this task as inputs and outputs.", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskResources"), - }, - }, "params": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -2603,57 +2365,7 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineTask(ref common.ReferenceCallback) }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.EmbeddedTask", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Matrix", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskResources", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WhenExpression", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspacePipelineTaskBinding", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_PipelineTaskInputResource(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineTaskInputResource maps the name of a declared PipelineResource input dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources that should be used. This input may come from a previous task.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name is the name of the PipelineResource as declared by the Task.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "resource": { - SchemaProps: spec.SchemaProps{ - Description: "Resource is the name of the DeclaredPipelineResource to use.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "from": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "From is the list of PipelineTask names that the resource has to come from. (Implies an ordering in the execution graph.)", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - }, - Required: []string{"name", "resource"}, - }, - }, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.EmbeddedTask", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Matrix", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WhenExpression", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspacePipelineTaskBinding", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, } } @@ -2700,36 +2412,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineTaskMetadata(ref common.ReferenceC } } -func schema_pkg_apis_pipeline_v1beta1_PipelineTaskOutputResource(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineTaskOutputResource maps the name of a declared PipelineResource output dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources that should be used.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name is the name of the PipelineResource as declared by the Task.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "resource": { - SchemaProps: spec.SchemaProps{ - Description: "Resource is the name of the DeclaredPipelineResource to use.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"name", "resource"}, - }, - }, - } -} - func schema_pkg_apis_pipeline_v1beta1_PipelineTaskParam(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -2758,64 +2440,11 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineTaskParam(ref common.ReferenceCall } } -func schema_pkg_apis_pipeline_v1beta1_PipelineTaskResources(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1beta1_PipelineTaskRun(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources should be provided to a Task as its inputs and outputs.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "inputs": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Inputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskInputResource"), - }, - }, - }, - }, - }, - "outputs": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Outputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskOutputResource"), - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskInputResource", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskOutputResource"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_PipelineTaskRun(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineTaskRun reports the results of running a step in the Task. Each task has the potential to succeed or fail (based on the exit code) and produces logs.", + Description: "PipelineTaskRun reports the results of running a step in the Task. Each task has the potential to succeed or fail (based on the exit code) and produces logs.", Type: []string{"object"}, Properties: map[string]spec.Schema{ "name": { @@ -4248,164 +3877,6 @@ func schema_pkg_apis_pipeline_v1beta1_TaskRef(ref common.ReferenceCallback) comm } } -func schema_pkg_apis_pipeline_v1beta1_TaskResource(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TaskResource defines an input or output Resource declared as a requirement by a Task. The Name field will be used to refer to these Resources within the Task definition, and when provided as an Input, the Name will be the path to the volume mounted containing this Resource as an input (e.g. an input Resource named `workspace` will be mounted at `/workspace`).", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name declares the name by which a resource is referenced in the definition. Resources may be referenced by name in the definition of a Task's steps.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Description: "Type is the type of this resource;", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "description": { - SchemaProps: spec.SchemaProps{ - Description: "Description is a user-facing description of the declared resource that may be used to populate a UI.", - Type: []string{"string"}, - Format: "", - }, - }, - "targetPath": { - SchemaProps: spec.SchemaProps{ - Description: "TargetPath is the path in workspace directory where the resource will be copied.", - Type: []string{"string"}, - Format: "", - }, - }, - "optional": { - SchemaProps: spec.SchemaProps{ - Description: "Optional declares the resource as optional. By default optional is set to false which makes a resource required. optional: true - the resource is considered optional optional: false - the resource is considered required (equivalent of not specifying it)", - Type: []string{"boolean"}, - Format: "", - }, - }, - }, - Required: []string{"name", "type"}, - }, - }, - } -} - -func schema_pkg_apis_pipeline_v1beta1_TaskResourceBinding(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TaskResourceBinding points to the PipelineResource that will be used for the Task input or output called Name.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name is the name of the PipelineResource in the Pipeline's declaration", - Type: []string{"string"}, - Format: "", - }, - }, - "resourceRef": { - SchemaProps: spec.SchemaProps{ - Description: "ResourceRef is a reference to the instance of the actual PipelineResource that should be used", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceRef"), - }, - }, - "resourceSpec": { - SchemaProps: spec.SchemaProps{ - Description: "ResourceSpec is specification of a resource that should be created and consumed by the task", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec"), - }, - }, - "paths": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Paths will probably be removed in #1284, and then PipelineResourceBinding can be used instead. The optional Path field corresponds to a path on disk at which the Resource can be found (used when providing the resource via mounted volume, overriding the default logic to fetch the Resource).", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineResourceRef", "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_TaskResources(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TaskResources allows a Pipeline to declare how its DeclaredPipelineResources should be provided to a Task as its inputs and outputs.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "inputs": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Inputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResource"), - }, - }, - }, - }, - }, - "outputs": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Outputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResource"), - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResource"}, - } -} - func schema_pkg_apis_pipeline_v1beta1_TaskResult(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -4538,57 +4009,6 @@ func schema_pkg_apis_pipeline_v1beta1_TaskRunDebug(ref common.ReferenceCallback) } } -func schema_pkg_apis_pipeline_v1beta1_TaskRunInputs(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TaskRunInputs holds the input values that this task was invoked with.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "resources": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"), - }, - }, - }, - }, - }, - "params": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"), - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"}, - } -} - func schema_pkg_apis_pipeline_v1beta1_TaskRunList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -4638,135 +4058,49 @@ func schema_pkg_apis_pipeline_v1beta1_TaskRunList(ref common.ReferenceCallback) } } -func schema_pkg_apis_pipeline_v1beta1_TaskRunOutputs(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1beta1_TaskRunResult(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "TaskRunOutputs holds the output values that this task was invoked with.", + Description: "TaskRunResult used to describe the results of a task", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "resources": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name the given name", + Default: "", + Type: []string{"string"}, + Format: "", }, + }, + "type": { SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"), - }, - }, - }, + Description: "Type is the user-specified type of the result. The possible type is currently \"string\" and will support \"array\" in following work.", + Type: []string{"string"}, + Format: "", + }, + }, + "value": { + SchemaProps: spec.SchemaProps{ + Description: "Value the given value of the result", + Default: map[string]interface{}{}, + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamValue"), }, }, }, + Required: []string{"name", "value"}, }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamValue"}, } } -func schema_pkg_apis_pipeline_v1beta1_TaskRunResources(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1beta1_TaskRunSidecarOverride(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "TaskRunResources allows a TaskRun to declare inputs and outputs TaskResourceBinding", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "inputs": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Inputs holds the inputs resources this task was invoked with", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"), - }, - }, - }, - }, - }, - "outputs": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Outputs holds the inputs resources this task was invoked with", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"), - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResourceBinding"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_TaskRunResult(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TaskRunResult used to describe the results of a task", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name the given name", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Description: "Type is the user-specified type of the result. The possible type is currently \"string\" and will support \"array\" in following work.", - Type: []string{"string"}, - Format: "", - }, - }, - "value": { - SchemaProps: spec.SchemaProps{ - Description: "Value the given value of the result", - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamValue"), - }, - }, - }, - Required: []string{"name", "value"}, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamValue"}, - } -} - -func schema_pkg_apis_pipeline_v1beta1_TaskRunSidecarOverride(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TaskRunSidecarOverride is used to override the values of a Sidecar in the corresponding Task.", + Description: "TaskRunSidecarOverride is used to override the values of a Sidecar in the corresponding Task.", Type: []string{"object"}, Properties: map[string]spec.Schema{ "name": { @@ -4823,11 +4157,6 @@ func schema_pkg_apis_pipeline_v1beta1_TaskRunSpec(ref common.ReferenceCallback) }, }, }, - "resources": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunResources"), - }, - }, "serviceAccountName": { SchemaProps: spec.SchemaProps{ Default: "", @@ -4946,7 +4275,7 @@ func schema_pkg_apis_pipeline_v1beta1_TaskRunSpec(ref common.ReferenceCallback) }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunDebug", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunResources", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceBinding", "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunDebug", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceBinding", "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, } } @@ -5387,12 +4716,6 @@ func schema_pkg_apis_pipeline_v1beta1_TaskSpec(ref common.ReferenceCallback) com Description: "TaskSpec defines the desired state of Task.", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "resources": { - SchemaProps: spec.SchemaProps{ - Description: "Resources is a list input and output resource to run the task Resources are represented in TaskRuns as bindings to instances of PipelineResources.", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResources"), - }, - }, "params": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -5524,7 +4847,7 @@ func schema_pkg_apis_pipeline_v1beta1_TaskSpec(ref common.ReferenceCallback) com }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Sidecar", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.StepTemplate", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResources", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceDeclaration", "k8s.io/api/core/v1.Volume"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Sidecar", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Step", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.StepTemplate", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceDeclaration", "k8s.io/api/core/v1.Volume"}, } } @@ -6034,292 +5357,3 @@ func schema_pkg_apis_resolution_v1beta1_ResolutionRequestStatusFields(ref common "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ConfigSource"}, } } - -func schema_pkg_apis_resource_v1alpha1_PipelineResource(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineResource describes a resource that is an input to or output from a Task.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Description: "Spec holds the desired state of the PipelineResource from the client", - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec"), - }, - }, - "status": { - SchemaProps: spec.SchemaProps{ - Description: "Status is used to communicate the observed state of the PipelineResource from the controller, but was unused as there is no controller for PipelineResource.\n\nDeprecated: Deprecated in v0.30.0.", - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceStatus"), - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceSpec", "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResourceStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_resource_v1alpha1_PipelineResourceList(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineResourceList contains a list of PipelineResources", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), - }, - }, - "items": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResource"), - }, - }, - }, - }, - }, - }, - Required: []string{"items"}, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.PipelineResource", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, - } -} - -func schema_pkg_apis_resource_v1alpha1_PipelineResourceSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineResourceSpec defines an individual resources used in the pipeline.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "description": { - SchemaProps: spec.SchemaProps{ - Description: "Description is a user-facing description of the resource that may be used to populate a UI.", - Type: []string{"string"}, - Format: "", - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "params": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.ResourceParam"), - }, - }, - }, - }, - }, - "secrets": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Secrets to fetch to populate some of resource fields", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.SecretParam"), - }, - }, - }, - }, - }, - }, - Required: []string{"type", "params"}, - }, - }, - Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.ResourceParam", "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1.SecretParam"}, - } -} - -func schema_pkg_apis_resource_v1alpha1_PipelineResourceStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PipelineResourceStatus does not contain anything because PipelineResources on their own do not have a status\n\nDeprecated: Deprecated in v0.30.0.", - Type: []string{"object"}, - }, - }, - } -} - -func schema_pkg_apis_resource_v1alpha1_ResourceDeclaration(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "ResourceDeclaration defines an input or output PipelineResource declared as a requirement by another type such as a Task or Condition. The Name field will be used to refer to these PipelineResources within the type's definition, and when provided as an Input, the Name will be the path to the volume mounted containing this PipelineResource as an input (e.g. an input Resource named `workspace` will be mounted at `/workspace`).", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name declares the name by which a resource is referenced in the definition. Resources may be referenced by name in the definition of a Task's steps.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Description: "Type is the type of this resource;", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "description": { - SchemaProps: spec.SchemaProps{ - Description: "Description is a user-facing description of the declared resource that may be used to populate a UI.", - Type: []string{"string"}, - Format: "", - }, - }, - "targetPath": { - SchemaProps: spec.SchemaProps{ - Description: "TargetPath is the path in workspace directory where the resource will be copied.", - Type: []string{"string"}, - Format: "", - }, - }, - "optional": { - SchemaProps: spec.SchemaProps{ - Description: "Optional declares the resource as optional. By default optional is set to false which makes a resource required. optional: true - the resource is considered optional optional: false - the resource is considered required (equivalent of not specifying it)", - Type: []string{"boolean"}, - Format: "", - }, - }, - }, - Required: []string{"name", "type"}, - }, - }, - } -} - -func schema_pkg_apis_resource_v1alpha1_ResourceParam(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "ResourceParam declares a string value to use for the parameter called Name, and is used in the specific context of PipelineResources.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "value": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"name", "value"}, - }, - }, - } -} - -func schema_pkg_apis_resource_v1alpha1_SecretParam(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "SecretParam indicates which secret can be used to populate a field of the resource", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "fieldName": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "secretKey": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "secretName": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"fieldName", "secretKey", "secretName"}, - }, - }, - } -} diff --git a/pkg/apis/pipeline/v1beta1/param_types.go b/pkg/apis/pipeline/v1beta1/param_types.go index 5547bbdddbb..b187f401557 100644 --- a/pkg/apis/pipeline/v1beta1/param_types.go +++ b/pkg/apis/pipeline/v1beta1/param_types.go @@ -22,7 +22,6 @@ import ( "fmt" "strings" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/substitution" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -104,10 +103,6 @@ func (pp *ParamSpec) setDefaultsForProperties() { } } -// ResourceParam declares a string value to use for the parameter called Name, and is used in -// the specific context of PipelineResources. -type ResourceParam = resource.ResourceParam - // Param declares an ParamValues to use for the parameter called name. type Param struct { Name string `json:"name"` diff --git a/pkg/apis/pipeline/v1beta1/pipeline_conversion.go b/pkg/apis/pipeline/v1beta1/pipeline_conversion.go index 992d738d146..a48ecbe25d5 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_conversion.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_conversion.go @@ -21,8 +21,6 @@ import ( "fmt" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/version" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" ) @@ -36,9 +34,6 @@ func (p *Pipeline) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { case *v1.Pipeline: sink.ObjectMeta = p.ObjectMeta - if err := serializePipelineResources(&sink.ObjectMeta, &p.Spec); err != nil { - return err - } return p.Spec.ConvertTo(ctx, &sink.Spec) default: return fmt.Errorf("unknown version, got: %T", sink) @@ -92,9 +87,6 @@ func (p *Pipeline) ConvertFrom(ctx context.Context, from apis.Convertible) error switch source := from.(type) { case *v1.Pipeline: p.ObjectMeta = source.ObjectMeta - if err := deserializePipelineResources(&p.ObjectMeta, &p.Spec); err != nil { - return err - } return p.Spec.ConvertFrom(ctx, &source.Spec) default: return fmt.Errorf("unknown version, got: %T", p) @@ -304,22 +296,3 @@ func (ptm *PipelineTaskMetadata) convertFrom(ctx context.Context, source v1.Pipe ptm.Labels = source.Labels ptm.Annotations = source.Labels } - -func serializePipelineResources(meta *metav1.ObjectMeta, spec *PipelineSpec) error { - if spec.Resources == nil { - return nil - } - return version.SerializeToMetadata(meta, spec.Resources, resourcesAnnotationKey) -} - -func deserializePipelineResources(meta *metav1.ObjectMeta, spec *PipelineSpec) error { - resources := &[]PipelineDeclaredResource{} - err := version.DeserializeFromMetadata(meta, resources, resourcesAnnotationKey) - if err != nil { - return err - } - if len(*resources) != 0 { - spec.Resources = *resources - } - return nil -} diff --git a/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go b/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go index d826acd345b..70fda8f3ef2 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go @@ -170,71 +170,3 @@ func TestPipelineConversion(t *testing.T) { } } } - -func TestPipelineConversionFromDeprecated(t *testing.T) { - tests := []struct { - name string - in *v1beta1.Pipeline - want *v1beta1.Pipeline - }{{ - name: "pipeline resources", - in: &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{ - { - Name: "1st pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, - Optional: true, - }, { - Name: "2nd pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, - Optional: false, - }, - }, - }}, - want: &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{ - { - Name: "1st pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, - Optional: true, - }, { - Name: "2nd pipeline resource", - Type: v1beta1.PipelineResourceTypeGit, - Optional: false, - }, - }, - }, - }, - }} - - for _, test := range tests { - versions := []apis.Convertible{&v1.Pipeline{}} - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - t.Logf("ConvertTo() = %#v", ver) - got := &v1beta1.Pipeline{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - t.Logf("ConvertFrom() = %#v", got) - if d := cmp.Diff(test.want, got); d != "" { - t.Errorf("roundtrip %s", diff.PrintWantGot(d)) - } - }) - } - } -} diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types.go b/pkg/apis/pipeline/v1beta1/pipeline_types.go index cd43fd92cc3..7eb54e1c510 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types.go @@ -90,10 +90,6 @@ type PipelineSpec struct { // used to populate a UI. // +optional Description string `json:"description,omitempty"` - // Resources declares the names and types of the resources given to the - // Pipeline's tasks as inputs and outputs. - // +listType=atomic - Resources []PipelineDeclaredResource `json:"resources,omitempty"` // Tasks declares the graph of Tasks that execute when this Pipeline is run. // +listType=atomic Tasks []PipelineTask `json:"tasks,omitempty"` @@ -219,11 +215,6 @@ type PipelineTask struct { // +listType=atomic RunAfter []string `json:"runAfter,omitempty"` - // Resources declares the resources given to this task as inputs and - // outputs. - // +optional - Resources *PipelineTaskResources `json:"resources,omitempty"` - // Parameters declares parameters passed to this task. // +optional // +listType=atomic @@ -273,11 +264,6 @@ func (pt PipelineTask) validateCustomTask() (errs *apis.FieldError) { if pt.TaskSpec != nil && pt.TaskSpec.APIVersion == "" { errs = errs.Also(apis.ErrInvalidValue("custom task spec must specify apiVersion", "taskSpec.apiVersion")) } - - // TODO(#3133): Support these features if possible. - if pt.Resources != nil { - errs = errs.Also(apis.ErrInvalidValue("custom tasks do not support PipelineResources", "resources")) - } return errs } @@ -507,15 +493,6 @@ func (pt PipelineTask) Deps() []string { // hold the list of dependencies in a set to avoid duplicates deps := sets.NewString() - // add any new dependents from a resource/workspace - if pt.Resources != nil { - for _, rd := range pt.Resources.Inputs { - for _, f := range rd.From { - deps.Insert(f) - } - } - } - // add any new dependents from result references - resource dependency for _, ref := range PipelineTaskResultRefs(&pt) { deps.Insert(ref.PipelineTask) @@ -586,61 +563,6 @@ type PipelineTaskParam struct { Value string `json:"value"` } -// PipelineDeclaredResource is used by a Pipeline to declare the types of the -// PipelineResources that it will required to run and names which can be used to -// refer to these PipelineResources in PipelineTaskResourceBindings. -type PipelineDeclaredResource struct { - // Name is the name that will be used by the Pipeline to refer to this resource. - // It does not directly correspond to the name of any PipelineResources Task - // inputs or outputs, and it does not correspond to the actual names of the - // PipelineResources that will be bound in the PipelineRun. - Name string `json:"name"` - // Type is the type of the PipelineResource. - Type PipelineResourceType `json:"type"` - // Optional declares the resource as optional. - // optional: true - the resource is considered optional - // optional: false - the resource is considered required (default/equivalent of not specifying it) - Optional bool `json:"optional,omitempty"` -} - -// PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources -// should be provided to a Task as its inputs and outputs. -type PipelineTaskResources struct { - // Inputs holds the mapping from the PipelineResources declared in - // DeclaredPipelineResources to the input PipelineResources required by the Task. - // +listType=atomic - Inputs []PipelineTaskInputResource `json:"inputs,omitempty"` - // Outputs holds the mapping from the PipelineResources declared in - // DeclaredPipelineResources to the input PipelineResources required by the Task. - // +listType=atomic - Outputs []PipelineTaskOutputResource `json:"outputs,omitempty"` -} - -// PipelineTaskInputResource maps the name of a declared PipelineResource input -// dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources -// that should be used. This input may come from a previous task. -type PipelineTaskInputResource struct { - // Name is the name of the PipelineResource as declared by the Task. - Name string `json:"name"` - // Resource is the name of the DeclaredPipelineResource to use. - Resource string `json:"resource"` - // From is the list of PipelineTask names that the resource has to come from. - // (Implies an ordering in the execution graph.) - // +optional - // +listType=atomic - From []string `json:"from,omitempty"` -} - -// PipelineTaskOutputResource maps the name of a declared PipelineResource output -// dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources -// that should be used. -type PipelineTaskOutputResource struct { - // Name is the name of the PipelineResource as declared by the Task. - Name string `json:"name"` - // Resource is the name of the DeclaredPipelineResource to use. - Resource string `json:"resource"` -} - // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // PipelineList contains a list of Pipeline diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types_test.go b/pkg/apis/pipeline/v1beta1/pipeline_types_test.go index db6a3f30b7b..3c04bb9761b 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types_test.go @@ -170,17 +170,6 @@ func TestPipelineTask_ValidateCustomTask(t *testing.T) { Message: `invalid value: custom task ref must specify apiVersion`, Paths: []string{"taskRef.apiVersion"}, }, - }, { - name: "custom task doesn't support pipeline resources", - task: PipelineTask{ - Name: "foo", - Resources: &PipelineTaskResources{}, - TaskRef: &TaskRef{APIVersion: "example.dev/v0", Kind: "Example"}, - }, - expectedError: apis.FieldError{ - Message: `invalid value: custom tasks do not support PipelineResources`, - Paths: []string{"resources"}, - }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -424,23 +413,6 @@ func TestPipelineTaskList_Deps(t *testing.T) { expectedDeps: map[string][]string{ "task-2": {"task-1"}, }, - }, { - name: "valid pipeline with resource deps - Inputs", - tasks: []PipelineTask{{ - Name: "task-1", - }, { - Name: "task-2", - }, { - Name: "task-3", - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-2"}, - }}, - }}, - }, - expectedDeps: map[string][]string{ - "task-3": {"task-1", "task-2"}, - }, }, { name: "valid pipeline with Task Results deps", tasks: []PipelineTask{{ @@ -491,191 +463,6 @@ func TestPipelineTaskList_Deps(t *testing.T) { expectedDeps: map[string][]string{ "task-2": {"task-1"}, }, - }, { - name: "valid pipeline with ordering deps and resource deps", - tasks: []PipelineTask{{ - Name: "task-1", - }, { - Name: "task-2", RunAfter: []string{"task-1"}, - }, { - Name: "task-3", - RunAfter: []string{"task-1"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-2"}, - }}, - }, - }, { - Name: "task-4", - RunAfter: []string{"task-1"}, - Params: []Param{{ - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-3.results.result)", - }}, - }, - }, { - Name: "task-5", - RunAfter: []string{"task-1"}, - WhenExpressions: WhenExpressions{{ - Input: "$(tasks.task-4.results.result)", - Operator: "in", - Values: []string{"foo"}, - }}, - }, { - Name: "task-6", - RunAfter: []string{"task-1"}, - Matrix: &Matrix{ - Params: []Param{{ - Value: ParamValue{ - Type: ParamTypeArray, - ArrayVal: []string{ - "$(tasks.task-2.results.result)", - "$(tasks.task-5.results.result)", - }, - }}}, - }, - }}, - expectedDeps: map[string][]string{ - "task-2": {"task-1"}, - "task-3": {"task-1", "task-2"}, - "task-4": {"task-1", "task-3"}, - "task-5": {"task-1", "task-4"}, - "task-6": {"task-1", "task-2", "task-5"}, - }, - }, { - name: "valid pipeline with ordering deps and resource deps - verify unique dependencies", - tasks: []PipelineTask{{ - Name: "task-1", - }, { - Name: "task-2", RunAfter: []string{"task-1"}, - }, { - Name: "task-3", - RunAfter: []string{"task-1"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-2"}, - }}, - }, - }, { - Name: "task-4", - RunAfter: []string{"task-1", "task-3"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-2"}, - }}, - }, - Params: []Param{{ - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-2.results.result)", - }}, { - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-3.results.result)", - }}, - }, - }, { - Name: "task-5", - RunAfter: []string{"task-1", "task-2", "task-3", "task-4"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-2"}, - }}, - }, - Params: []Param{{ - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-4.results.result)", - }}, - }, - WhenExpressions: WhenExpressions{{ - Input: "$(tasks.task-3.results.result)", - Operator: "in", - Values: []string{"foo"}, - }, { - Input: "$(tasks.task-4.results.result)", - Operator: "in", - Values: []string{"foo"}, - }}, - }, { - Name: "task-6", - RunAfter: []string{"task-1", "task-2", "task-3", "task-4", "task-5"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-2"}, - }}, - }, - Params: []Param{{ - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-4.results.result)", - }}, - }, - WhenExpressions: WhenExpressions{{ - Input: "$(tasks.task-3.results.result)", - Operator: "in", - Values: []string{"foo"}, - }, { - Input: "$(tasks.task-4.results.result)", - Operator: "in", - Values: []string{"foo"}, - }}, - Matrix: &Matrix{ - Params: []Param{{ - Value: ParamValue{ - Type: ParamTypeArray, - ArrayVal: []string{ - "$(tasks.task-2.results.result)", - "$(tasks.task-5.results.result)", - }, - }}}, - }, - }, { - Name: "task-7", - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - From: []string{"task-1", "task-1"}, - }}, - }, - }, { - Name: "task-8", - WhenExpressions: WhenExpressions{{ - Input: "$(tasks.task-3.results.result1)", - Operator: "in", - Values: []string{"foo"}, - }, { - Input: "$(tasks.task-3.results.result2)", - Operator: "in", - Values: []string{"foo"}, - }}, - }, { - Name: "task-9", - Params: []Param{{ - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-4.results.result1)", - }}, { - Value: ParamValue{ - Type: "string", - StringVal: "$(tasks.task-4.results.result2)", - }}, - }, - }, { - Name: "task-10", - RunAfter: []string{"task-1", "task-1", "task-1", "task-1"}, - }}, - expectedDeps: map[string][]string{ - "task-2": {"task-1"}, - "task-3": {"task-1", "task-2"}, - "task-4": {"task-1", "task-2", "task-3"}, - "task-5": {"task-1", "task-2", "task-3", "task-4"}, - "task-6": {"task-1", "task-2", "task-3", "task-4", "task-5"}, - "task-7": {"task-1"}, - "task-8": {"task-3"}, - "task-9": {"task-4"}, - "task-10": {"task-1"}, - }, }} for _, tc := range pipelines { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation.go b/pkg/apis/pipeline/v1beta1/pipeline_validation.go index b1af8de0c26..dafd748dfbc 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation.go @@ -23,7 +23,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/validate" - "github.com/tektoncd/pipeline/pkg/list" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" "github.com/tektoncd/pipeline/pkg/substitution" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" @@ -57,11 +56,6 @@ func (ps *PipelineSpec) Validate(ctx context.Context) (errs *apis.FieldError) { } // PipelineTask must have a valid unique label and at least one of taskRef or taskSpec should be specified errs = errs.Also(ValidatePipelineTasks(ctx, ps.Tasks, ps.Finally)) - // All declared resources should be used, and the Pipeline shouldn't try to use any resources - // that aren't declared - errs = errs.Also(validateDeclaredResources(ps.Resources, ps.Tasks, ps.Finally)) - // The from values should make sense - errs = errs.Also(validateFrom(ps.Tasks)) // Validate the pipeline task graph errs = errs.Also(validateGraph(ps.Tasks)) // The parameter variables should be valid @@ -350,7 +344,6 @@ func validateFinalTasks(tasks []PipelineTask, finalTasks []PipelineTask) (errs * fts := PipelineTaskList(finalTasks).Names() errs = errs.Also(validateTaskResultReferenceInFinallyTasks(finalTasks, ts, fts)) - errs = errs.Also(validateTasksInputFrom(finalTasks).ViaField("finally")) return errs } @@ -390,22 +383,6 @@ func validateResultsVariablesExpressionsInFinally(expressions []string, pipeline return errs } -func validateTasksInputFrom(tasks []PipelineTask) (errs *apis.FieldError) { - for idx, t := range tasks { - inputResources := []PipelineTaskInputResource{} - if t.Resources != nil { - inputResources = append(inputResources, t.Resources.Inputs...) - } - for i, rd := range inputResources { - if len(rd.From) != 0 { - errs = errs.Also(apis.ErrGeneric(fmt.Sprintf("no from allowed under inputs,"+ - " final task %s has from specified", rd.Name), "").ViaFieldIndex("inputs", i).ViaField("resources").ViaIndex(idx)) - } - } - } - return errs -} - func validateWhenExpressions(tasks []PipelineTask, finalTasks []PipelineTask) (errs *apis.FieldError) { for i, t := range tasks { errs = errs.Also(t.WhenExpressions.validate().ViaFieldIndex("tasks", i)) @@ -416,93 +393,6 @@ func validateWhenExpressions(tasks []PipelineTask, finalTasks []PipelineTask) (e return errs } -// validateDeclaredResources ensures that the specified resources have unique names and -// validates that all the resources referenced by pipeline tasks are declared in the pipeline -func validateDeclaredResources(resources []PipelineDeclaredResource, tasks []PipelineTask, finalTasks []PipelineTask) *apis.FieldError { - encountered := sets.NewString() - for _, r := range resources { - if encountered.Has(r.Name) { - return apis.ErrInvalidValue(fmt.Sprintf("resource with name %q appears more than once", r.Name), "resources") - } - encountered.Insert(r.Name) - } - required := []string{} - for _, t := range tasks { - if t.Resources != nil { - for _, input := range t.Resources.Inputs { - required = append(required, input.Resource) - } - for _, output := range t.Resources.Outputs { - required = append(required, output.Resource) - } - } - } - for _, t := range finalTasks { - if t.Resources != nil { - for _, input := range t.Resources.Inputs { - required = append(required, input.Resource) - } - for _, output := range t.Resources.Outputs { - required = append(required, output.Resource) - } - } - } - - provided := make([]string, 0, len(resources)) - for _, resource := range resources { - provided = append(provided, resource.Name) - } - missing := list.DiffLeft(required, provided) - if len(missing) > 0 { - return apis.ErrInvalidValue(fmt.Sprintf("pipeline declared resources didn't match usage in Tasks: Didn't provide required values: %s", missing), "resources") - } - return nil -} - -func isOutput(outputs []PipelineTaskOutputResource, resource string) bool { - for _, output := range outputs { - if output.Resource == resource { - return true - } - } - return false -} - -// validateFrom ensures that the `from` values make sense: that they rely on values from Tasks -// that ran previously, and that the PipelineResource is actually an output of the Task it should come from. -func validateFrom(tasks []PipelineTask) (errs *apis.FieldError) { - taskOutputs := map[string][]PipelineTaskOutputResource{} - for _, task := range tasks { - var to []PipelineTaskOutputResource - if task.Resources != nil { - to = make([]PipelineTaskOutputResource, len(task.Resources.Outputs)) - copy(to, task.Resources.Outputs) - } - taskOutputs[task.Name] = to - } - for i, t := range tasks { - inputResources := []PipelineTaskInputResource{} - if t.Resources != nil { - inputResources = append(inputResources, t.Resources.Inputs...) - } - - for j, rd := range inputResources { - for _, pt := range rd.From { - outputs, found := taskOutputs[pt] - if !found { - return apis.ErrInvalidValue(fmt.Sprintf("expected resource %s to be from task %s, but task %s doesn't exist", rd.Resource, pt, pt), - "from").ViaFieldIndex("inputs", j).ViaField("resources").ViaFieldIndex("tasks", i) - } - if !isOutput(outputs, rd.Resource) { - return apis.ErrInvalidValue(fmt.Sprintf("the resource %s from %s must be an output but is an input", rd.Resource, pt), - "from").ViaFieldIndex("inputs", j).ViaField("resources").ViaFieldIndex("tasks", i) - } - } - } - } - return errs -} - // validateGraph ensures the Pipeline's dependency Graph (DAG) make sense: that there is no dependency // cycle or that they rely on values from Tasks that ran previously, and that the PipelineResource // is actually an output of the Task it should come from. diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go index 1bc03563ec3..52c28edb6b8 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "testing" - "time" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -72,65 +71,6 @@ func TestPipeline_Validate_Success(t *testing.T) { }}, }, }, - }, { - name: "valid pipeline with params, resources, workspaces, task results, and pipeline results", - p: &Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, - Spec: PipelineSpec{ - Description: "this is a valid pipeline with all possible fields initialized", - Resources: []PipelineDeclaredResource{{ - Name: "app-repo", - Type: "git", - Optional: false, - }, { - Name: "app-image", - Type: "git", - Optional: false, - }}, - Tasks: []PipelineTask{{ - Name: "my-task", - TaskRef: &TaskRef{Name: "foo-task"}, - Retries: 5, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "task-app-repo", - Resource: "app-repo", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "task-app-image", - Resource: "app-image", - }}, - }, - Params: []Param{{ - Name: "param1", - Value: ParamValue{}, - }}, - Workspaces: []WorkspacePipelineTaskBinding{{ - Name: "task-shared-workspace", - Workspace: "shared-workspace", - }}, - Timeout: &metav1.Duration{Duration: 5 * time.Minute}, - }}, - Params: []ParamSpec{{ - Name: "param1", - Type: ParamType("string"), - Description: "this is my param", - Default: &ParamValue{ - Type: ParamType("string"), - StringVal: "pipeline-default", - }, - }}, - Workspaces: []PipelineWorkspaceDeclaration{{ - Name: "shared-workspace", - Description: "this is my shared workspace", - }}, - Results: []PipelineResult{{ - Name: "pipeline-result", - Description: "this is my pipeline result", - Value: *NewStructuredValues("$(tasks.my-task.results.my-result)"), - }}, - }, - }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -656,59 +596,6 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { Message: `missing field(s)`, Paths: []string{"tasks[1].when[0]", "finally[0].when[0]"}, }, - }, { - name: "invalid pipeline with pipeline task having reference to resources which does not exist", - ps: &PipelineSpec{ - Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "wonderful-resource", Type: PipelineResourceTypeGit, - }}, - Tasks: []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "missing-great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-imagee", Resource: "missing-wonderful-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-image", Resource: "wonderful-resource", - }}, - }, - }}, - }, - expectedError: apis.FieldError{ - Message: `invalid value: pipeline declared resources didn't match usage in Tasks: Didn't provide required values: [missing-great-resource missing-wonderful-resource]`, - Paths: []string{"resources"}, - }, - }, { - name: "invalid pipeline spec - from referring to a pipeline task which does not exist", - ps: &PipelineSpec{ - Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }}, - Tasks: []PipelineTask{{ - Name: "baz", TaskRef: &TaskRef{Name: "baz-task"}, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "great-resource", From: []string{"bar"}, - }}, - }, - }}, - }, - expectedError: *apis.ErrGeneric(`invalid value: couldn't add link between foo and bar: task foo depends on bar but bar wasn't present in Pipeline`, "tasks").Also( - apis.ErrInvalidValue("expected resource great-resource to be from task bar, but task bar doesn't exist", "tasks[1].resources.inputs[0].from")), }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -815,284 +702,6 @@ func TestValidatePipelineTasks_Failure(t *testing.T) { } } -func TestValidateFrom_Success(t *testing.T) { - desc := "valid pipeline task - from resource referring to valid output resource of the pipeline task" - tasks := []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-resource", Resource: "some-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "output-resource", Resource: "output-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "wow-image", Resource: "output-resource", From: []string{"bar"}, - }}, - }, - }} - t.Run(desc, func(t *testing.T) { - err := validateFrom(tasks) - if err != nil { - t.Errorf("Pipeline.validateFrom() returned error for: %v", err) - } - }) -} - -func TestValidateFrom_Failure(t *testing.T) { - tests := []struct { - name string - tasks []PipelineTask - expectedError apis.FieldError - }{{ - name: "invalid pipeline task - from in a pipeline with single pipeline task", - tasks: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "great-resource", From: []string{"bar"}, - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: expected resource great-resource to be from task bar, but task bar doesn't exist`, - Paths: []string{"tasks[0].resources.inputs[0].from"}, - }, - }, { - name: "invalid pipeline task - from referencing pipeline task which does not exist", - tasks: []PipelineTask{{ - Name: "baz", TaskRef: &TaskRef{Name: "baz-task"}, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "great-resource", From: []string{"bar"}, - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: expected resource great-resource to be from task bar, but task bar doesn't exist`, - Paths: []string{"tasks[1].resources.inputs[0].from"}, - }, - }, { - name: "invalid pipeline task - from resource referring to a pipeline task which has no output", - tasks: []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-resource", Resource: "great-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "wow-image", Resource: "wonderful-resource", From: []string{"bar"}, - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: the resource wonderful-resource from bar must be an output but is an input`, - Paths: []string{"tasks[1].resources.inputs[0].from"}, - }, - }, { - name: "invalid pipeline task - from resource referring to input resource of the pipeline task instead of output", - tasks: []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-resource", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "output-resource", Resource: "great-output-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "wow-image", Resource: "some-resource", From: []string{"bar"}, - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: the resource some-resource from bar must be an output but is an input`, - Paths: []string{"tasks[1].resources.inputs[0].from"}, - }, - }} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := validateFrom(tt.tasks) - if err == nil { - t.Error("Pipeline.validateFrom() did not return error for invalid pipeline task resources") - } - if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { - t.Errorf("PipelineSpec.Validate() errors diff %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestValidateDeclaredResources_Success(t *testing.T) { - tests := []struct { - name string - resources []PipelineDeclaredResource - tasks []PipelineTask - }{{ - name: "valid resource declarations and usage", - resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "wonderful-resource", Type: PipelineResourceTypeGit, - }}, - tasks: []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-workspace", Resource: "wonderful-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-image", Resource: "wonderful-resource", From: []string{"bar"}, - }}, - }, - }}, - }, { - name: "valid resource declarations with extra resources, not used in any pipeline task", - resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "awesome-resource", Type: PipelineResourceTypeGit, - }, { - Name: "yet-another-great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "yet-another-awesome-resource", Type: PipelineResourceTypeGit, - }}, - tasks: []PipelineTask{{ - 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", - }}, - }, - }}, - }} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := validateDeclaredResources(tt.resources, tt.tasks, []PipelineTask{}) - if err != nil { - t.Errorf("Pipeline.validateDeclaredResources() returned error for valid resource declarations: %v", err) - } - }) - } -} - -func TestValidateDeclaredResources_Failure(t *testing.T) { - tests := []struct { - name string - resources []PipelineDeclaredResource - tasks []PipelineTask - expectedError apis.FieldError - }{{ - name: "duplicate resource declaration - resource declarations must be unique", - resources: []PipelineDeclaredResource{{ - Name: "duplicate-resource", Type: PipelineResourceTypeGit, - }, { - Name: "duplicate-resource", Type: PipelineResourceTypeGit, - }}, - tasks: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "duplicate-resource", - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: resource with name "duplicate-resource" appears more than once`, - Paths: []string{"resources"}, - }, - }, { - name: "output resource is missing from resource declarations", - resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }}, - tasks: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "the-magic-resource", Resource: "missing-resource", - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: pipeline declared resources didn't match usage in Tasks: Didn't provide required values: [missing-resource]`, - Paths: []string{"resources"}, - }, - }, { - name: "input resource is missing from resource declarations", - resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }}, - tasks: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "missing-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "the-magic-resource", Resource: "great-resource", - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `invalid value: pipeline declared resources didn't match usage in Tasks: Didn't provide required values: [missing-resource]`, - Paths: []string{"resources"}, - }, - }} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := validateDeclaredResources(tt.resources, tt.tasks, []PipelineTask{}) - if err == nil { - t.Errorf("Pipeline.validateDeclaredResources() did not return error for invalid resource declarations") - } - if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { - t.Errorf("PipelineSpec.Validate() errors diff %s", diff.PrintWantGot(d)) - } - }) - } -} - func TestValidateGraph_Success(t *testing.T) { desc := "valid dependency graph with multiple tasks" tasks := []PipelineTask{{ @@ -2372,42 +1981,6 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { }}, }, }, - }, { - name: "valid pipeline with resource declarations and their valid usage", - p: &Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, - Spec: PipelineSpec{ - Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "wonderful-resource", Type: PipelineResourceTypeGit, - }}, - Tasks: []PipelineTask{{ - Name: "non-final-task", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-image", Resource: "wonderful-resource", - }}, - }, - }}, - Finally: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-image", Resource: "wonderful-resource", - }}, - }, - }}, - }, - }, }, { name: "valid pipeline with final tasks referring to task results from a dag task", p: &Pipeline{ @@ -2778,21 +2351,6 @@ func TestValidateFinalTasks_Failure(t *testing.T) { Message: `invalid value: no runAfter allowed under spec.finally, final task final-task has runAfter specified`, Paths: []string{"finally[0]"}, }, - }, { - name: "invalid pipeline with final task output resources referring to other task input", - finalTasks: []PipelineTask{{ - Name: "final-task", - TaskRef: &TaskRef{Name: "final-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "final-input-2", Resource: "great-resource", From: []string{"task"}, - }}, - }, - }}, - expectedError: apis.FieldError{ - Message: `no from allowed under inputs, final task final-input-2 has from specified`, - Paths: []string{"finally[0].resources.inputs[0]"}, - }, }, { name: "invalid pipeline with final tasks having task results reference from a final task", finalTasks: []PipelineTask{{ diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_conversion.go b/pkg/apis/pipeline/v1beta1/pipelinerun_conversion.go index 1e0ddf01ab6..68a475233f1 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_conversion.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_conversion.go @@ -21,8 +21,6 @@ import ( "fmt" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/version" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" ) @@ -36,9 +34,6 @@ func (pr *PipelineRun) ConvertTo(ctx context.Context, to apis.Convertible) error switch sink := to.(type) { case *v1.PipelineRun: sink.ObjectMeta = pr.ObjectMeta - if err := serializePipelineRunResources(&sink.ObjectMeta, &pr.Spec); err != nil { - return err - } if err := pr.Status.convertTo(ctx, &sink.Status); err != nil { return err } @@ -99,9 +94,6 @@ func (pr *PipelineRun) ConvertFrom(ctx context.Context, from apis.Convertible) e switch source := from.(type) { case *v1.PipelineRun: pr.ObjectMeta = source.ObjectMeta - if err := deserializePipelineRunResources(&pr.ObjectMeta, &pr.Spec); err != nil { - return err - } if err := pr.Status.convertFrom(ctx, &source.Status); err != nil { return err } @@ -351,22 +343,3 @@ func (csr *ChildStatusReference) convertFrom(ctx context.Context, source v1.Chil csr.WhenExpressions = append(csr.WhenExpressions, new) } } - -func serializePipelineRunResources(meta *metav1.ObjectMeta, spec *PipelineRunSpec) error { - if spec.Resources == nil { - return nil - } - return version.SerializeToMetadata(meta, spec.Resources, resourcesAnnotationKey) -} - -func deserializePipelineRunResources(meta *metav1.ObjectMeta, spec *PipelineRunSpec) error { - resources := []PipelineResourceBinding{} - err := version.DeserializeFromMetadata(meta, &resources, resourcesAnnotationKey) - if err != nil { - return err - } - if len(resources) != 0 { - spec.Resources = resources - } - return nil -} diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go index 6e4e6d8c277..d4b0c94ab22 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go @@ -354,42 +354,6 @@ func TestPipelineRunConversionFromDeprecated(t *testing.T) { in *v1beta1.PipelineRun want *v1beta1.PipelineRun }{{ - name: "resources", - in: &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.PipelineRunSpec{ - Resources: []v1beta1.PipelineResourceBinding{ - { - Name: "git-resource", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "sweet-resource"}, - }, { - Name: "image-resource", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "sweet-resource2"}, - }, - }, - }, - }, - want: &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.PipelineRunSpec{ - Resources: []v1beta1.PipelineResourceBinding{ - { - Name: "git-resource", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "sweet-resource"}, - }, { - Name: "image-resource", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "sweet-resource2"}, - }, - }, - }, - }, - }, { name: "timeout to timeouts", in: &v1beta1.PipelineRun{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go index 609c31ebadd..1d3f84ae665 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go @@ -223,11 +223,6 @@ type PipelineRunSpec struct { PipelineRef *PipelineRef `json:"pipelineRef,omitempty"` // +optional PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"` - // Resources is a list of bindings specifying which actual instances of - // PipelineResources to use for the resources the Pipeline has declared - // it needs. - // +listType=atomic - Resources []PipelineResourceBinding `json:"resources,omitempty"` // Params is a list of parameter names and values. // +listType=atomic Params []Param `json:"params,omitempty"` diff --git a/pkg/apis/pipeline/v1beta1/resource_paths.go b/pkg/apis/pipeline/v1beta1/resource_paths.go deleted file mode 100644 index 260a2ed5f9d..00000000000 --- a/pkg/apis/pipeline/v1beta1/resource_paths.go +++ /dev/null @@ -1,40 +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 v1beta1 - -import "path/filepath" - -// InputResourcePath returns the path where the given input resource -// will get mounted in a Pod -func InputResourcePath(r ResourceDeclaration) string { - return path("/workspace", r) -} - -// OutputResourcePath returns the path to the output resource in a Pod -func OutputResourcePath(r ResourceDeclaration) string { - return path("/workspace/output", r) -} - -func path(root string, r ResourceDeclaration) string { - if r.TargetPath != "" { - if filepath.IsAbs(r.TargetPath) { - return r.TargetPath - } - return filepath.Join("/workspace", r.TargetPath) - } - return filepath.Join(root, r.Name) -} diff --git a/pkg/apis/pipeline/v1beta1/resource_paths_test.go b/pkg/apis/pipeline/v1beta1/resource_paths_test.go deleted file mode 100644 index 346dab77eb5..00000000000 --- a/pkg/apis/pipeline/v1beta1/resource_paths_test.go +++ /dev/null @@ -1,81 +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 v1beta1_test - -import ( - "testing" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" -) - -func TestInputResourcePath(t *testing.T) { - tcs := []struct { - name string - resource v1beta1.ResourceDeclaration - expected string - }{{ - name: "default_path", - resource: v1beta1.ResourceDeclaration{ - Name: "foo", - }, - expected: "/workspace/foo", - }, { - name: "with target path", - resource: v1beta1.ResourceDeclaration{ - Name: "foo", - TargetPath: "bar", - }, - expected: "/workspace/bar", - }} - - for _, tc := range tcs { - t.Run(tc.name, func(t *testing.T) { - if actual := v1beta1.InputResourcePath(tc.resource); actual != tc.expected { - t.Errorf("Unexpected input resource path: %s", actual) - } - }) - } -} - -func TestOutputResourcePath(t *testing.T) { - tcs := []struct { - name string - resource v1beta1.ResourceDeclaration - expected string - }{{ - name: "default_path", - resource: v1beta1.ResourceDeclaration{ - Name: "foo", - }, - expected: "/workspace/output/foo", - }, { - name: "with target path", - resource: v1beta1.ResourceDeclaration{ - Name: "foo", - TargetPath: "bar", - }, - expected: "/workspace/bar", - }} - - for _, tc := range tcs { - t.Run(tc.name, func(t *testing.T) { - if actual := v1beta1.OutputResourcePath(tc.resource); actual != tc.expected { - t.Errorf("Unexpected output resource path: %s", actual) - } - }) - } -} diff --git a/pkg/apis/pipeline/v1beta1/resource_types.go b/pkg/apis/pipeline/v1beta1/resource_types.go index 2658793ab23..5280c62d8fe 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types.go +++ b/pkg/apis/pipeline/v1beta1/resource_types.go @@ -20,100 +20,9 @@ import ( "encoding/json" "fmt" - "github.com/google/go-cmp/cmp" "github.com/hashicorp/go-multierror" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - v1 "k8s.io/api/core/v1" ) -// PipelineResourceType represents the type of endpoint the pipelineResource is, so that the -// controller will know this pipelineResource should be fetched and optionally what -// additional metatdata should be provided for it. -type PipelineResourceType = resource.PipelineResourceType - -var ( - // AllowedOutputResources are the resource types that can be used as outputs - AllowedOutputResources = resource.AllowedOutputResources -) - -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 -) - -// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types. -var AllResourceTypes = resource.AllResourceTypes - -// TaskResources allows a Pipeline to declare how its DeclaredPipelineResources -// should be provided to a Task as its inputs and outputs. -type TaskResources struct { - // Inputs holds the mapping from the PipelineResources declared in - // DeclaredPipelineResources to the input PipelineResources required by the Task. - // +listType=atomic - Inputs []TaskResource `json:"inputs,omitempty"` - // Outputs holds the mapping from the PipelineResources declared in - // DeclaredPipelineResources to the input PipelineResources required by the Task. - // +listType=atomic - Outputs []TaskResource `json:"outputs,omitempty"` -} - -// TaskResource defines an input or output Resource declared as a requirement -// by a Task. The Name field will be used to refer to these Resources within -// the Task definition, and when provided as an Input, the Name will be the -// path to the volume mounted containing this Resource as an input (e.g. -// an input Resource named `workspace` will be mounted at `/workspace`). -type TaskResource struct { - ResourceDeclaration `json:",inline"` -} - -// TaskRunResources allows a TaskRun to declare inputs and outputs TaskResourceBinding -type TaskRunResources struct { - // Inputs holds the inputs resources this task was invoked with - // +listType=atomic - Inputs []TaskResourceBinding `json:"inputs,omitempty"` - // Outputs holds the inputs resources this task was invoked with - // +listType=atomic - Outputs []TaskResourceBinding `json:"outputs,omitempty"` -} - -// TaskResourceBinding points to the PipelineResource that -// will be used for the Task input or output called Name. -type TaskResourceBinding struct { - PipelineResourceBinding `json:",inline"` - // Paths will probably be removed in #1284, and then PipelineResourceBinding can be used instead. - // The optional Path field corresponds to a path on disk at which the Resource can be found - // (used when providing the resource via mounted volume, overriding the default logic to fetch the Resource). - // +optional - // +listType=atomic - Paths []string `json:"paths,omitempty"` -} - -// ResourceDeclaration defines an input or output PipelineResource declared as a requirement -// by another type such as a Task or Condition. The Name field will be used to refer to these -// PipelineResources within the type's definition, and when provided as an Input, the Name will be the -// path to the volume mounted containing this PipelineResource as an input (e.g. -// an input Resource named `workspace` will be mounted at `/workspace`). -type ResourceDeclaration = resource.ResourceDeclaration - -// PipelineResourceBinding connects a reference to an instance of a PipelineResource -// with a PipelineResource dependency that the Pipeline has declared -type PipelineResourceBinding struct { - // Name is the name of the PipelineResource in the Pipeline's declaration - Name string `json:"name,omitempty"` - // ResourceRef is a reference to the instance of the actual PipelineResource - // that should be used - // +optional - ResourceRef *PipelineResourceRef `json:"resourceRef,omitempty"` - - // ResourceSpec is specification of a resource that should be created and - // consumed by the task - // +optional - ResourceSpec *resource.PipelineResourceSpec `json:"resourceSpec,omitempty"` -} - // PipelineResourceResult used to export the image name and digest as json type PipelineResourceResult struct { Key string `json:"key"` @@ -164,112 +73,3 @@ func (r *ResultType) UnmarshalJSON(data []byte) error { return nil } - -// PipelineResourceRef can be used to refer to a specific instance of a Resource -type PipelineResourceRef struct { - // Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names - Name string `json:"name,omitempty"` - // API version of the referent - // +optional - APIVersion string `json:"apiVersion,omitempty"` -} - -// PipelineResourceInterface interface to be implemented by different PipelineResource types -type PipelineResourceInterface interface { - // GetName returns the name of this PipelineResource instance. - GetName() string - // GetType returns the type of this PipelineResource (often a super type, e.g. in the case of storage). - GetType() PipelineResourceType - // Replacements returns all the attributes that this PipelineResource has that - // can be used for variable replacement. - Replacements() map[string]string - // GetOutputTaskModifier returns the TaskModifier instance that should be used on a Task - // in order to add this kind of resource when it is being used as an output. - GetOutputTaskModifier(ts *TaskSpec, path string) (TaskModifier, error) - // GetInputTaskModifier returns the TaskModifier instance that should be used on a Task - // in order to add this kind of resource when it is being used as an input. - GetInputTaskModifier(ts *TaskSpec, path string) (TaskModifier, error) -} - -// TaskModifier is an interface to be implemented by different PipelineResources -type TaskModifier interface { - GetStepsToPrepend() []Step - GetStepsToAppend() []Step - GetVolumes() []v1.Volume -} - -// InternalTaskModifier implements TaskModifier for resources that are built-in to Tekton Pipelines. -type InternalTaskModifier struct { - // +listType=atomic - StepsToPrepend []Step `json:"stepsToPrepend"` - // +listType=atomic - StepsToAppend []Step `json:"stepsToAppend"` - // +listType=atomic - Volumes []v1.Volume `json:"volumes"` -} - -// GetStepsToPrepend returns a set of Steps to prepend to the Task. -func (tm *InternalTaskModifier) GetStepsToPrepend() []Step { - return tm.StepsToPrepend -} - -// GetStepsToAppend returns a set of Steps to append to the Task. -func (tm *InternalTaskModifier) GetStepsToAppend() []Step { - return tm.StepsToAppend -} - -// GetVolumes returns a set of Volumes to prepend to the Task pod. -func (tm *InternalTaskModifier) GetVolumes() []v1.Volume { - return tm.Volumes -} - -// ApplyTaskModifier applies a modifier to the task by appending and prepending steps and volumes. -// If steps with the same name exist in ts an error will be returned. If identical Volumes have -// been added, they will not be added again. If Volumes with the same name but different contents -// have been added, an error will be returned. -func ApplyTaskModifier(ts *TaskSpec, tm TaskModifier) error { - steps := tm.GetStepsToPrepend() - for _, step := range steps { - if err := checkStepNotAlreadyAdded(step, ts.Steps); err != nil { - return err - } - } - ts.Steps = append(steps, ts.Steps...) - - steps = tm.GetStepsToAppend() - for _, step := range steps { - if err := checkStepNotAlreadyAdded(step, ts.Steps); err != nil { - return err - } - } - ts.Steps = append(ts.Steps, steps...) - - volumes := tm.GetVolumes() - for _, volume := range volumes { - var alreadyAdded bool - for _, v := range ts.Volumes { - if volume.Name == v.Name { - // If a Volume with the same name but different contents has already been added, we can't add both - if d := cmp.Diff(volume, v); d != "" { - return fmt.Errorf("tried to add volume %s already added but with different contents", volume.Name) - } - // If an identical Volume has already been added, don't add it again - alreadyAdded = true - } - } - if !alreadyAdded { - ts.Volumes = append(ts.Volumes, volume) - } - } - - return nil -} - -func checkStepNotAlreadyAdded(s Step, steps []Step) error { - for _, step := range steps { - if s.Name == step.Name { - return fmt.Errorf("Step %s cannot be added again", step.Name) - } - } - return nil -} diff --git a/pkg/apis/pipeline/v1beta1/resource_types_test.go b/pkg/apis/pipeline/v1beta1/resource_types_test.go index 27de5af798c..cdd9afc6b3d 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types_test.go +++ b/pkg/apis/pipeline/v1beta1/resource_types_test.go @@ -58,88 +58,6 @@ func (tm *TestTaskModifier) GetVolumes() []corev1.Volume { return []corev1.Volume{volume} } -func TestApplyTaskModifier(t *testing.T) { - testcases := []struct { - name string - ts v1beta1.TaskSpec - }{{ - name: "success", - ts: v1beta1.TaskSpec{}, - }, { - name: "identical volume already added", - ts: v1beta1.TaskSpec{ - // Trying to add the same Volume that has already been added shouldn't be an error - // and it should not be added twice - Volumes: []corev1.Volume{volume}, - }, - }} - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - if err := v1beta1.ApplyTaskModifier(&tc.ts, &TestTaskModifier{}); err != nil { - t.Fatalf("Did not expect error modifying TaskSpec but got %v", err) - } - - expectedTaskSpec := v1beta1.TaskSpec{ - Steps: []v1beta1.Step{ - prependStep, - appendStep, - }, - Volumes: []corev1.Volume{ - volume, - }, - } - - if d := cmp.Diff(expectedTaskSpec, tc.ts); d != "" { - t.Errorf("TaskSpec was not modified as expected %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestApplyTaskModifier_AlreadyAdded(t *testing.T) { - testcases := []struct { - name string - ts v1beta1.TaskSpec - }{{ - name: "prepend already added", - ts: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{prependStep}, - }, - }, { - name: "append already added", - ts: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{appendStep}, - }, - }, { - name: "both steps already added", - ts: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{prependStep, appendStep}, - }, - }, { - name: "both steps already added reverse order", - ts: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{appendStep, prependStep}, - }, - }, { - name: "volume with same name but diff content already added", - ts: v1beta1.TaskSpec{ - Volumes: []corev1.Volume{{ - Name: "magic-volume", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, - }}, - }, - }} - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - if err := v1beta1.ApplyTaskModifier(&tc.ts, &TestTaskModifier{}); err == nil { - t.Errorf("Expected error when applying values already added but got none") - } - }) - } -} - func TestPipelineResourceResult_UnmarshalJSON(t *testing.T) { testcases := []struct { name string diff --git a/pkg/apis/pipeline/v1beta1/resource_types_validation.go b/pkg/apis/pipeline/v1beta1/resource_types_validation.go deleted file mode 100644 index 30bad216ae2..00000000000 --- a/pkg/apis/pipeline/v1beta1/resource_types_validation.go +++ /dev/null @@ -1,101 +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 v1beta1 - -import ( - "context" - "fmt" - "strings" - - "k8s.io/apimachinery/pkg/util/sets" - "knative.dev/pkg/apis" -) - -// Validate implements apis.Validatable -func (tr *TaskResources) Validate(context.Context) (errs *apis.FieldError) { - if tr != nil { - errs = errs.Also(validateTaskResources(tr.Inputs).ViaField("inputs")) - errs = errs.Also(validateTaskResources(tr.Outputs).ViaField("outputs")) - } - return errs -} - -func validateTaskResources(resources []TaskResource) (errs *apis.FieldError) { - for idx, resource := range resources { - errs = errs.Also(validateResourceType(resource, fmt.Sprintf("%s.type", resource.Name))).ViaIndex(idx) - } - return errs.Also(checkForDuplicates(resources, "name")) -} - -func checkForDuplicates(resources []TaskResource, path string) *apis.FieldError { - encountered := sets.NewString() - for _, r := range resources { - if encountered.Has(strings.ToLower(r.Name)) { - return apis.ErrMultipleOneOf(path) - } - encountered.Insert(strings.ToLower(r.Name)) - } - return nil -} - -func validateResourceType(r TaskResource, path string) *apis.FieldError { - for _, allowed := range AllResourceTypes { - if r.Type == allowed { - return nil - } - } - return apis.ErrInvalidValue(r.Type, path) -} - -// Validate implements apis.Validatable -func (tr *TaskRunResources) Validate(ctx context.Context) *apis.FieldError { - if tr == nil { - return nil - } - if err := validateTaskRunResources(ctx, tr.Inputs, "spec.resources.inputs.name"); err != nil { - return err - } - return validateTaskRunResources(ctx, tr.Outputs, "spec.resources.outputs.name") -} - -// validateTaskRunResources validates that -// 1. resource is not declared more than once -// 2. if both resource reference and resource spec is defined at the same time -// 3. at least resource ref or resource spec is defined -func validateTaskRunResources(ctx context.Context, resources []TaskResourceBinding, path string) *apis.FieldError { - encountered := sets.NewString() - for _, r := range resources { - // We should provide only one binding for each resource required by the Task. - name := strings.ToLower(r.Name) - if encountered.Has(strings.ToLower(name)) { - return apis.ErrMultipleOneOf(path) - } - encountered.Insert(name) - // Check that both resource ref and resource Spec are not present - if r.ResourceRef != nil && r.ResourceSpec != nil { - return apis.ErrDisallowedFields(fmt.Sprintf("%s.resourceRef", path), fmt.Sprintf("%s.resourceSpec", path)) - } - // Check that one of resource ref and resource Spec is present - if (r.ResourceRef == nil || r.ResourceRef.Name == "") && r.ResourceSpec == nil { - return apis.ErrMissingField(fmt.Sprintf("%s.resourceRef", path), fmt.Sprintf("%s.resourceSpec", path)) - } - if r.ResourceSpec != nil && r.ResourceSpec.Validate(ctx) != nil { - return r.ResourceSpec.Validate(ctx) - } - } - return nil -} diff --git a/pkg/apis/pipeline/v1beta1/swagger.json b/pkg/apis/pipeline/v1beta1/swagger.json index f226ece35a2..5a8d2406b4a 100644 --- a/pkg/apis/pipeline/v1beta1/swagger.json +++ b/pkg/apis/pipeline/v1beta1/swagger.json @@ -151,173 +151,6 @@ } } }, - "v1alpha1.PipelineResource": { - "description": "PipelineResource describes a resource that is an input to or output from a Task.", - "type": "object", - "properties": { - "apiVersion": { - "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - "type": "string" - }, - "kind": { - "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - "type": "string" - }, - "metadata": { - "default": {}, - "$ref": "#/definitions/v1.ObjectMeta" - }, - "spec": { - "description": "Spec holds the desired state of the PipelineResource from the client", - "default": {}, - "$ref": "#/definitions/v1alpha1.PipelineResourceSpec" - }, - "status": { - "description": "Status is used to communicate the observed state of the PipelineResource from the controller, but was unused as there is no controller for PipelineResource.\n\nDeprecated: Deprecated in v0.30.0.", - "$ref": "#/definitions/v1alpha1.PipelineResourceStatus" - } - } - }, - "v1alpha1.PipelineResourceList": { - "description": "PipelineResourceList contains a list of PipelineResources", - "type": "object", - "required": [ - "items" - ], - "properties": { - "apiVersion": { - "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - "type": "string" - }, - "items": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1alpha1.PipelineResource" - } - }, - "kind": { - "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - "type": "string" - }, - "metadata": { - "default": {}, - "$ref": "#/definitions/v1.ListMeta" - } - } - }, - "v1alpha1.PipelineResourceSpec": { - "description": "PipelineResourceSpec defines an individual resources used in the pipeline.", - "type": "object", - "required": [ - "type", - "params" - ], - "properties": { - "description": { - "description": "Description is a user-facing description of the resource that may be used to populate a UI.", - "type": "string" - }, - "params": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1alpha1.ResourceParam" - }, - "x-kubernetes-list-type": "atomic" - }, - "secrets": { - "description": "Secrets to fetch to populate some of resource fields", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1alpha1.SecretParam" - }, - "x-kubernetes-list-type": "atomic" - }, - "type": { - "type": "string", - "default": "" - } - } - }, - "v1alpha1.PipelineResourceStatus": { - "description": "PipelineResourceStatus does not contain anything because PipelineResources on their own do not have a status\n\nDeprecated: Deprecated in v0.30.0.", - "type": "object" - }, - "v1alpha1.ResourceDeclaration": { - "description": "ResourceDeclaration defines an input or output PipelineResource declared as a requirement by another type such as a Task or Condition. The Name field will be used to refer to these PipelineResources within the type's definition, and when provided as an Input, the Name will be the path to the volume mounted containing this PipelineResource as an input (e.g. an input Resource named `workspace` will be mounted at `/workspace`).", - "type": "object", - "required": [ - "name", - "type" - ], - "properties": { - "description": { - "description": "Description is a user-facing description of the declared resource that may be used to populate a UI.", - "type": "string" - }, - "name": { - "description": "Name declares the name by which a resource is referenced in the definition. Resources may be referenced by name in the definition of a Task's steps.", - "type": "string", - "default": "" - }, - "optional": { - "description": "Optional declares the resource as optional. By default optional is set to false which makes a resource required. optional: true - the resource is considered optional optional: false - the resource is considered required (equivalent of not specifying it)", - "type": "boolean" - }, - "targetPath": { - "description": "TargetPath is the path in workspace directory where the resource will be copied.", - "type": "string" - }, - "type": { - "description": "Type is the type of this resource;", - "type": "string", - "default": "" - } - } - }, - "v1alpha1.ResourceParam": { - "description": "ResourceParam declares a string value to use for the parameter called Name, and is used in the specific context of PipelineResources.", - "type": "object", - "required": [ - "name", - "value" - ], - "properties": { - "name": { - "type": "string", - "default": "" - }, - "value": { - "type": "string", - "default": "" - } - } - }, - "v1alpha1.SecretParam": { - "description": "SecretParam indicates which secret can be used to populate a field of the resource", - "type": "object", - "required": [ - "fieldName", - "secretKey", - "secretName" - ], - "properties": { - "fieldName": { - "type": "string", - "default": "" - }, - "secretKey": { - "type": "string", - "default": "" - }, - "secretName": { - "type": "string", - "default": "" - } - } - }, "v1beta1.ChildStatusReference": { "description": "ChildStatusReference is used to point to the statuses of individual TaskRuns and Runs within this PipelineRun.", "type": "object", @@ -616,10 +449,6 @@ }, "x-kubernetes-list-type": "atomic" }, - "resources": { - "description": "Resources is a list input and output resource to run the task Resources are represented in TaskRuns as bindings to instances of PipelineResources.", - "$ref": "#/definitions/v1beta1.TaskResources" - }, "results": { "description": "Results are values that this Task can output", "type": "array", @@ -676,41 +505,6 @@ } } }, - "v1beta1.InternalTaskModifier": { - "description": "InternalTaskModifier implements TaskModifier for resources that are built-in to Tekton Pipelines.", - "type": "object", - "required": [ - "stepsToPrepend", - "stepsToAppend", - "volumes" - ], - "properties": { - "stepsToAppend": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.Step" - }, - "x-kubernetes-list-type": "atomic" - }, - "stepsToPrepend": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.Step" - }, - "x-kubernetes-list-type": "atomic" - }, - "volumes": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1.Volume" - }, - "x-kubernetes-list-type": "atomic" - } - } - }, "v1beta1.Matrix": { "description": "Matrix is used to fan out Tasks in a Pipeline", "type": "object", @@ -865,30 +659,6 @@ } } }, - "v1beta1.PipelineDeclaredResource": { - "description": "PipelineDeclaredResource is used by a Pipeline to declare the types of the PipelineResources that it will required to run and names which can be used to refer to these PipelineResources in PipelineTaskResourceBindings.", - "type": "object", - "required": [ - "name", - "type" - ], - "properties": { - "name": { - "description": "Name is the name that will be used by the Pipeline to refer to this resource. It does not directly correspond to the name of any PipelineResources Task inputs or outputs, and it does not correspond to the actual names of the PipelineResources that will be bound in the PipelineRun.", - "type": "string", - "default": "" - }, - "optional": { - "description": "Optional declares the resource as optional. optional: true - the resource is considered optional optional: false - the resource is considered required (default/equivalent of not specifying it)", - "type": "boolean" - }, - "type": { - "description": "Type is the type of the PipelineResource.", - "type": "string", - "default": "" - } - } - }, "v1beta1.PipelineList": { "description": "PipelineList contains a list of Pipeline", "type": "object", @@ -935,38 +705,6 @@ } } }, - "v1beta1.PipelineResourceBinding": { - "description": "PipelineResourceBinding connects a reference to an instance of a PipelineResource with a PipelineResource dependency that the Pipeline has declared", - "type": "object", - "properties": { - "name": { - "description": "Name is the name of the PipelineResource in the Pipeline's declaration", - "type": "string" - }, - "resourceRef": { - "description": "ResourceRef is a reference to the instance of the actual PipelineResource that should be used", - "$ref": "#/definitions/v1beta1.PipelineResourceRef" - }, - "resourceSpec": { - "description": "ResourceSpec is specification of a resource that should be created and consumed by the task", - "$ref": "#/definitions/v1alpha1.PipelineResourceSpec" - } - } - }, - "v1beta1.PipelineResourceRef": { - "description": "PipelineResourceRef can be used to refer to a specific instance of a Resource", - "type": "object", - "properties": { - "apiVersion": { - "description": "API version of the referent", - "type": "string" - }, - "name": { - "description": "Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names", - "type": "string" - } - } - }, "v1beta1.PipelineResourceResult": { "description": "PipelineResourceResult used to export the image name and digest as json", "type": "object", @@ -1138,15 +876,6 @@ "description": "PodTemplate holds pod specific configuration", "$ref": "#/definitions/pod.Template" }, - "resources": { - "description": "Resources is a list of bindings specifying which actual instances of PipelineResources to use for the resources the Pipeline has declared it needs.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.PipelineResourceBinding" - }, - "x-kubernetes-list-type": "atomic" - }, "serviceAccountName": { "type": "string" }, @@ -1376,15 +1105,6 @@ }, "x-kubernetes-list-type": "atomic" }, - "resources": { - "description": "Resources declares the names and types of the resources given to the Pipeline's tasks as inputs and outputs.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.PipelineDeclaredResource" - }, - "x-kubernetes-list-type": "atomic" - }, "results": { "description": "Results are values that this pipeline can output once run", "type": "array", @@ -1435,10 +1155,6 @@ }, "x-kubernetes-list-type": "atomic" }, - "resources": { - "description": "Resources declares the resources given to this task as inputs and outputs.", - "$ref": "#/definitions/v1beta1.PipelineTaskResources" - }, "retries": { "description": "Retries represents how many times this task should be retried in case of task failure: ConditionSucceeded set to False", "type": "integer", @@ -1484,35 +1200,6 @@ } } }, - "v1beta1.PipelineTaskInputResource": { - "description": "PipelineTaskInputResource maps the name of a declared PipelineResource input dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources that should be used. This input may come from a previous task.", - "type": "object", - "required": [ - "name", - "resource" - ], - "properties": { - "from": { - "description": "From is the list of PipelineTask names that the resource has to come from. (Implies an ordering in the execution graph.)", - "type": "array", - "items": { - "type": "string", - "default": "" - }, - "x-kubernetes-list-type": "atomic" - }, - "name": { - "description": "Name is the name of the PipelineResource as declared by the Task.", - "type": "string", - "default": "" - }, - "resource": { - "description": "Resource is the name of the DeclaredPipelineResource to use.", - "type": "string", - "default": "" - } - } - }, "v1beta1.PipelineTaskMetadata": { "description": "PipelineTaskMetadata contains the labels or annotations for an EmbeddedTask", "type": "object", @@ -1533,26 +1220,6 @@ } } }, - "v1beta1.PipelineTaskOutputResource": { - "description": "PipelineTaskOutputResource maps the name of a declared PipelineResource output dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources that should be used.", - "type": "object", - "required": [ - "name", - "resource" - ], - "properties": { - "name": { - "description": "Name is the name of the PipelineResource as declared by the Task.", - "type": "string", - "default": "" - }, - "resource": { - "description": "Resource is the name of the DeclaredPipelineResource to use.", - "type": "string", - "default": "" - } - } - }, "v1beta1.PipelineTaskParam": { "description": "PipelineTaskParam is used to provide arbitrary string parameters to a Task.", "type": "object", @@ -1571,30 +1238,6 @@ } } }, - "v1beta1.PipelineTaskResources": { - "description": "PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources should be provided to a Task as its inputs and outputs.", - "type": "object", - "properties": { - "inputs": { - "description": "Inputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.PipelineTaskInputResource" - }, - "x-kubernetes-list-type": "atomic" - }, - "outputs": { - "description": "Outputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.PipelineTaskOutputResource" - }, - "x-kubernetes-list-type": "atomic" - } - } - }, "v1beta1.PipelineTaskRun": { "description": "PipelineTaskRun reports the results of running a step in the Task. Each task has the potential to succeed or fail (based on the exit code) and produces logs.", "type": "object", @@ -2513,89 +2156,6 @@ } } }, - "v1beta1.TaskResource": { - "description": "TaskResource defines an input or output Resource declared as a requirement by a Task. The Name field will be used to refer to these Resources within the Task definition, and when provided as an Input, the Name will be the path to the volume mounted containing this Resource as an input (e.g. an input Resource named `workspace` will be mounted at `/workspace`).", - "type": "object", - "required": [ - "name", - "type" - ], - "properties": { - "description": { - "description": "Description is a user-facing description of the declared resource that may be used to populate a UI.", - "type": "string" - }, - "name": { - "description": "Name declares the name by which a resource is referenced in the definition. Resources may be referenced by name in the definition of a Task's steps.", - "type": "string", - "default": "" - }, - "optional": { - "description": "Optional declares the resource as optional. By default optional is set to false which makes a resource required. optional: true - the resource is considered optional optional: false - the resource is considered required (equivalent of not specifying it)", - "type": "boolean" - }, - "targetPath": { - "description": "TargetPath is the path in workspace directory where the resource will be copied.", - "type": "string" - }, - "type": { - "description": "Type is the type of this resource;", - "type": "string", - "default": "" - } - } - }, - "v1beta1.TaskResourceBinding": { - "description": "TaskResourceBinding points to the PipelineResource that will be used for the Task input or output called Name.", - "type": "object", - "properties": { - "name": { - "description": "Name is the name of the PipelineResource in the Pipeline's declaration", - "type": "string" - }, - "paths": { - "description": "Paths will probably be removed in #1284, and then PipelineResourceBinding can be used instead. The optional Path field corresponds to a path on disk at which the Resource can be found (used when providing the resource via mounted volume, overriding the default logic to fetch the Resource).", - "type": "array", - "items": { - "type": "string", - "default": "" - }, - "x-kubernetes-list-type": "atomic" - }, - "resourceRef": { - "description": "ResourceRef is a reference to the instance of the actual PipelineResource that should be used", - "$ref": "#/definitions/v1beta1.PipelineResourceRef" - }, - "resourceSpec": { - "description": "ResourceSpec is specification of a resource that should be created and consumed by the task", - "$ref": "#/definitions/v1alpha1.PipelineResourceSpec" - } - } - }, - "v1beta1.TaskResources": { - "description": "TaskResources allows a Pipeline to declare how its DeclaredPipelineResources should be provided to a Task as its inputs and outputs.", - "type": "object", - "properties": { - "inputs": { - "description": "Inputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.TaskResource" - }, - "x-kubernetes-list-type": "atomic" - }, - "outputs": { - "description": "Outputs holds the mapping from the PipelineResources declared in DeclaredPipelineResources to the input PipelineResources required by the Task.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.TaskResource" - }, - "x-kubernetes-list-type": "atomic" - } - } - }, "v1beta1.TaskResult": { "description": "TaskResult used to describe the results of a task", "type": "object", @@ -2666,28 +2226,6 @@ } } }, - "v1beta1.TaskRunInputs": { - "description": "TaskRunInputs holds the input values that this task was invoked with.", - "type": "object", - "properties": { - "params": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.Param" - }, - "x-kubernetes-list-type": "atomic" - }, - "resources": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.TaskResourceBinding" - }, - "x-kubernetes-list-type": "atomic" - } - } - }, "v1beta1.TaskRunList": { "description": "TaskRunList contains a list of TaskRun", "type": "object", @@ -2716,44 +2254,6 @@ } } }, - "v1beta1.TaskRunOutputs": { - "description": "TaskRunOutputs holds the output values that this task was invoked with.", - "type": "object", - "properties": { - "resources": { - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.TaskResourceBinding" - }, - "x-kubernetes-list-type": "atomic" - } - } - }, - "v1beta1.TaskRunResources": { - "description": "TaskRunResources allows a TaskRun to declare inputs and outputs TaskResourceBinding", - "type": "object", - "properties": { - "inputs": { - "description": "Inputs holds the inputs resources this task was invoked with", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.TaskResourceBinding" - }, - "x-kubernetes-list-type": "atomic" - }, - "outputs": { - "description": "Outputs holds the inputs resources this task was invoked with", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.TaskResourceBinding" - }, - "x-kubernetes-list-type": "atomic" - } - } - }, "v1beta1.TaskRunResult": { "description": "TaskRunResult used to describe the results of a task", "type": "object", @@ -2821,9 +2321,6 @@ "description": "PodTemplate holds pod specific configuration", "$ref": "#/definitions/pod.Template" }, - "resources": { - "$ref": "#/definitions/v1beta1.TaskRunResources" - }, "retries": { "description": "Retries represents how many times this TaskRun should be retried in the event of Task failure.", "type": "integer", @@ -3125,10 +2622,6 @@ }, "x-kubernetes-list-type": "atomic" }, - "resources": { - "description": "Resources is a list input and output resource to run the task Resources are represented in TaskRuns as bindings to instances of PipelineResources.", - "$ref": "#/definitions/v1beta1.TaskResources" - }, "results": { "description": "Results are values that this Task can output", "type": "array", diff --git a/pkg/apis/pipeline/v1beta1/task_conversion.go b/pkg/apis/pipeline/v1beta1/task_conversion.go index ee0e8bd7b13..3fefd5cbfda 100644 --- a/pkg/apis/pipeline/v1beta1/task_conversion.go +++ b/pkg/apis/pipeline/v1beta1/task_conversion.go @@ -21,13 +21,9 @@ import ( "fmt" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/tektoncd/pipeline/pkg/apis/version" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" ) -const resourcesAnnotationKey = "tekton.dev/v1beta1Resources" - var _ apis.Convertible = (*Task)(nil) // ConvertTo implements apis.Convertible @@ -38,9 +34,6 @@ func (t *Task) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { case *v1.Task: sink.ObjectMeta = t.ObjectMeta - if err := serializeResources(&sink.ObjectMeta, &t.Spec); err != nil { - return err - } return t.Spec.ConvertTo(ctx, &sink.Spec) default: return fmt.Errorf("unknown version, got: %T", sink) @@ -97,9 +90,6 @@ func (t *Task) ConvertFrom(ctx context.Context, from apis.Convertible) error { switch source := from.(type) { case *v1.Task: t.ObjectMeta = source.ObjectMeta - if err := deserializeResources(&t.ObjectMeta, &t.Spec); err != nil { - return err - } return t.Spec.ConvertFrom(ctx, &source.Spec) default: return fmt.Errorf("unknown version, got: %T", t) @@ -147,22 +137,3 @@ func (ts *TaskSpec) ConvertFrom(ctx context.Context, source *v1.TaskSpec) error ts.Description = source.Description return nil } - -func serializeResources(meta *metav1.ObjectMeta, spec *TaskSpec) error { - if spec.Resources == nil { - return nil - } - return version.SerializeToMetadata(meta, spec.Resources, resourcesAnnotationKey) -} - -func deserializeResources(meta *metav1.ObjectMeta, spec *TaskSpec) error { - resources := &TaskResources{} - err := version.DeserializeFromMetadata(meta, resources, resourcesAnnotationKey) - if err != nil { - return err - } - if resources.Inputs != nil || resources.Outputs != nil { - spec.Resources = resources - } - return nil -} diff --git a/pkg/apis/pipeline/v1beta1/task_conversion_test.go b/pkg/apis/pipeline/v1beta1/task_conversion_test.go index 01617c9bbf1..36e25bd6bcb 100644 --- a/pkg/apis/pipeline/v1beta1/task_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/task_conversion_test.go @@ -184,81 +184,3 @@ func TestTaskConversion(t *testing.T) { } } } - -func TestTaskConversionFromDeprecated(t *testing.T) { - tests := []struct { - name string - in *v1beta1.Task - want *v1beta1.Task - }{{ - name: "input resources", - in: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - Generation: 1, - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{v1beta1.ResourceDeclaration{Name: "input-resource"}}}, - }, - }, - }, - want: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - Generation: 1, - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{v1beta1.ResourceDeclaration{Name: "input-resource"}}}, - }, - }, - }, - }, { - name: "output resources", - in: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - Generation: 1, - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{v1beta1.ResourceDeclaration{Name: "output-resource"}}}, - }, - }, - }, - want: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - Generation: 1, - }, - Spec: v1beta1.TaskSpec{Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{v1beta1.ResourceDeclaration{Name: "output-resource"}}}, - }}, - }, - }} - for _, test := range tests { - versions := []apis.Convertible{&v1.Task{}} - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - t.Logf("ConvertTo() = %#v", ver) - got := &v1beta1.Task{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - t.Logf("ConvertFrom() = %#v", got) - if d := cmp.Diff(test.want, got); d != "" { - t.Errorf("roundtrip %s", diff.PrintWantGot(d)) - } - }) - } - } -} diff --git a/pkg/apis/pipeline/v1beta1/task_types.go b/pkg/apis/pipeline/v1beta1/task_types.go index b72abf2c3ff..d400d93cb8f 100644 --- a/pkg/apis/pipeline/v1beta1/task_types.go +++ b/pkg/apis/pipeline/v1beta1/task_types.go @@ -80,12 +80,6 @@ func (*Task) GetGroupVersionKind() schema.GroupVersionKind { // TaskSpec defines the desired state of Task. type TaskSpec struct { - // Resources is a list input and output resource to run the task - // Resources are represented in TaskRuns as bindings to instances of - // PipelineResources. - // +optional - Resources *TaskResources `json:"resources,omitempty"` - // Params is a list of input parameters required to run the task. Params // must be supplied as inputs in TaskRuns unless they declare a default // value. diff --git a/pkg/apis/pipeline/v1beta1/task_validation.go b/pkg/apis/pipeline/v1beta1/task_validation.go index 892aa1b35f3..1486c38aaa6 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation.go +++ b/pkg/apis/pipeline/v1beta1/task_validation.go @@ -94,10 +94,8 @@ func (ts *TaskSpec) Validate(ctx context.Context) (errs *apis.FieldError) { errs = errs.Also(validateSteps(ctx, mergedSteps).ViaField("steps")) errs = errs.Also(validateSidecarNames(ts.Sidecars)) - errs = errs.Also(ts.Resources.Validate(ctx).ViaField("resources")) errs = errs.Also(ValidateParameterTypes(ctx, ts.Params).ViaField("params")) errs = errs.Also(ValidateParameterVariables(ctx, ts.Steps, ts.Params)) - errs = errs.Also(ValidateResourcesVariables(ctx, ts.Steps, ts.Resources)) errs = errs.Also(validateTaskContextVariables(ctx, ts.Steps)) errs = errs.Also(validateTaskResultsVariables(ctx, ts.Steps, ts.Results)) errs = errs.Also(validateResults(ctx, ts.Results).ViaField("results")) @@ -421,25 +419,6 @@ func validateTaskResultsVariables(ctx context.Context, steps []Step, results []T return errs } -// ValidateResourcesVariables validates all variables within a TaskResources against a slice of Steps -func ValidateResourcesVariables(ctx context.Context, steps []Step, resources *TaskResources) *apis.FieldError { - if resources == nil { - return nil - } - resourceNames := sets.NewString() - if resources.Inputs != nil { - for _, r := range resources.Inputs { - resourceNames.Insert(r.Name) - } - } - if resources.Outputs != nil { - for _, r := range resources.Outputs { - resourceNames.Insert(r.Name) - } - } - return validateVariables(ctx, steps, "resources.(?:inputs|outputs)", resourceNames) -} - // validateObjectUsage validates the usage of individual attributes of an object param and the usage of the entire object func validateObjectUsage(ctx context.Context, steps []Step, params []ParamSpec) (errs *apis.FieldError) { objectParameterNames := sets.NewString() diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index 0a42616e981..982655e2540 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -34,20 +34,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", - Type: "what", - }, -} - var validSteps = []v1beta1.Step{{ Name: "mystep", Image: "myimage", @@ -95,7 +81,6 @@ func TestTaskValidate(t *testing.T) { func TestTaskSpecValidatePropagatedParamsAndWorkspaces(t *testing.T) { type fields struct { Params []v1beta1.ParamSpec - Resources *v1beta1.TaskResources Steps []v1beta1.Step StepTemplate *v1beta1.StepTemplate Workspaces []v1beta1.WorkspaceDeclaration @@ -151,7 +136,6 @@ func TestTaskSpecValidatePropagatedParamsAndWorkspaces(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ts := &v1beta1.TaskSpec{ Params: tt.fields.Params, - Resources: tt.fields.Resources, Steps: tt.fields.Steps, StepTemplate: tt.fields.StepTemplate, Workspaces: tt.fields.Workspaces, @@ -170,7 +154,6 @@ func TestTaskSpecValidatePropagatedParamsAndWorkspaces(t *testing.T) { func TestTaskSpecValidate(t *testing.T) { type fields struct { Params []v1beta1.ParamSpec - Resources *v1beta1.TaskResources Steps []v1beta1.Step StepTemplate *v1beta1.StepTemplate Workspaces []v1beta1.WorkspaceDeclaration @@ -188,22 +171,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{ @@ -543,7 +510,6 @@ func TestTaskSpecValidate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ts := &v1beta1.TaskSpec{ Params: tt.fields.Params, - Resources: tt.fields.Resources, Steps: tt.fields.Steps, StepTemplate: tt.fields.StepTemplate, Workspaces: tt.fields.Workspaces, @@ -561,7 +527,6 @@ func TestTaskSpecValidate(t *testing.T) { func TestTaskSpecValidateError(t *testing.T) { type fields struct { Params []v1beta1.ParamSpec - Resources *v1beta1.TaskResources Steps []v1beta1.Step Volumes []corev1.Volume StepTemplate *v1beta1.StepTemplate @@ -592,80 +557,6 @@ func TestTaskSpecValidateError(t *testing.T) { Message: `missing field(s)`, Paths: []string{"steps"}, }, - }, { - name: "invalid input resource", - fields: fields{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{invalidResource}, - }, - Steps: validSteps, - }, - expectedError: apis.FieldError{ - 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{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{invalidResource}, - }, - Steps: validSteps, - }, - expectedError: apis.FieldError{ - 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: "step script refers to nonexistent result", fields: fields{ @@ -1420,7 +1311,6 @@ func TestTaskSpecValidateError(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ts := &v1beta1.TaskSpec{ Params: tt.fields.Params, - Resources: tt.fields.Resources, Steps: tt.fields.Steps, Volumes: tt.fields.Volumes, StepTemplate: tt.fields.StepTemplate, diff --git a/pkg/apis/pipeline/v1beta1/taskrun_conversion.go b/pkg/apis/pipeline/v1beta1/taskrun_conversion.go index bb081314b4e..726448ab104 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_conversion.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_conversion.go @@ -41,9 +41,6 @@ func (tr *TaskRun) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { case *v1.TaskRun: sink.ObjectMeta = tr.ObjectMeta - if err := serializeTaskRunResources(&sink.ObjectMeta, &tr.Spec); err != nil { - return err - } if err := serializeTaskRunCloudEvents(&sink.ObjectMeta, &tr.Status); err != nil { return err } @@ -118,9 +115,6 @@ func (tr *TaskRun) ConvertFrom(ctx context.Context, from apis.Convertible) error switch source := from.(type) { case *v1.TaskRun: tr.ObjectMeta = source.ObjectMeta - if err := deserializeTaskRunResources(&tr.ObjectMeta, &tr.Spec); err != nil { - return err - } if err := deserializeTaskRunCloudEvents(&tr.ObjectMeta, &tr.Status); err != nil { return err } @@ -360,25 +354,6 @@ func (ss *SidecarState) convertFrom(ctx context.Context, source v1.SidecarState) ss.ImageID = source.ImageID } -func serializeTaskRunResources(meta *metav1.ObjectMeta, spec *TaskRunSpec) error { - if spec.Resources == nil { - return nil - } - return version.SerializeToMetadata(meta, spec.Resources, resourcesAnnotationKey) -} - -func deserializeTaskRunResources(meta *metav1.ObjectMeta, spec *TaskRunSpec) error { - resources := &TaskRunResources{} - err := version.DeserializeFromMetadata(meta, resources, resourcesAnnotationKey) - if err != nil { - return err - } - if resources.Inputs != nil || resources.Outputs != nil { - spec.Resources = resources - } - return nil -} - func serializeTaskRunCloudEvents(meta *metav1.ObjectMeta, status *TaskRunStatus) error { if status.CloudEvents == nil { return nil diff --git a/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go b/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go index 02e6d16aff4..de8dccd209f 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go @@ -280,86 +280,6 @@ func TestTaskRunConversionFromDeprecated(t *testing.T) { in *v1beta1.TaskRun want *v1beta1.TaskRun }{{ - name: "input resources", - in: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - Paths: []string{"test-path"}, - }}, - }, - }, - }, - want: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - Paths: []string{"test-path"}, - }}, - }, - }, - }, - }, { - name: "output resources", - in: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - Paths: []string{"test-path"}, - }}, - }, - }, - }, - want: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "bar", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "the-git-with-branch", - }, - Name: "gitspace", - }, - Paths: []string{"test-path"}, - }}, - }, - }, - }, - }, { name: "bundle", in: &v1beta1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/apis/pipeline/v1beta1/taskrun_types.go b/pkg/apis/pipeline/v1beta1/taskrun_types.go index 774278772e5..d7a7e1fef8f 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_types.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_types.go @@ -42,8 +42,6 @@ type TaskRunSpec struct { // +listType=atomic Params []Param `json:"params,omitempty"` // +optional - Resources *TaskRunResources `json:"resources,omitempty"` - // +optional ServiceAccountName string `json:"serviceAccountName"` // no more than one of the TaskRef and TaskSpec may be specified. // +optional @@ -115,23 +113,6 @@ type TaskRunDebug struct { Breakpoint []string `json:"breakpoint,omitempty"` } -// TaskRunInputs holds the input values that this task was invoked with. -type TaskRunInputs struct { - // +optional - // +listType=atomic - Resources []TaskResourceBinding `json:"resources,omitempty"` - // +optional - // +listType=atomic - Params []Param `json:"params,omitempty"` -} - -// TaskRunOutputs holds the output values that this task was invoked with. -type TaskRunOutputs struct { - // +optional - // +listType=atomic - Resources []TaskResourceBinding `json:"resources,omitempty"` -} - var taskRunCondSet = apis.NewBatchConditionSet() // TaskRunStatus defines the observed state of TaskRun diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation.go b/pkg/apis/pipeline/v1beta1/taskrun_validation.go index f8d379c6df3..fabd630cc9e 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation.go @@ -72,7 +72,6 @@ func (ts *TaskRunSpec) Validate(ctx context.Context) (errs *apis.FieldError) { // Validate propagated parameters errs = errs.Also(ts.validateInlineParameters(ctx)) errs = errs.Also(ValidateWorkspaceBindings(ctx, ts.Workspaces).ViaField("workspaces")) - errs = errs.Also(ts.Resources.Validate(ctx).ViaField("resources")) if ts.Debug != nil { errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "debug", config.AlphaAPIFields).ViaField("debug")) errs = errs.Also(validateDebug(ts.Debug).ViaField("debug")) diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go index cca73d3da38..9d3d5dd1f6a 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go @@ -26,7 +26,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" pod "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" corev1resources "k8s.io/apimachinery/pkg/api/resource" @@ -886,235 +885,3 @@ func TestTaskRunSpec_Validate(t *testing.T) { }) } } - -func TestResources_Validate(t *testing.T) { - tests := []struct { - name string - resources *v1beta1.TaskRunResources - }{{ - name: "no resources is valid", - }, { - name: "inputs only", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource", - }, - Name: "workspace", - }, - }}, - }, - }, { - name: "multiple inputs only", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource1", - }, - Name: "workspace1", - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource2", - }, - Name: "workspace2", - }, - }}, - }, - }, { - name: "outputs only", - resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource", - }, - Name: "workspace", - }, - }}, - }, - }, { - name: "multiple outputs only", - resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource1", - }, - Name: "workspace1", - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource2", - }, - Name: "workspace2", - }, - }}, - }, - }, { - name: "inputs and outputs", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource", - }, - Name: "workspace", - }, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource", - }, - Name: "workspace", - }, - }}, - }, - }} - for _, ts := range tests { - t.Run(ts.name, func(t *testing.T) { - if err := ts.resources.Validate(context.Background()); err != nil { - t.Errorf("TaskRunInputs.Validate() error = %v", err) - } - }) - } -} - -func TestResources_Invalidate(t *testing.T) { - tests := []struct { - name string - resources *v1beta1.TaskRunResources - wantErr *apis.FieldError - }{{ - name: "duplicate task inputs", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource1", - }, - Name: "workspace", - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource2", - }, - Name: "workspace", - }, - }}, - }, - wantErr: apis.ErrMultipleOneOf("spec.resources.inputs.name"), - }, { - name: "duplicate resource ref and resource spec", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource", - }, - ResourceSpec: &resource.PipelineResourceSpec{ - Type: v1beta1.PipelineResourceTypeGit, - }, - Name: "resource-dup", - }, - }}, - }, - wantErr: apis.ErrDisallowedFields("spec.resources.inputs.name.resourceRef", "spec.resources.inputs.name.resourceSpec"), - }, { - name: "invalid resource spec", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &resource.PipelineResourceSpec{ - Type: "non-existent", - }, - Name: "resource-inv", - }, - }}, - }, - wantErr: apis.ErrInvalidValue("spec.type", "non-existent"), - }, { - name: "no resource ref", // and resource spec - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "resource", - }, - }}, - }, - wantErr: apis.ErrMissingField("spec.resources.inputs.name.resourceRef", "spec.resources.inputs.name.resourceSpec"), - }, { - name: "duplicate task outputs", - resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource1", - }, - Name: "workspace", - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource2", - }, - Name: "workspace", - }, - }}, - }, - wantErr: apis.ErrMultipleOneOf("spec.resources.outputs.name"), - }, { - name: "duplicate resource ref and resource spec", - resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "testresource", - }, - ResourceSpec: &resource.PipelineResourceSpec{ - Type: v1beta1.PipelineResourceTypeGit, - }, - Name: "resource-dup", - }, - }}, - }, - wantErr: apis.ErrDisallowedFields("spec.resources.outputs.name.resourceRef", "spec.resources.outputs.name.resourceSpec"), - }, { - name: "invalid resource spec", - resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceSpec: &resource.PipelineResourceSpec{ - Type: "non-existent", - }, - Name: "resource-inv", - }, - }}, - }, - wantErr: apis.ErrInvalidValue("spec.type", "non-existent"), - }, { - name: "no resource ref ", // and resource spec - resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "resource", - }, - }}, - }, - wantErr: apis.ErrMissingField("spec.resources.outputs.name.resourceRef", "spec.resources.outputs.name.resourceSpec"), - }} - for _, ts := range tests { - t.Run(ts.name, func(t *testing.T) { - err := ts.resources.Validate(context.Background()) - if d := cmp.Diff(err.Error(), ts.wantErr.Error()); d != "" { - t.Error(diff.PrintWantGot(d)) - } - }) - } -} diff --git a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go index 512456098c6..c521b8f9bf1 100644 --- a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go @@ -24,7 +24,6 @@ package v1beta1 import ( config "github.com/tektoncd/pipeline/pkg/apis/config" pod "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" runv1beta1 "github.com/tektoncd/pipeline/pkg/apis/run/v1beta1" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -320,43 +319,6 @@ func (in *EmbeddedTask) DeepCopy() *EmbeddedTask { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *InternalTaskModifier) DeepCopyInto(out *InternalTaskModifier) { - *out = *in - if in.StepsToPrepend != nil { - in, out := &in.StepsToPrepend, &out.StepsToPrepend - *out = make([]Step, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.StepsToAppend != nil { - in, out := &in.StepsToAppend, &out.StepsToAppend - *out = make([]Step, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Volumes != nil { - in, out := &in.Volumes, &out.Volumes - *out = make([]corev1.Volume, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InternalTaskModifier. -func (in *InternalTaskModifier) DeepCopy() *InternalTaskModifier { - if in == nil { - return nil - } - out := new(InternalTaskModifier) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Matrix) DeepCopyInto(out *Matrix) { *out = *in @@ -554,22 +516,6 @@ func (in *Pipeline) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineDeclaredResource) DeepCopyInto(out *PipelineDeclaredResource) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineDeclaredResource. -func (in *PipelineDeclaredResource) DeepCopy() *PipelineDeclaredResource { - if in == nil { - return nil - } - out := new(PipelineDeclaredResource) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineList) DeepCopyInto(out *PipelineList) { *out = *in @@ -620,48 +566,6 @@ func (in *PipelineRef) DeepCopy() *PipelineRef { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineResourceBinding) DeepCopyInto(out *PipelineResourceBinding) { - *out = *in - if in.ResourceRef != nil { - in, out := &in.ResourceRef, &out.ResourceRef - *out = new(PipelineResourceRef) - **out = **in - } - if in.ResourceSpec != nil { - in, out := &in.ResourceSpec, &out.ResourceSpec - *out = new(v1alpha1.PipelineResourceSpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineResourceBinding. -func (in *PipelineResourceBinding) DeepCopy() *PipelineResourceBinding { - if in == nil { - return nil - } - out := new(PipelineResourceBinding) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineResourceRef) DeepCopyInto(out *PipelineResourceRef) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineResourceRef. -func (in *PipelineResourceRef) DeepCopy() *PipelineResourceRef { - if in == nil { - return nil - } - out := new(PipelineResourceRef) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineResourceResult) DeepCopyInto(out *PipelineResourceResult) { *out = *in @@ -814,13 +718,6 @@ func (in *PipelineRunSpec) DeepCopyInto(out *PipelineRunSpec) { *out = new(PipelineSpec) (*in).DeepCopyInto(*out) } - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = make([]PipelineResourceBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } if in.Params != nil { in, out := &in.Params, &out.Params *out = make([]Param, len(*in)) @@ -985,11 +882,6 @@ func (in *PipelineRunTaskRunStatus) DeepCopy() *PipelineRunTaskRunStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineSpec) DeepCopyInto(out *PipelineSpec) { *out = *in - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = make([]PipelineDeclaredResource, len(*in)) - copy(*out, *in) - } if in.Tasks != nil { in, out := &in.Tasks, &out.Tasks *out = make([]PipelineTask, len(*in)) @@ -1061,11 +953,6 @@ func (in *PipelineTask) DeepCopyInto(out *PipelineTask) { *out = make([]string, len(*in)) copy(*out, *in) } - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = new(PipelineTaskResources) - (*in).DeepCopyInto(*out) - } if in.Params != nil { in, out := &in.Params, &out.Params *out = make(Params, len(*in)) @@ -1101,27 +988,6 @@ func (in *PipelineTask) DeepCopy() *PipelineTask { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineTaskInputResource) DeepCopyInto(out *PipelineTaskInputResource) { - *out = *in - if in.From != nil { - in, out := &in.From, &out.From - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineTaskInputResource. -func (in *PipelineTaskInputResource) DeepCopy() *PipelineTaskInputResource { - if in == nil { - return nil - } - out := new(PipelineTaskInputResource) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in PipelineTaskList) DeepCopyInto(out *PipelineTaskList) { { @@ -1174,22 +1040,6 @@ func (in *PipelineTaskMetadata) DeepCopy() *PipelineTaskMetadata { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineTaskOutputResource) DeepCopyInto(out *PipelineTaskOutputResource) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineTaskOutputResource. -func (in *PipelineTaskOutputResource) DeepCopy() *PipelineTaskOutputResource { - if in == nil { - return nil - } - out := new(PipelineTaskOutputResource) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineTaskParam) DeepCopyInto(out *PipelineTaskParam) { *out = *in @@ -1206,34 +1056,6 @@ func (in *PipelineTaskParam) DeepCopy() *PipelineTaskParam { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineTaskResources) DeepCopyInto(out *PipelineTaskResources) { - *out = *in - if in.Inputs != nil { - in, out := &in.Inputs, &out.Inputs - *out = make([]PipelineTaskInputResource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Outputs != nil { - in, out := &in.Outputs, &out.Outputs - *out = make([]PipelineTaskOutputResource, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineTaskResources. -func (in *PipelineTaskResources) DeepCopy() *PipelineTaskResources { - if in == nil { - return nil - } - out := new(PipelineTaskResources) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineTaskRun) DeepCopyInto(out *PipelineTaskRun) { *out = *in @@ -1816,71 +1638,6 @@ func (in *TaskRef) DeepCopy() *TaskRef { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskResource) DeepCopyInto(out *TaskResource) { - *out = *in - out.ResourceDeclaration = in.ResourceDeclaration - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskResource. -func (in *TaskResource) DeepCopy() *TaskResource { - if in == nil { - return nil - } - out := new(TaskResource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskResourceBinding) DeepCopyInto(out *TaskResourceBinding) { - *out = *in - in.PipelineResourceBinding.DeepCopyInto(&out.PipelineResourceBinding) - if in.Paths != nil { - in, out := &in.Paths, &out.Paths - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskResourceBinding. -func (in *TaskResourceBinding) DeepCopy() *TaskResourceBinding { - if in == nil { - return nil - } - out := new(TaskResourceBinding) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskResources) DeepCopyInto(out *TaskResources) { - *out = *in - if in.Inputs != nil { - in, out := &in.Inputs, &out.Inputs - *out = make([]TaskResource, len(*in)) - copy(*out, *in) - } - if in.Outputs != nil { - in, out := &in.Outputs, &out.Outputs - *out = make([]TaskResource, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskResources. -func (in *TaskResources) DeepCopy() *TaskResources { - if in == nil { - return nil - } - out := new(TaskResources) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TaskResult) DeepCopyInto(out *TaskResult) { *out = *in @@ -1953,36 +1710,6 @@ func (in *TaskRunDebug) DeepCopy() *TaskRunDebug { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskRunInputs) DeepCopyInto(out *TaskRunInputs) { - *out = *in - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = make([]TaskResourceBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Params != nil { - in, out := &in.Params, &out.Params - *out = make([]Param, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskRunInputs. -func (in *TaskRunInputs) DeepCopy() *TaskRunInputs { - if in == nil { - return nil - } - out := new(TaskRunInputs) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TaskRunList) DeepCopyInto(out *TaskRunList) { *out = *in @@ -2016,59 +1743,6 @@ func (in *TaskRunList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskRunOutputs) DeepCopyInto(out *TaskRunOutputs) { - *out = *in - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = make([]TaskResourceBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskRunOutputs. -func (in *TaskRunOutputs) DeepCopy() *TaskRunOutputs { - if in == nil { - return nil - } - out := new(TaskRunOutputs) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskRunResources) DeepCopyInto(out *TaskRunResources) { - *out = *in - if in.Inputs != nil { - in, out := &in.Inputs, &out.Inputs - *out = make([]TaskResourceBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Outputs != nil { - in, out := &in.Outputs, &out.Outputs - *out = make([]TaskResourceBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskRunResources. -func (in *TaskRunResources) DeepCopy() *TaskRunResources { - if in == nil { - return nil - } - out := new(TaskRunResources) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TaskRunResult) DeepCopyInto(out *TaskRunResult) { *out = *in @@ -2118,11 +1792,6 @@ func (in *TaskRunSpec) DeepCopyInto(out *TaskRunSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = new(TaskRunResources) - (*in).DeepCopyInto(*out) - } if in.TaskRef != nil { in, out := &in.TaskRef, &out.TaskRef *out = new(TaskRef) @@ -2301,11 +1970,6 @@ func (in *TaskRunStepOverride) DeepCopy() *TaskRunStepOverride { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TaskSpec) DeepCopyInto(out *TaskSpec) { *out = *in - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = new(TaskResources) - (*in).DeepCopyInto(*out) - } if in.Params != nil { in, out := &in.Params, &out.Params *out = make(ParamSpecs, len(*in)) diff --git a/pkg/apis/resource/resource.go b/pkg/apis/resource/resource.go deleted file mode 100644 index 91fbb0cf93b..00000000000 --- a/pkg/apis/resource/resource.go +++ /dev/null @@ -1,40 +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 resource - -import ( - "fmt" - - "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/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.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/doc.go b/pkg/apis/resource/v1alpha1/doc.go deleted file mode 100644 index b2c8398ab3f..00000000000 --- a/pkg/apis/resource/v1alpha1/doc.go +++ /dev/null @@ -1,23 +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 v1alpha1 contains API Schema definitions for the pipeline v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=github.com/tektoncd/pipeline/pkg/apis/resource -// +k8s:defaulter-gen=TypeMeta -// +groupName=tekton.dev -package v1alpha1 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/pipeline_resource_defaults.go b/pkg/apis/resource/v1alpha1/pipeline_resource_defaults.go deleted file mode 100644 index faf03c08c1d..00000000000 --- a/pkg/apis/resource/v1alpha1/pipeline_resource_defaults.go +++ /dev/null @@ -1,34 +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 v1alpha1 - -import ( - "context" - - "knative.dev/pkg/apis" -) - -var _ apis.Defaultable = (*PipelineResource)(nil) - -// SetDefaults implements api.Defaultable -func (t *PipelineResource) SetDefaults(ctx context.Context) { - t.Spec.SetDefaults(ctx) -} - -// SetDefaults implements api.Defaultable -func (ts *PipelineResourceSpec) SetDefaults(ctx context.Context) { -} diff --git a/pkg/apis/resource/v1alpha1/pipeline_resource_types.go b/pkg/apis/resource/v1alpha1/pipeline_resource_types.go deleted file mode 100644 index 332d447f5de..00000000000 --- a/pkg/apis/resource/v1alpha1/pipeline_resource_types.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 v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// PipelineResourceType represents the type of endpoint the pipelineResource is, so that the -// controller will know this pipelineResource shouldx be fetched and optionally what -// additional metatdata should be provided for it. -type PipelineResourceType = string - -var ( - // AllowedOutputResources are the resource types that can be used as outputs - AllowedOutputResources = map[PipelineResourceType]bool{ - PipelineResourceTypeStorage: true, - PipelineResourceTypeGit: true, - } -) - -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" - - // 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} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +genclient:noStatus - -// PipelineResource describes a resource that is an input to or output from a -// Task. -// -// +k8s:openapi-gen=true -type PipelineResource struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec holds the desired state of the PipelineResource from the client - Spec PipelineResourceSpec `json:"spec,omitempty"` - - // Status is used to communicate the observed state of the PipelineResource from - // the controller, but was unused as there is no controller for PipelineResource. - // - // Deprecated: Deprecated in v0.30.0. - // - // +optional - Status *PipelineResourceStatus `json:"status,omitempty"` -} - -// PipelineResourceStatus does not contain anything because PipelineResources on their own -// do not have a status -// -// Deprecated: Deprecated in v0.30.0. -type PipelineResourceStatus struct { -} - -// PipelineResourceSpec defines an individual resources used in the pipeline. -type PipelineResourceSpec struct { - // Description is a user-facing description of the resource that may be - // used to populate a UI. - // +optional - Description string `json:"description,omitempty"` - Type PipelineResourceType `json:"type"` - // +listType=atomic - Params []ResourceParam `json:"params"` - // Secrets to fetch to populate some of resource fields - // +optional - // +listType=atomic - SecretParams []SecretParam `json:"secrets,omitempty"` -} - -// SecretParam indicates which secret can be used to populate a field of the resource -type SecretParam struct { - FieldName string `json:"fieldName"` - SecretKey string `json:"secretKey"` - SecretName string `json:"secretName"` -} - -// ResourceParam declares a string value to use for the parameter called Name, and is used in -// the specific context of PipelineResources. -type ResourceParam struct { - Name string `json:"name"` - Value string `json:"value"` -} - -// ResourceDeclaration defines an input or output PipelineResource declared as a requirement -// by another type such as a Task or Condition. The Name field will be used to refer to these -// PipelineResources within the type's definition, and when provided as an Input, the Name will be the -// path to the volume mounted containing this PipelineResource as an input (e.g. -// an input Resource named `workspace` will be mounted at `/workspace`). -type ResourceDeclaration struct { - // Name declares the name by which a resource is referenced in the - // definition. Resources may be referenced by name in the definition of a - // Task's steps. - Name string `json:"name"` - // Type is the type of this resource; - Type PipelineResourceType `json:"type"` - // Description is a user-facing description of the declared resource that may be - // used to populate a UI. - // +optional - Description string `json:"description,omitempty"` - // TargetPath is the path in workspace directory where the resource - // will be copied. - // +optional - TargetPath string `json:"targetPath,omitempty"` - // Optional declares the resource as optional. - // By default optional is set to false which makes a resource required. - // optional: true - the resource is considered optional - // optional: false - the resource is considered required (equivalent of not specifying it) - Optional bool `json:"optional,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// PipelineResourceList contains a list of PipelineResources -type PipelineResourceList struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ListMeta `json:"metadata,omitempty"` - Items []PipelineResource `json:"items"` -} diff --git a/pkg/apis/resource/v1alpha1/pipelineresource_validation.go b/pkg/apis/resource/v1alpha1/pipelineresource_validation.go deleted file mode 100644 index f4004b05b97..00000000000 --- a/pkg/apis/resource/v1alpha1/pipelineresource_validation.go +++ /dev/null @@ -1,81 +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 v1alpha1 - -import ( - "context" - "strings" - - "github.com/tektoncd/pipeline/pkg/apis/validate" - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" -) - -var _ apis.Validatable = (*PipelineResource)(nil) - -// Validate validates the PipelineResource's ObjectMeta and Spec -func (r *PipelineResource) Validate(ctx context.Context) *apis.FieldError { - if err := validate.ObjectMetadata(r.GetObjectMeta()); err != nil { - return err.ViaField("metadata") - } - if apis.IsInDelete(ctx) { - return nil - } - return r.Spec.Validate(ctx) -} - -// Validate validates the PipelineResourceSpec based on its type -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 { - return nil - } - } - - 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 deleted file mode 100644 index 4f0ac3b8749..00000000000 --- a/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go +++ /dev/null @@ -1,151 +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 v1alpha1_test - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/test/diff" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -func TestResourceValidation_Invalid(t *testing.T) { - tests := []struct { - 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", - }}, - }, - }, - 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", - }}, - }, - }, - 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.ErrMissingField("spec.type"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := tt.res.Validate(context.Background()) - if d := cmp.Diff(tt.want.Error(), err.Error()); d != "" { - t.Errorf("Didn't get expected error for %s %s", tt.name, diff.PrintWantGot(d)) - } - }) - } -} - -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/register.go b/pkg/apis/resource/v1alpha1/register.go deleted file mode 100644 index 78367093f37..00000000000 --- a/pkg/apis/resource/v1alpha1/register.go +++ /dev/null @@ -1,54 +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 v1alpha1 - -import ( - "github.com/tektoncd/pipeline/pkg/apis/pipeline" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: pipeline.GroupName, Version: "v1alpha1"} - -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} - -var ( - schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - - // AddToScheme adds Build types to the scheme. - AddToScheme = schemeBuilder.AddToScheme -) - -// Adds the list of known types to Scheme. -func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &PipelineResource{}, - &PipelineResourceList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} 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 242f5d51ef2..00000000000 --- a/pkg/apis/resource/v1alpha1/storage/gcs_test.go +++ /dev/null @@ -1,455 +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" - - "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" - metav1 "k8s.io/apimachinery/pkg/apis/meta/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", -} - -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/apis/resource/v1alpha1/types_test.go b/pkg/apis/resource/v1alpha1/types_test.go deleted file mode 100644 index 3beb13d0b5a..00000000000 --- a/pkg/apis/resource/v1alpha1/types_test.go +++ /dev/null @@ -1,29 +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 v1alpha1_test - -import ( - "testing" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "knative.dev/pkg/webhook/resourcesemantics" -) - -func TestTypes(t *testing.T) { - // Assert that types satisfy webhook interface. - var _ resourcesemantics.GenericCRD = (*v1alpha1.PipelineResource)(nil) -} diff --git a/pkg/apis/resource/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/resource/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 5f6ff368b62..00000000000 --- a/pkg/apis/resource/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,181 +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 v1alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineResource) DeepCopyInto(out *PipelineResource) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - if in.Status != nil { - in, out := &in.Status, &out.Status - *out = new(PipelineResourceStatus) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineResource. -func (in *PipelineResource) DeepCopy() *PipelineResource { - if in == nil { - return nil - } - out := new(PipelineResource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PipelineResource) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineResourceList) DeepCopyInto(out *PipelineResourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]PipelineResource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineResourceList. -func (in *PipelineResourceList) DeepCopy() *PipelineResourceList { - if in == nil { - return nil - } - out := new(PipelineResourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PipelineResourceList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineResourceSpec) DeepCopyInto(out *PipelineResourceSpec) { - *out = *in - if in.Params != nil { - in, out := &in.Params, &out.Params - *out = make([]ResourceParam, len(*in)) - copy(*out, *in) - } - if in.SecretParams != nil { - in, out := &in.SecretParams, &out.SecretParams - *out = make([]SecretParam, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineResourceSpec. -func (in *PipelineResourceSpec) DeepCopy() *PipelineResourceSpec { - if in == nil { - return nil - } - out := new(PipelineResourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PipelineResourceStatus) DeepCopyInto(out *PipelineResourceStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineResourceStatus. -func (in *PipelineResourceStatus) DeepCopy() *PipelineResourceStatus { - if in == nil { - return nil - } - out := new(PipelineResourceStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourceDeclaration) DeepCopyInto(out *ResourceDeclaration) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceDeclaration. -func (in *ResourceDeclaration) DeepCopy() *ResourceDeclaration { - if in == nil { - return nil - } - out := new(ResourceDeclaration) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourceParam) DeepCopyInto(out *ResourceParam) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceParam. -func (in *ResourceParam) DeepCopy() *ResourceParam { - if in == nil { - return nil - } - out := new(ResourceParam) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SecretParam) DeepCopyInto(out *SecretParam) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretParam. -func (in *SecretParam) DeepCopy() *SecretParam { - if in == nil { - return nil - } - out := new(SecretParam) - 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 d352474a299..00000000000 --- a/pkg/artifacts/artifact_storage_test.go +++ /dev/null @@ -1,619 +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", - } - 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/client/resource/clientset/versioned/clientset.go b/pkg/client/resource/clientset/versioned/clientset.go deleted file mode 100644 index 9a624825bbb..00000000000 --- a/pkg/client/resource/clientset/versioned/clientset.go +++ /dev/null @@ -1,121 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package versioned - -import ( - "fmt" - "net/http" - - tektonv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1" - discovery "k8s.io/client-go/discovery" - rest "k8s.io/client-go/rest" - flowcontrol "k8s.io/client-go/util/flowcontrol" -) - -type Interface interface { - Discovery() discovery.DiscoveryInterface - TektonV1alpha1() tektonv1alpha1.TektonV1alpha1Interface -} - -// Clientset contains the clients for groups. Each group has exactly one -// version included in a Clientset. -type Clientset struct { - *discovery.DiscoveryClient - tektonV1alpha1 *tektonv1alpha1.TektonV1alpha1Client -} - -// TektonV1alpha1 retrieves the TektonV1alpha1Client -func (c *Clientset) TektonV1alpha1() tektonv1alpha1.TektonV1alpha1Interface { - return c.tektonV1alpha1 -} - -// Discovery retrieves the DiscoveryClient -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - if c == nil { - return nil - } - return c.DiscoveryClient -} - -// NewForConfig creates a new Clientset for the given config. -// If config's RateLimiter is not set and QPS and Burst are acceptable, -// NewForConfig will generate a rate-limiter in configShallowCopy. -// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), -// where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*Clientset, error) { - configShallowCopy := *c - - if configShallowCopy.UserAgent == "" { - configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() - } - - // share the transport between all clients - httpClient, err := rest.HTTPClientFor(&configShallowCopy) - if err != nil { - return nil, err - } - - return NewForConfigAndClient(&configShallowCopy, httpClient) -} - -// NewForConfigAndClient creates a new Clientset for the given config and http client. -// Note the http client provided takes precedence over the configured transport values. -// If config's RateLimiter is not set and QPS and Burst are acceptable, -// NewForConfigAndClient will generate a rate-limiter in configShallowCopy. -func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { - configShallowCopy := *c - if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { - if configShallowCopy.Burst <= 0 { - return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") - } - configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) - } - - var cs Clientset - var err error - cs.tektonV1alpha1, err = tektonv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } - - cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } - return &cs, nil -} - -// NewForConfigOrDie creates a new Clientset for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *Clientset { - cs, err := NewForConfig(c) - if err != nil { - panic(err) - } - return cs -} - -// New creates a new Clientset for the given RESTClient. -func New(c rest.Interface) *Clientset { - var cs Clientset - cs.tektonV1alpha1 = tektonv1alpha1.New(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClient(c) - return &cs -} diff --git a/pkg/client/resource/clientset/versioned/doc.go b/pkg/client/resource/clientset/versioned/doc.go deleted file mode 100644 index 0d13552ae28..00000000000 --- a/pkg/client/resource/clientset/versioned/doc.go +++ /dev/null @@ -1,20 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated clientset. -package versioned diff --git a/pkg/client/resource/clientset/versioned/fake/clientset_generated.go b/pkg/client/resource/clientset/versioned/fake/clientset_generated.go deleted file mode 100644 index 1d6881d7b97..00000000000 --- a/pkg/client/resource/clientset/versioned/fake/clientset_generated.go +++ /dev/null @@ -1,85 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - clientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - tektonv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1" - faketektonv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" - "k8s.io/client-go/testing" -) - -// NewSimpleClientset returns a clientset that will respond with the provided objects. -// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement -// for a real clientset and is mostly useful in simple unit tests. -func NewSimpleClientset(objects ...runtime.Object) *Clientset { - o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) - for _, obj := range objects { - if err := o.Add(obj); err != nil { - panic(err) - } - } - - cs := &Clientset{tracker: o} - cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} - cs.AddReactor("*", "*", testing.ObjectReaction(o)) - cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { - gvr := action.GetResource() - ns := action.GetNamespace() - watch, err := o.Watch(gvr, ns) - if err != nil { - return false, nil, err - } - return true, watch, nil - }) - - return cs -} - -// Clientset implements clientset.Interface. Meant to be embedded into a -// struct to get a default implementation. This makes faking out just the method -// you want to test easier. -type Clientset struct { - testing.Fake - discovery *fakediscovery.FakeDiscovery - tracker testing.ObjectTracker -} - -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -func (c *Clientset) Tracker() testing.ObjectTracker { - return c.tracker -} - -var ( - _ clientset.Interface = &Clientset{} - _ testing.FakeClient = &Clientset{} -) - -// TektonV1alpha1 retrieves the TektonV1alpha1Client -func (c *Clientset) TektonV1alpha1() tektonv1alpha1.TektonV1alpha1Interface { - return &faketektonv1alpha1.FakeTektonV1alpha1{Fake: &c.Fake} -} diff --git a/pkg/client/resource/clientset/versioned/fake/doc.go b/pkg/client/resource/clientset/versioned/fake/doc.go deleted file mode 100644 index 4e4dbb68181..00000000000 --- a/pkg/client/resource/clientset/versioned/fake/doc.go +++ /dev/null @@ -1,20 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated fake clientset. -package fake diff --git a/pkg/client/resource/clientset/versioned/fake/register.go b/pkg/client/resource/clientset/versioned/fake/register.go deleted file mode 100644 index e33dea7aa03..00000000000 --- a/pkg/client/resource/clientset/versioned/fake/register.go +++ /dev/null @@ -1,56 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - tektonv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" -) - -var scheme = runtime.NewScheme() -var codecs = serializer.NewCodecFactory(scheme) - -var localSchemeBuilder = runtime.SchemeBuilder{ - tektonv1alpha1.AddToScheme, -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -var AddToScheme = localSchemeBuilder.AddToScheme - -func init() { - v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) - utilruntime.Must(AddToScheme(scheme)) -} diff --git a/pkg/client/resource/clientset/versioned/scheme/doc.go b/pkg/client/resource/clientset/versioned/scheme/doc.go deleted file mode 100644 index 0fb16cc0567..00000000000 --- a/pkg/client/resource/clientset/versioned/scheme/doc.go +++ /dev/null @@ -1,20 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package contains the scheme of the automatically generated clientset. -package scheme diff --git a/pkg/client/resource/clientset/versioned/scheme/register.go b/pkg/client/resource/clientset/versioned/scheme/register.go deleted file mode 100644 index 972999462fa..00000000000 --- a/pkg/client/resource/clientset/versioned/scheme/register.go +++ /dev/null @@ -1,56 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package scheme - -import ( - tektonv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) -var localSchemeBuilder = runtime.SchemeBuilder{ - tektonv1alpha1.AddToScheme, -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -var AddToScheme = localSchemeBuilder.AddToScheme - -func init() { - v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) - utilruntime.Must(AddToScheme(Scheme)) -} diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/doc.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/doc.go deleted file mode 100644 index 69ed294b828..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/doc.go +++ /dev/null @@ -1,20 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated typed clients. -package v1alpha1 diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/doc.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/doc.go deleted file mode 100644 index 1a72e0befe2..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/doc.go +++ /dev/null @@ -1,20 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go deleted file mode 100644 index 8ffb1b7ff81..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go +++ /dev/null @@ -1,130 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakePipelineResources implements PipelineResourceInterface -type FakePipelineResources struct { - Fake *FakeTektonV1alpha1 - ns string -} - -var pipelineresourcesResource = schema.GroupVersionResource{Group: "tekton.dev", Version: "v1alpha1", Resource: "pipelineresources"} - -var pipelineresourcesKind = schema.GroupVersionKind{Group: "tekton.dev", Version: "v1alpha1", Kind: "PipelineResource"} - -// Get takes name of the pipelineResource, and returns the corresponding pipelineResource object, and an error if there is any. -func (c *FakePipelineResources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PipelineResource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(pipelineresourcesResource, c.ns, name), &v1alpha1.PipelineResource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PipelineResource), err -} - -// List takes label and field selectors, and returns the list of PipelineResources that match those selectors. -func (c *FakePipelineResources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PipelineResourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(pipelineresourcesResource, pipelineresourcesKind, c.ns, opts), &v1alpha1.PipelineResourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.PipelineResourceList{ListMeta: obj.(*v1alpha1.PipelineResourceList).ListMeta} - for _, item := range obj.(*v1alpha1.PipelineResourceList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested pipelineResources. -func (c *FakePipelineResources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(pipelineresourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a pipelineResource and creates it. Returns the server's representation of the pipelineResource, and an error, if there is any. -func (c *FakePipelineResources) Create(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.CreateOptions) (result *v1alpha1.PipelineResource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(pipelineresourcesResource, c.ns, pipelineResource), &v1alpha1.PipelineResource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PipelineResource), err -} - -// Update takes the representation of a pipelineResource and updates it. Returns the server's representation of the pipelineResource, and an error, if there is any. -func (c *FakePipelineResources) Update(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.UpdateOptions) (result *v1alpha1.PipelineResource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pipelineresourcesResource, c.ns, pipelineResource), &v1alpha1.PipelineResource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PipelineResource), err -} - -// Delete takes name of the pipelineResource and deletes it. Returns an error if one occurs. -func (c *FakePipelineResources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(pipelineresourcesResource, c.ns, name, opts), &v1alpha1.PipelineResource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakePipelineResources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pipelineresourcesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.PipelineResourceList{}) - return err -} - -// Patch applies the patch and returns the patched pipelineResource. -func (c *FakePipelineResources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PipelineResource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pipelineresourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.PipelineResource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PipelineResource), err -} diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_resource_client.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_resource_client.go deleted file mode 100644 index 44cc7f52002..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_resource_client.go +++ /dev/null @@ -1,40 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1" - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" -) - -type FakeTektonV1alpha1 struct { - *testing.Fake -} - -func (c *FakeTektonV1alpha1) PipelineResources(namespace string) v1alpha1.PipelineResourceInterface { - return &FakePipelineResources{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeTektonV1alpha1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/generated_expansion.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/generated_expansion.go deleted file mode 100644 index 1536d99ffb8..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/generated_expansion.go +++ /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 - - 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 client-gen. DO NOT EDIT. - -package v1alpha1 - -type PipelineResourceExpansion interface{} diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go deleted file mode 100644 index ec03040eebe..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go +++ /dev/null @@ -1,178 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - "time" - - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - scheme "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" -) - -// PipelineResourcesGetter has a method to return a PipelineResourceInterface. -// A group's client should implement this interface. -type PipelineResourcesGetter interface { - PipelineResources(namespace string) PipelineResourceInterface -} - -// PipelineResourceInterface has methods to work with PipelineResource resources. -type PipelineResourceInterface interface { - Create(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.CreateOptions) (*v1alpha1.PipelineResource, error) - Update(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.UpdateOptions) (*v1alpha1.PipelineResource, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.PipelineResource, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PipelineResourceList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PipelineResource, err error) - PipelineResourceExpansion -} - -// pipelineResources implements PipelineResourceInterface -type pipelineResources struct { - client rest.Interface - ns string -} - -// newPipelineResources returns a PipelineResources -func newPipelineResources(c *TektonV1alpha1Client, namespace string) *pipelineResources { - return &pipelineResources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the pipelineResource, and returns the corresponding pipelineResource object, and an error if there is any. -func (c *pipelineResources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineresources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of PipelineResources that match those selectors. -func (c *pipelineResources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PipelineResourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.PipelineResourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineresources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pipelineResources. -func (c *pipelineResources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("pipelineresources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pipelineResource and creates it. Returns the server's representation of the pipelineResource, and an error, if there is any. -func (c *pipelineResources) Create(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.CreateOptions) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pipelineresources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineResource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pipelineResource and updates it. Returns the server's representation of the pipelineResource, and an error, if there is any. -func (c *pipelineResources) Update(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.UpdateOptions) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelineresources"). - Name(pipelineResource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineResource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pipelineResource and deletes it. Returns an error if one occurs. -func (c *pipelineResources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelineresources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pipelineResources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelineresources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pipelineResource. -func (c *pipelineResources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pipelineresources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/resource_client.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/resource_client.go deleted file mode 100644 index eaf177014b9..00000000000 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/resource_client.go +++ /dev/null @@ -1,107 +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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "net/http" - - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/scheme" - rest "k8s.io/client-go/rest" -) - -type TektonV1alpha1Interface interface { - RESTClient() rest.Interface - PipelineResourcesGetter -} - -// TektonV1alpha1Client is used to interact with features provided by the tekton.dev group. -type TektonV1alpha1Client struct { - restClient rest.Interface -} - -func (c *TektonV1alpha1Client) PipelineResources(namespace string) PipelineResourceInterface { - return newPipelineResources(c, namespace) -} - -// NewForConfig creates a new TektonV1alpha1Client for the given config. -// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), -// where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*TektonV1alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - httpClient, err := rest.HTTPClientFor(&config) - if err != nil { - return nil, err - } - return NewForConfigAndClient(&config, httpClient) -} - -// NewForConfigAndClient creates a new TektonV1alpha1Client for the given config and http client. -// Note the http client provided takes precedence over the configured transport values. -func NewForConfigAndClient(c *rest.Config, h *http.Client) (*TektonV1alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - client, err := rest.RESTClientForConfigAndClient(&config, h) - if err != nil { - return nil, err - } - return &TektonV1alpha1Client{client}, nil -} - -// NewForConfigOrDie creates a new TektonV1alpha1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *TektonV1alpha1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new TektonV1alpha1Client for the given RESTClient. -func New(c rest.Interface) *TektonV1alpha1Client { - return &TektonV1alpha1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v1alpha1.SchemeGroupVersion - config.GroupVersion = &gv - config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() - - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } - - return nil -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *TektonV1alpha1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/pkg/client/resource/informers/externalversions/factory.go b/pkg/client/resource/informers/externalversions/factory.go deleted file mode 100644 index c2d3a2292f3..00000000000 --- a/pkg/client/resource/informers/externalversions/factory.go +++ /dev/null @@ -1,180 +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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package externalversions - -import ( - reflect "reflect" - sync "sync" - time "time" - - versioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/internalinterfaces" - resource "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" -) - -// SharedInformerOption defines the functional option type for SharedInformerFactory. -type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory - -type sharedInformerFactory struct { - client versioned.Interface - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc - lock sync.Mutex - defaultResync time.Duration - customResync map[reflect.Type]time.Duration - - informers map[reflect.Type]cache.SharedIndexInformer - // startedInformers is used for tracking which informers have been started. - // This allows Start() to be called multiple times safely. - startedInformers map[reflect.Type]bool -} - -// WithCustomResyncConfig sets a custom resync period for the specified informer types. -func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { - return func(factory *sharedInformerFactory) *sharedInformerFactory { - for k, v := range resyncConfig { - factory.customResync[reflect.TypeOf(k)] = v - } - return factory - } -} - -// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. -func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { - return func(factory *sharedInformerFactory) *sharedInformerFactory { - factory.tweakListOptions = tweakListOptions - return factory - } -} - -// WithNamespace limits the SharedInformerFactory to the specified namespace. -func WithNamespace(namespace string) SharedInformerOption { - return func(factory *sharedInformerFactory) *sharedInformerFactory { - factory.namespace = namespace - return factory - } -} - -// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { - return NewSharedInformerFactoryWithOptions(client, defaultResync) -} - -// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. -// Listers obtained via this SharedInformerFactory will be subject to the same filters -// as specified here. -// Deprecated: Please use NewSharedInformerFactoryWithOptions instead -func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { - return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) -} - -// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { - factory := &sharedInformerFactory{ - client: client, - namespace: v1.NamespaceAll, - defaultResync: defaultResync, - informers: make(map[reflect.Type]cache.SharedIndexInformer), - startedInformers: make(map[reflect.Type]bool), - customResync: make(map[reflect.Type]time.Duration), - } - - // Apply all options - for _, opt := range options { - factory = opt(factory) - } - - return factory -} - -// Start initializes all requested informers. -func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { - f.lock.Lock() - defer f.lock.Unlock() - - for informerType, informer := range f.informers { - if !f.startedInformers[informerType] { - go informer.Run(stopCh) - f.startedInformers[informerType] = true - } - } -} - -// WaitForCacheSync waits for all started informers' cache were synced. -func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { - informers := func() map[reflect.Type]cache.SharedIndexInformer { - f.lock.Lock() - defer f.lock.Unlock() - - informers := map[reflect.Type]cache.SharedIndexInformer{} - for informerType, informer := range f.informers { - if f.startedInformers[informerType] { - informers[informerType] = informer - } - } - return informers - }() - - res := map[reflect.Type]bool{} - for informType, informer := range informers { - res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) - } - return res -} - -// InternalInformerFor returns the SharedIndexInformer for obj using an internal -// client. -func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { - f.lock.Lock() - defer f.lock.Unlock() - - informerType := reflect.TypeOf(obj) - informer, exists := f.informers[informerType] - if exists { - return informer - } - - resyncPeriod, exists := f.customResync[informerType] - if !exists { - resyncPeriod = f.defaultResync - } - - informer = newFunc(f.client, resyncPeriod) - f.informers[informerType] = informer - - return informer -} - -// SharedInformerFactory provides shared informers for resources in all known -// API group versions. -type SharedInformerFactory interface { - internalinterfaces.SharedInformerFactory - ForResource(resource schema.GroupVersionResource) (GenericInformer, error) - WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - - Tekton() resource.Interface -} - -func (f *sharedInformerFactory) Tekton() resource.Interface { - return resource.New(f, f.namespace, f.tweakListOptions) -} diff --git a/pkg/client/resource/informers/externalversions/generic.go b/pkg/client/resource/informers/externalversions/generic.go deleted file mode 100644 index 5d1d77acd6a..00000000000 --- a/pkg/client/resource/informers/externalversions/generic.go +++ /dev/null @@ -1,62 +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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package externalversions - -import ( - "fmt" - - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" -) - -// GenericInformer is type of SharedIndexInformer which will locate and delegate to other -// sharedInformers based on type -type GenericInformer interface { - Informer() cache.SharedIndexInformer - Lister() cache.GenericLister -} - -type genericInformer struct { - informer cache.SharedIndexInformer - resource schema.GroupResource -} - -// Informer returns the SharedIndexInformer. -func (f *genericInformer) Informer() cache.SharedIndexInformer { - return f.informer -} - -// Lister returns the GenericLister. -func (f *genericInformer) Lister() cache.GenericLister { - return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) -} - -// ForResource gives generic access to a shared informer of the matching type -// TODO extend this to unknown resources with a client pool -func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { - switch resource { - // Group=tekton.dev, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithResource("pipelineresources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Tekton().V1alpha1().PipelineResources().Informer()}, nil - - } - - return nil, fmt.Errorf("no informer found for %v", resource) -} diff --git a/pkg/client/resource/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/resource/informers/externalversions/internalinterfaces/factory_interfaces.go deleted file mode 100644 index 1a7c773e02b..00000000000 --- a/pkg/client/resource/informers/externalversions/internalinterfaces/factory_interfaces.go +++ /dev/null @@ -1,40 +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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package internalinterfaces - -import ( - time "time" - - versioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - cache "k8s.io/client-go/tools/cache" -) - -// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. -type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer - -// SharedInformerFactory a small interface to allow for adding an informer without an import cycle -type SharedInformerFactory interface { - Start(stopCh <-chan struct{}) - InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer -} - -// TweakListOptionsFunc is a function that transforms a v1.ListOptions. -type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/client/resource/informers/externalversions/resource/interface.go b/pkg/client/resource/informers/externalversions/resource/interface.go deleted file mode 100644 index aed88a590b4..00000000000 --- a/pkg/client/resource/informers/externalversions/resource/interface.go +++ /dev/null @@ -1,46 +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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package resource - -import ( - internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource/v1alpha1" -) - -// Interface provides access to each of this group's versions. -type Interface interface { - // V1alpha1 provides access to shared informers for resources in V1alpha1. - V1alpha1() v1alpha1.Interface -} - -type group struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// V1alpha1 returns a new v1alpha1.Interface. -func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} diff --git a/pkg/client/resource/informers/externalversions/resource/v1alpha1/interface.go b/pkg/client/resource/informers/externalversions/resource/v1alpha1/interface.go deleted file mode 100644 index d541d43917f..00000000000 --- a/pkg/client/resource/informers/externalversions/resource/v1alpha1/interface.go +++ /dev/null @@ -1,45 +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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // PipelineResources returns a PipelineResourceInformer. - PipelineResources() PipelineResourceInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// PipelineResources returns a PipelineResourceInformer. -func (v *version) PipelineResources() PipelineResourceInformer { - return &pipelineResourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/resource/informers/externalversions/resource/v1alpha1/pipelineresource.go b/pkg/client/resource/informers/externalversions/resource/v1alpha1/pipelineresource.go deleted file mode 100644 index a814fe80082..00000000000 --- a/pkg/client/resource/informers/externalversions/resource/v1alpha1/pipelineresource.go +++ /dev/null @@ -1,90 +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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - time "time" - - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - versioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/listers/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// PipelineResourceInformer provides access to a shared informer and lister for -// PipelineResources. -type PipelineResourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.PipelineResourceLister -} - -type pipelineResourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewPipelineResourceInformer constructs a new informer for PipelineResource type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewPipelineResourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredPipelineResourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredPipelineResourceInformer constructs a new informer for PipelineResource type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredPipelineResourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.TektonV1alpha1().PipelineResources(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.TektonV1alpha1().PipelineResources(namespace).Watch(context.TODO(), options) - }, - }, - &resourcev1alpha1.PipelineResource{}, - resyncPeriod, - indexers, - ) -} - -func (f *pipelineResourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredPipelineResourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *pipelineResourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&resourcev1alpha1.PipelineResource{}, f.defaultInformer) -} - -func (f *pipelineResourceInformer) Lister() v1alpha1.PipelineResourceLister { - return v1alpha1.NewPipelineResourceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/resource/injection/client/client.go b/pkg/client/resource/injection/client/client.go deleted file mode 100644 index e58dce9e3b8..00000000000 --- a/pkg/client/resource/injection/client/client.go +++ /dev/null @@ -1,243 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package client - -import ( - context "context" - json "encoding/json" - errors "errors" - fmt "fmt" - - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - versioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - typedtektonv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - discovery "k8s.io/client-go/discovery" - dynamic "k8s.io/client-go/dynamic" - rest "k8s.io/client-go/rest" - injection "knative.dev/pkg/injection" - dynamicclient "knative.dev/pkg/injection/clients/dynamicclient" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterClient(withClientFromConfig) - injection.Default.RegisterClientFetcher(func(ctx context.Context) interface{} { - return Get(ctx) - }) - injection.Dynamic.RegisterDynamicClient(withClientFromDynamic) -} - -// Key is used as the key for associating information with a context.Context. -type Key struct{} - -func withClientFromConfig(ctx context.Context, cfg *rest.Config) context.Context { - return context.WithValue(ctx, Key{}, versioned.NewForConfigOrDie(cfg)) -} - -func withClientFromDynamic(ctx context.Context) context.Context { - return context.WithValue(ctx, Key{}, &wrapClient{dyn: dynamicclient.Get(ctx)}) -} - -// Get extracts the versioned.Interface client from the context. -func Get(ctx context.Context) versioned.Interface { - untyped := ctx.Value(Key{}) - if untyped == nil { - if injection.GetConfig(ctx) == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned.Interface from context. This context is not the application context (which is typically given to constructors via sharedmain).") - } else { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned.Interface from context.") - } - } - return untyped.(versioned.Interface) -} - -type wrapClient struct { - dyn dynamic.Interface -} - -var _ versioned.Interface = (*wrapClient)(nil) - -func (w *wrapClient) Discovery() discovery.DiscoveryInterface { - panic("Discovery called on dynamic client!") -} - -func convert(from interface{}, to runtime.Object) error { - bs, err := json.Marshal(from) - if err != nil { - return fmt.Errorf("Marshal() = %w", err) - } - if err := json.Unmarshal(bs, to); err != nil { - return fmt.Errorf("Unmarshal() = %w", err) - } - return nil -} - -// TektonV1alpha1 retrieves the TektonV1alpha1Client -func (w *wrapClient) TektonV1alpha1() typedtektonv1alpha1.TektonV1alpha1Interface { - return &wrapTektonV1alpha1{ - dyn: w.dyn, - } -} - -type wrapTektonV1alpha1 struct { - dyn dynamic.Interface -} - -func (w *wrapTektonV1alpha1) RESTClient() rest.Interface { - panic("RESTClient called on dynamic client!") -} - -func (w *wrapTektonV1alpha1) PipelineResources(namespace string) typedtektonv1alpha1.PipelineResourceInterface { - return &wrapTektonV1alpha1PipelineResourceImpl{ - dyn: w.dyn.Resource(schema.GroupVersionResource{ - Group: "tekton.dev", - Version: "v1alpha1", - Resource: "pipelineresources", - }), - - namespace: namespace, - } -} - -type wrapTektonV1alpha1PipelineResourceImpl struct { - dyn dynamic.NamespaceableResourceInterface - - namespace string -} - -var _ typedtektonv1alpha1.PipelineResourceInterface = (*wrapTektonV1alpha1PipelineResourceImpl)(nil) - -func (w *wrapTektonV1alpha1PipelineResourceImpl) Create(ctx context.Context, in *v1alpha1.PipelineResource, opts v1.CreateOptions) (*v1alpha1.PipelineResource, error) { - in.SetGroupVersionKind(schema.GroupVersionKind{ - Group: "tekton.dev", - Version: "v1alpha1", - Kind: "PipelineResource", - }) - uo := &unstructured.Unstructured{} - if err := convert(in, uo); err != nil { - return nil, err - } - uo, err := w.dyn.Namespace(w.namespace).Create(ctx, uo, opts) - if err != nil { - return nil, err - } - out := &v1alpha1.PipelineResource{} - if err := convert(uo, out); err != nil { - return nil, err - } - return out, nil -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return w.dyn.Namespace(w.namespace).Delete(ctx, name, opts) -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - return w.dyn.Namespace(w.namespace).DeleteCollection(ctx, opts, listOpts) -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.PipelineResource, error) { - uo, err := w.dyn.Namespace(w.namespace).Get(ctx, name, opts) - if err != nil { - return nil, err - } - out := &v1alpha1.PipelineResource{} - if err := convert(uo, out); err != nil { - return nil, err - } - return out, nil -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PipelineResourceList, error) { - uo, err := w.dyn.Namespace(w.namespace).List(ctx, opts) - if err != nil { - return nil, err - } - out := &v1alpha1.PipelineResourceList{} - if err := convert(uo, out); err != nil { - return nil, err - } - return out, nil -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PipelineResource, err error) { - uo, err := w.dyn.Namespace(w.namespace).Patch(ctx, name, pt, data, opts) - if err != nil { - return nil, err - } - out := &v1alpha1.PipelineResource{} - if err := convert(uo, out); err != nil { - return nil, err - } - return out, nil -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) Update(ctx context.Context, in *v1alpha1.PipelineResource, opts v1.UpdateOptions) (*v1alpha1.PipelineResource, error) { - in.SetGroupVersionKind(schema.GroupVersionKind{ - Group: "tekton.dev", - Version: "v1alpha1", - Kind: "PipelineResource", - }) - uo := &unstructured.Unstructured{} - if err := convert(in, uo); err != nil { - return nil, err - } - uo, err := w.dyn.Namespace(w.namespace).Update(ctx, uo, opts) - if err != nil { - return nil, err - } - out := &v1alpha1.PipelineResource{} - if err := convert(uo, out); err != nil { - return nil, err - } - return out, nil -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) UpdateStatus(ctx context.Context, in *v1alpha1.PipelineResource, opts v1.UpdateOptions) (*v1alpha1.PipelineResource, error) { - in.SetGroupVersionKind(schema.GroupVersionKind{ - Group: "tekton.dev", - Version: "v1alpha1", - Kind: "PipelineResource", - }) - uo := &unstructured.Unstructured{} - if err := convert(in, uo); err != nil { - return nil, err - } - uo, err := w.dyn.Namespace(w.namespace).UpdateStatus(ctx, uo, opts) - if err != nil { - return nil, err - } - out := &v1alpha1.PipelineResource{} - if err := convert(uo, out); err != nil { - return nil, err - } - return out, nil -} - -func (w *wrapTektonV1alpha1PipelineResourceImpl) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return nil, errors.New("NYI: Watch") -} diff --git a/pkg/client/resource/injection/client/fake/fake.go b/pkg/client/resource/injection/client/fake/fake.go deleted file mode 100644 index 1447b8e6ace..00000000000 --- a/pkg/client/resource/injection/client/fake/fake.go +++ /dev/null @@ -1,57 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/fake" - client "github.com/tektoncd/pipeline/pkg/client/resource/injection/client" - runtime "k8s.io/apimachinery/pkg/runtime" - rest "k8s.io/client-go/rest" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Fake.RegisterClient(withClient) - injection.Fake.RegisterClientFetcher(func(ctx context.Context) interface{} { - return Get(ctx) - }) -} - -func withClient(ctx context.Context, cfg *rest.Config) context.Context { - ctx, _ = With(ctx) - return ctx -} - -func With(ctx context.Context, objects ...runtime.Object) (context.Context, *fake.Clientset) { - cs := fake.NewSimpleClientset(objects...) - return context.WithValue(ctx, client.Key{}, cs), cs -} - -// Get extracts the Kubernetes client from the context. -func Get(ctx context.Context) *fake.Clientset { - untyped := ctx.Value(client.Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/fake.Clientset from context.") - } - return untyped.(*fake.Clientset) -} diff --git a/pkg/client/resource/injection/informers/factory/factory.go b/pkg/client/resource/injection/informers/factory/factory.go deleted file mode 100644 index ea517cdfd0e..00000000000 --- a/pkg/client/resource/injection/informers/factory/factory.go +++ /dev/null @@ -1,56 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package factory - -import ( - context "context" - - externalversions "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions" - client "github.com/tektoncd/pipeline/pkg/client/resource/injection/client" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformerFactory(withInformerFactory) -} - -// Key is used as the key for associating information with a context.Context. -type Key struct{} - -func withInformerFactory(ctx context.Context) context.Context { - c := client.Get(ctx) - opts := make([]externalversions.SharedInformerOption, 0, 1) - if injection.HasNamespaceScope(ctx) { - opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx))) - } - return context.WithValue(ctx, Key{}, - externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...)) -} - -// Get extracts the InformerFactory from the context. -func Get(ctx context.Context) externalversions.SharedInformerFactory { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions.SharedInformerFactory from context.") - } - return untyped.(externalversions.SharedInformerFactory) -} diff --git a/pkg/client/resource/injection/informers/factory/fake/fake.go b/pkg/client/resource/injection/informers/factory/fake/fake.go deleted file mode 100644 index fdb9e625960..00000000000 --- a/pkg/client/resource/injection/informers/factory/fake/fake.go +++ /dev/null @@ -1,45 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - externalversions "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions" - fake "github.com/tektoncd/pipeline/pkg/client/resource/injection/client/fake" - factory "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = factory.Get - -func init() { - injection.Fake.RegisterInformerFactory(withInformerFactory) -} - -func withInformerFactory(ctx context.Context) context.Context { - c := fake.Get(ctx) - opts := make([]externalversions.SharedInformerOption, 0, 1) - if injection.HasNamespaceScope(ctx) { - opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx))) - } - return context.WithValue(ctx, factory.Key{}, - externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...)) -} diff --git a/pkg/client/resource/injection/informers/factory/filtered/fake/fake_filtered_factory.go b/pkg/client/resource/injection/informers/factory/filtered/fake/fake_filtered_factory.go deleted file mode 100644 index 6fdf67aee1b..00000000000 --- a/pkg/client/resource/injection/informers/factory/filtered/fake/fake_filtered_factory.go +++ /dev/null @@ -1,59 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fakeFilteredFactory - -import ( - context "context" - - externalversions "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions" - fake "github.com/tektoncd/pipeline/pkg/client/resource/injection/client/fake" - filtered "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/factory/filtered" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -var Get = filtered.Get - -func init() { - injection.Fake.RegisterInformerFactory(withInformerFactory) -} - -func withInformerFactory(ctx context.Context) context.Context { - c := fake.Get(ctx) - untyped := ctx.Value(filtered.LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - for _, selector := range labelSelectors { - opts := []externalversions.SharedInformerOption{} - if injection.HasNamespaceScope(ctx) { - opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx))) - } - opts = append(opts, externalversions.WithTweakListOptions(func(l *v1.ListOptions) { - l.LabelSelector = selector - })) - ctx = context.WithValue(ctx, filtered.Key{Selector: selector}, - externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...)) - } - return ctx -} diff --git a/pkg/client/resource/injection/informers/factory/filtered/filtered_factory.go b/pkg/client/resource/injection/informers/factory/filtered/filtered_factory.go deleted file mode 100644 index 560e97f91d2..00000000000 --- a/pkg/client/resource/injection/informers/factory/filtered/filtered_factory.go +++ /dev/null @@ -1,77 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package filteredFactory - -import ( - context "context" - - externalversions "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions" - client "github.com/tektoncd/pipeline/pkg/client/resource/injection/client" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformerFactory(withInformerFactory) -} - -// Key is used as the key for associating information with a context.Context. -type Key struct { - Selector string -} - -type LabelKey struct{} - -func WithSelectors(ctx context.Context, selector ...string) context.Context { - return context.WithValue(ctx, LabelKey{}, selector) -} - -func withInformerFactory(ctx context.Context) context.Context { - c := client.Get(ctx) - untyped := ctx.Value(LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - for _, selector := range labelSelectors { - opts := []externalversions.SharedInformerOption{} - if injection.HasNamespaceScope(ctx) { - opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx))) - } - opts = append(opts, externalversions.WithTweakListOptions(func(l *v1.ListOptions) { - l.LabelSelector = selector - })) - ctx = context.WithValue(ctx, Key{Selector: selector}, - externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...)) - } - return ctx -} - -// Get extracts the InformerFactory from the context. -func Get(ctx context.Context, selector string) externalversions.SharedInformerFactory { - untyped := ctx.Value(Key{Selector: selector}) - if untyped == nil { - logging.FromContext(ctx).Panicf( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions.SharedInformerFactory with selector %s from context.", selector) - } - return untyped.(externalversions.SharedInformerFactory) -} diff --git a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/fake/fake.go b/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/fake/fake.go deleted file mode 100644 index a3aee746b78..00000000000 --- a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/fake/fake.go +++ /dev/null @@ -1,40 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/factory/fake" - pipelineresource "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = pipelineresource.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Tekton().V1alpha1().PipelineResources() - return context.WithValue(ctx, pipelineresource.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/fake/fake.go b/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/fake/fake.go deleted file mode 100644 index f6dbee6aea3..00000000000 --- a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/fake/fake.go +++ /dev/null @@ -1,52 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - factoryfiltered "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/factory/filtered" - filtered "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -var Get = filtered.Get - -func init() { - injection.Fake.RegisterFilteredInformers(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, []controller.Informer) { - untyped := ctx.Value(factoryfiltered.LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - infs := []controller.Informer{} - for _, selector := range labelSelectors { - f := factoryfiltered.Get(ctx, selector) - inf := f.Tekton().V1alpha1().PipelineResources() - ctx = context.WithValue(ctx, filtered.Key{Selector: selector}, inf) - infs = append(infs, inf.Informer()) - } - return ctx, infs -} diff --git a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/pipelineresource.go b/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/pipelineresource.go deleted file mode 100644 index 48883e46269..00000000000 --- a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/filtered/pipelineresource.go +++ /dev/null @@ -1,136 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package filtered - -import ( - context "context" - - apisresourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - versioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - v1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource/v1alpha1" - client "github.com/tektoncd/pipeline/pkg/client/resource/injection/client" - filtered "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/factory/filtered" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/listers/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - cache "k8s.io/client-go/tools/cache" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterFilteredInformers(withInformer) - injection.Dynamic.RegisterDynamicInformer(withDynamicInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct { - Selector string -} - -func withInformer(ctx context.Context) (context.Context, []controller.Informer) { - untyped := ctx.Value(filtered.LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - infs := []controller.Informer{} - for _, selector := range labelSelectors { - f := filtered.Get(ctx, selector) - inf := f.Tekton().V1alpha1().PipelineResources() - ctx = context.WithValue(ctx, Key{Selector: selector}, inf) - infs = append(infs, inf.Informer()) - } - return ctx, infs -} - -func withDynamicInformer(ctx context.Context) context.Context { - untyped := ctx.Value(filtered.LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - for _, selector := range labelSelectors { - inf := &wrapper{client: client.Get(ctx), selector: selector} - ctx = context.WithValue(ctx, Key{Selector: selector}, inf) - } - return ctx -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context, selector string) v1alpha1.PipelineResourceInformer { - untyped := ctx.Value(Key{Selector: selector}) - if untyped == nil { - logging.FromContext(ctx).Panicf( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource/v1alpha1.PipelineResourceInformer with selector %s from context.", selector) - } - return untyped.(v1alpha1.PipelineResourceInformer) -} - -type wrapper struct { - client versioned.Interface - - namespace string - - selector string -} - -var _ v1alpha1.PipelineResourceInformer = (*wrapper)(nil) -var _ resourcev1alpha1.PipelineResourceLister = (*wrapper)(nil) - -func (w *wrapper) Informer() cache.SharedIndexInformer { - return cache.NewSharedIndexInformer(nil, &apisresourcev1alpha1.PipelineResource{}, 0, nil) -} - -func (w *wrapper) Lister() resourcev1alpha1.PipelineResourceLister { - return w -} - -func (w *wrapper) PipelineResources(namespace string) resourcev1alpha1.PipelineResourceNamespaceLister { - return &wrapper{client: w.client, namespace: namespace, selector: w.selector} -} - -func (w *wrapper) List(selector labels.Selector) (ret []*apisresourcev1alpha1.PipelineResource, err error) { - reqs, err := labels.ParseToRequirements(w.selector) - if err != nil { - return nil, err - } - selector = selector.Add(reqs...) - lo, err := w.client.TektonV1alpha1().PipelineResources(w.namespace).List(context.TODO(), v1.ListOptions{ - LabelSelector: selector.String(), - // TODO(mattmoor): Incorporate resourceVersion bounds based on staleness criteria. - }) - if err != nil { - return nil, err - } - for idx := range lo.Items { - ret = append(ret, &lo.Items[idx]) - } - return ret, nil -} - -func (w *wrapper) Get(name string) (*apisresourcev1alpha1.PipelineResource, error) { - // TODO(mattmoor): Check that the fetched object matches the selector. - return w.client.TektonV1alpha1().PipelineResources(w.namespace).Get(context.TODO(), name, v1.GetOptions{ - // TODO(mattmoor): Incorporate resourceVersion bounds based on staleness criteria. - }) -} diff --git a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/pipelineresource.go b/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/pipelineresource.go deleted file mode 100644 index 6dde6ad326b..00000000000 --- a/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/pipelineresource.go +++ /dev/null @@ -1,116 +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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package pipelineresource - -import ( - context "context" - - apisresourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - versioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - v1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource/v1alpha1" - client "github.com/tektoncd/pipeline/pkg/client/resource/injection/client" - factory "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/factory" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/listers/resource/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - cache "k8s.io/client-go/tools/cache" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) - injection.Dynamic.RegisterDynamicInformer(withDynamicInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Tekton().V1alpha1().PipelineResources() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -func withDynamicInformer(ctx context.Context) context.Context { - inf := &wrapper{client: client.Get(ctx), resourceVersion: injection.GetResourceVersion(ctx)} - return context.WithValue(ctx, Key{}, inf) -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.PipelineResourceInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource/v1alpha1.PipelineResourceInformer from context.") - } - return untyped.(v1alpha1.PipelineResourceInformer) -} - -type wrapper struct { - client versioned.Interface - - namespace string - - resourceVersion string -} - -var _ v1alpha1.PipelineResourceInformer = (*wrapper)(nil) -var _ resourcev1alpha1.PipelineResourceLister = (*wrapper)(nil) - -func (w *wrapper) Informer() cache.SharedIndexInformer { - return cache.NewSharedIndexInformer(nil, &apisresourcev1alpha1.PipelineResource{}, 0, nil) -} - -func (w *wrapper) Lister() resourcev1alpha1.PipelineResourceLister { - return w -} - -func (w *wrapper) PipelineResources(namespace string) resourcev1alpha1.PipelineResourceNamespaceLister { - return &wrapper{client: w.client, namespace: namespace, resourceVersion: w.resourceVersion} -} - -// SetResourceVersion allows consumers to adjust the minimum resourceVersion -// used by the underlying client. It is not accessible via the standard -// lister interface, but can be accessed through a user-defined interface and -// an implementation check e.g. rvs, ok := foo.(ResourceVersionSetter) -func (w *wrapper) SetResourceVersion(resourceVersion string) { - w.resourceVersion = resourceVersion -} - -func (w *wrapper) List(selector labels.Selector) (ret []*apisresourcev1alpha1.PipelineResource, err error) { - lo, err := w.client.TektonV1alpha1().PipelineResources(w.namespace).List(context.TODO(), v1.ListOptions{ - LabelSelector: selector.String(), - ResourceVersion: w.resourceVersion, - }) - if err != nil { - return nil, err - } - for idx := range lo.Items { - ret = append(ret, &lo.Items[idx]) - } - return ret, nil -} - -func (w *wrapper) Get(name string) (*apisresourcev1alpha1.PipelineResource, error) { - return w.client.TektonV1alpha1().PipelineResources(w.namespace).Get(context.TODO(), name, v1.GetOptions{ - ResourceVersion: w.resourceVersion, - }) -} diff --git a/pkg/client/resource/listers/resource/v1alpha1/expansion_generated.go b/pkg/client/resource/listers/resource/v1alpha1/expansion_generated.go deleted file mode 100644 index ef6617f7bb5..00000000000 --- a/pkg/client/resource/listers/resource/v1alpha1/expansion_generated.go +++ /dev/null @@ -1,27 +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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -// PipelineResourceListerExpansion allows custom methods to be added to -// PipelineResourceLister. -type PipelineResourceListerExpansion interface{} - -// PipelineResourceNamespaceListerExpansion allows custom methods to be added to -// PipelineResourceNamespaceLister. -type PipelineResourceNamespaceListerExpansion interface{} diff --git a/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go b/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go deleted file mode 100644 index 9d698cb9431..00000000000 --- a/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go +++ /dev/null @@ -1,99 +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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// PipelineResourceLister helps list PipelineResources. -// All objects returned here must be treated as read-only. -type PipelineResourceLister interface { - // List lists all PipelineResources in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.PipelineResource, err error) - // PipelineResources returns an object that can list and get PipelineResources. - PipelineResources(namespace string) PipelineResourceNamespaceLister - PipelineResourceListerExpansion -} - -// pipelineResourceLister implements the PipelineResourceLister interface. -type pipelineResourceLister struct { - indexer cache.Indexer -} - -// NewPipelineResourceLister returns a new PipelineResourceLister. -func NewPipelineResourceLister(indexer cache.Indexer) PipelineResourceLister { - return &pipelineResourceLister{indexer: indexer} -} - -// List lists all PipelineResources in the indexer. -func (s *pipelineResourceLister) List(selector labels.Selector) (ret []*v1alpha1.PipelineResource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.PipelineResource)) - }) - return ret, err -} - -// PipelineResources returns an object that can list and get PipelineResources. -func (s *pipelineResourceLister) PipelineResources(namespace string) PipelineResourceNamespaceLister { - return pipelineResourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// PipelineResourceNamespaceLister helps list and get PipelineResources. -// All objects returned here must be treated as read-only. -type PipelineResourceNamespaceLister interface { - // List lists all PipelineResources in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.PipelineResource, err error) - // Get retrieves the PipelineResource from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha1.PipelineResource, error) - PipelineResourceNamespaceListerExpansion -} - -// pipelineResourceNamespaceLister implements the PipelineResourceNamespaceLister -// interface. -type pipelineResourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all PipelineResources in the indexer for a given namespace. -func (s pipelineResourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.PipelineResource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.PipelineResource)) - }) - return ret, err -} - -// Get retrieves the PipelineResource from the indexer for a given namespace and name. -func (s pipelineResourceNamespaceLister) Get(name string) (*v1alpha1.PipelineResource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("pipelineresource"), name) - } - return obj.(*v1alpha1.PipelineResource), nil -} 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/pipeline/dag/dag_test.go b/pkg/reconciler/pipeline/dag/dag_test.go index 0a41e9e09e6..c1d75f25464 100644 --- a/pkg/reconciler/pipeline/dag/dag_test.go +++ b/pkg/reconciler/pipeline/dag/dag_test.go @@ -153,27 +153,43 @@ func TestBuild_Parallel(t *testing.T) { } func TestBuild_JoinMultipleRoots(t *testing.T) { - a := v1beta1.PipelineTask{Name: "a"} + a := v1beta1.PipelineTask{ + Name: "a", + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "result", + }}, + }}, + } b := v1beta1.PipelineTask{Name: "b"} - c := v1beta1.PipelineTask{Name: "c"} + c := v1beta1.PipelineTask{ + Name: "c", + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "result", + }}, + }}, + } xDependsOnA := v1beta1.PipelineTask{ Name: "x", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"a"}}}, + Params: []v1beta1.Param{ + { + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }, }, } yDependsOnARunsAfterB := v1beta1.PipelineTask{ Name: "y", RunAfter: []string{"b"}, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"a"}}}, + Params: []v1beta1.Param{ + { + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }, }, } zDependsOnX := v1beta1.PipelineTask{ - Name: "z", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"x"}}}, - }, + Name: "z", + RunAfter: []string{"x"}, } // a b c @@ -219,22 +235,43 @@ func TestBuild_JoinMultipleRoots(t *testing.T) { } func TestBuild_FanInFanOut(t *testing.T) { - a := v1beta1.PipelineTask{Name: "a"} + a := v1beta1.PipelineTask{ + Name: "a", + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "result", + }}, + }}, + } dDependsOnA := v1beta1.PipelineTask{ Name: "d", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"a"}}}, - }, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "resultFromD", + }}, + }}, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }}, } eRunsAfterA := v1beta1.PipelineTask{ - Name: "e", - RunAfter: []string{"a"}, + Name: "e", + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "resultFromE", + }}, + }}, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }}, } fDependsOnDAndE := v1beta1.PipelineTask{ Name: "f", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"d", "e"}}}, - }, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.d.results.resultFromD)"), + }, { + Value: *v1beta1.NewStructuredValues("$(tasks.e.results.resultFromE)"), + }}, } gRunsAfterF := v1beta1.PipelineTask{ Name: "g", @@ -378,24 +415,41 @@ func TestBuild_TaskParamsFromTaskResults(t *testing.T) { } func TestBuild_InvalidDAG(t *testing.T) { - a := v1beta1.PipelineTask{Name: "a"} + a := v1beta1.PipelineTask{ + Name: "a", + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "result", + }}, + }}, + } xDependsOnA := v1beta1.PipelineTask{ Name: "x", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"a"}}}, - }, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "resultX", + }}, + }}, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }}, } zDependsOnX := v1beta1.PipelineTask{ Name: "z", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"x"}}}, - }, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "resultZ", + }}, + }}, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.x.results.resultX)"), + }}, } aDependsOnZ := v1beta1.PipelineTask{ Name: "a", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"z"}}}, - }, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.z.results.resultZ)"), + }}, } xAfterA := v1beta1.PipelineTask{ Name: "x", @@ -409,43 +463,69 @@ func TestBuild_InvalidDAG(t *testing.T) { Name: "a", RunAfter: []string{"z"}, } - selfLinkFrom := v1beta1.PipelineTask{ + selfLinkResult := v1beta1.PipelineTask{ Name: "a", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"a"}}}, - }, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "result", + }}, + }}, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }}, + } + invalidTaskResult := v1beta1.PipelineTask{ + Name: "a", + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.invalid.results.none)"), + }}, } selfLinkAfter := v1beta1.PipelineTask{ Name: "a", RunAfter: []string{"a"}, } - invalidTaskFrom := v1beta1.PipelineTask{ - Name: "a", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"none"}}}, - }, - } invalidTaskAfter := v1beta1.PipelineTask{ Name: "a", RunAfter: []string{"none"}, } - aRunsAfterE := v1beta1.PipelineTask{Name: "a", RunAfter: []string{"e"}} + aRunsAfterE := v1beta1.PipelineTask{ + Name: "a", RunAfter: []string{"e"}, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "result", + }}, + }}, + } bDependsOnA := v1beta1.PipelineTask{ Name: "b", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"a"}}}, - }, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }}, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "resultb", + }}, + }}, } cRunsAfterA := v1beta1.PipelineTask{ - Name: "c", - RunAfter: []string{"a"}, + Name: "c", + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.a.results.result)"), + }}, + TaskSpec: &v1beta1.EmbeddedTask{TaskSpec: v1beta1.TaskSpec{ + Results: []v1beta1.TaskResult{{ + Name: "resultc", + }}, + }}, } dDependsOnBAndC := v1beta1.PipelineTask{ Name: "d", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"b", "c"}}}, - }, + Params: []v1beta1.Param{{ + Value: *v1beta1.NewStructuredValues("$(tasks.b.results.resultb)"), + }, { + Value: *v1beta1.NewStructuredValues("$(tasks.c.results.resultc)"), + }}, } eRunsAfterD := v1beta1.PipelineTask{ Name: "e", @@ -456,10 +536,8 @@ func TestBuild_InvalidDAG(t *testing.T) { RunAfter: []string{"d"}, } gDependsOnF := v1beta1.PipelineTask{ - Name: "g", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{From: []string{"f"}}}, - }, + Name: "g", + RunAfter: []string{"f"}, } tcs := []struct { @@ -469,9 +547,9 @@ func TestBuild_InvalidDAG(t *testing.T) { }{{ // a // | - // a ("a" depends on resource from "a") - name: "self-link-from", - spec: v1beta1.PipelineSpec{Tasks: []v1beta1.PipelineTask{selfLinkFrom}}, + // a ("a" uses result of "a" as params) + name: "self-link-result", + spec: v1beta1.PipelineSpec{Tasks: []v1beta1.PipelineTask{selfLinkResult}}, err: "cycle detected", }, { // a @@ -527,8 +605,8 @@ func TestBuild_InvalidDAG(t *testing.T) { spec: v1beta1.PipelineSpec{Tasks: []v1beta1.PipelineTask{a, a}}, err: "duplicate pipeline task", }, { - name: "invalid-task-name-from", - spec: v1beta1.PipelineSpec{Tasks: []v1beta1.PipelineTask{invalidTaskFrom}}, + name: "invalid-task-result", + spec: v1beta1.PipelineSpec{Tasks: []v1beta1.PipelineTask{invalidTaskResult}}, err: "wasn't present in Pipeline", }, { name: "invalid-task-name-after", diff --git a/pkg/reconciler/pipelinerun/controller.go b/pkg/reconciler/pipelinerun/controller.go index 2607ec173fe..17d6866c74c 100644 --- a/pkg/reconciler/pipelinerun/controller.go +++ b/pkg/reconciler/pipelinerun/controller.go @@ -31,7 +31,6 @@ import ( pipelinerunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/pipelinerun" resolutionclient "github.com/tektoncd/pipeline/pkg/client/resolution/injection/client" resolutioninformer "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest" - resourceinformer "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource" "github.com/tektoncd/pipeline/pkg/pipelinerunmetrics" cloudeventclient "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim" @@ -54,7 +53,6 @@ func NewController(opts *pipeline.Options, clock clock.PassiveClock, tracerProvi taskRunInformer := taskruninformer.Get(ctx) customRunInformer := customruninformer.Get(ctx) pipelineRunInformer := pipelineruninformer.Get(ctx) - resourceInformer := resourceinformer.Get(ctx) resolutionInformer := resolutioninformer.Get(ctx) runInformer := runinformer.Get(ctx) verificationpolicyInformer := verificationpolicyinformer.Get(ctx) @@ -70,7 +68,6 @@ func NewController(opts *pipeline.Options, clock clock.PassiveClock, tracerProvi taskRunLister: taskRunInformer.Lister(), customRunLister: customRunInformer.Lister(), runLister: runInformer.Lister(), - resourceLister: resourceInformer.Lister(), verificationPolicyLister: verificationpolicyInformer.Lister(), cloudEventClient: cloudeventclient.Get(ctx), metrics: pipelinerunmetrics.Get(ctx), diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index a84ca645fc1..9f72cc10181 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -31,14 +31,11 @@ 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" 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" listers "github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1beta1" - resourcelisters "github.com/tektoncd/pipeline/pkg/client/resource/listers/resource/v1alpha1" resolutionutil "github.com/tektoncd/pipeline/pkg/internal/resolution" "github.com/tektoncd/pipeline/pkg/matrix" "github.com/tektoncd/pipeline/pkg/pipelinerunmetrics" @@ -59,7 +56,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" - kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8slabels "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -100,9 +96,6 @@ const ( // ReasonCouldntGetTask indicates that the reason for the failure status is that the // associated Pipeline's Tasks couldn't all be retrieved ReasonCouldntGetTask = "CouldntGetTask" - // ReasonCouldntGetResource indicates that the reason for the failure status is that the - // associated PipelineRun's bound PipelineResources couldn't all be retrieved - ReasonCouldntGetResource = "CouldntGetResource" // ReasonParameterMissing indicates that the reason for the failure status is that the // associated PipelineRun didn't provide all the required parameters ReasonParameterMissing = "ParameterMissing" @@ -148,7 +141,6 @@ type Reconciler struct { taskRunLister listers.TaskRunLister customRunLister listers.CustomRunLister runLister alpha1listers.RunLister - resourceLister resourcelisters.PipelineResourceLister verificationPolicyLister alpha1listers.VerificationPolicyLister cloudEventClient cloudevent.CEClient metrics *pipelinerunmetrics.Recorder @@ -208,10 +200,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) @@ -304,8 +292,7 @@ func (c *Reconciler) resolvePipelineState( ctx context.Context, tasks []v1beta1.PipelineTask, pipelineMeta *metav1.ObjectMeta, - pr *v1beta1.PipelineRun, - providedResources map[string]*resourcev1alpha1.PipelineResource) (resources.PipelineRunState, error) { + pr *v1beta1.PipelineRun) (resources.PipelineRunState, error) { ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "resolvePipelineState") defer span.End() pst := resources.PipelineRunState{} @@ -357,7 +344,7 @@ func (c *Reconciler) resolvePipelineState( return c.taskRunLister.TaskRuns(pr.Namespace).Get(name) }, getRunObjectFunc, - task, providedResources, + task, ) if err != nil { if tresources.IsGetTaskErrTransient(err) { @@ -457,30 +444,6 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get return controller.NewPermanentError(err) } - if err := resources.ValidateResourceBindings(pipelineSpec, pr); err != nil { - // This Run has failed, so we need to mark it as failed and stop reconciling it - pr.Status.MarkFailed(ReasonInvalidBindings, - "PipelineRun %s/%s doesn't bind Pipeline %s/%s's PipelineResources correctly: %s", - pr.Namespace, pr.Name, pr.Namespace, pipelineMeta.Name, err) - return controller.NewPermanentError(err) - } - providedResources, err := resources.GetResourcesFromBindings(pr, c.resourceLister.PipelineResources(pr.Namespace).Get) - if err != nil { - if kerrors.IsNotFound(err) && tknreconciler.IsYoungResource(pr) { - // For newly created resources, don't fail immediately. - // Instead return an (non-permanent) error, which will prompt the - // controller to requeue the key with backoff. - logger.Warnf("References for pipelinerun %s not found: %v", pr.Name, err) - pr.Status.MarkRunning(ReasonCouldntGetResource, - "Unable to resolve dependencies for %q: %v", pr.Name, err) - return err - } - // This Run has failed, so we need to mark it as failed and stop reconciling it - pr.Status.MarkFailed(ReasonCouldntGetResource, - "PipelineRun %s/%s can't be Run; it tries to bind Resources that don't exist: %s", - pipelineMeta.Namespace, pr.Name, err) - return controller.NewPermanentError(err) - } // Ensure that the PipelineRun provides all the parameters required by the Pipeline if err := resources.ValidateRequiredParametersProvided(&pipelineSpec.Params, &pr.Spec.Params); err != nil { // This Run has failed, so we need to mark it as failed and stop reconciling it @@ -549,7 +512,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get if len(pipelineSpec.Finally) > 0 { tasks = append(tasks, pipelineSpec.Finally...) } - pipelineRunState, err := c.resolvePipelineState(ctx, tasks, pipelineMeta.ObjectMeta, pr, providedResources) + pipelineRunState, err := c.resolvePipelineState(ctx, tasks, pipelineMeta.ObjectMeta, pr) switch { case errors.Is(err, remote.ErrorRequestInProgress): message := fmt.Sprintf("PipelineRun %s/%s awaiting remote resource", pr.Namespace, pr.Name) @@ -650,12 +613,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() @@ -691,7 +648,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 } @@ -737,7 +694,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() @@ -804,13 +761,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) @@ -830,14 +787,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).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 } @@ -846,7 +803,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) @@ -900,7 +857,6 @@ 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) 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 14100704572..a7251c95e20 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" @@ -74,9 +73,7 @@ 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", } ignoreResourceVersion = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion") @@ -214,16 +211,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, ` @@ -240,37 +227,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 @@ -279,56 +250,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 @@ -344,35 +284,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: @@ -383,55 +301,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() @@ -454,8 +335,6 @@ spec: value: somethingfun - name: bar value: somethingmorefun - - name: templatedparam - value: $(inputs.workspace.revision) - name: contextRunParam value: test-pipeline-run-success - name: contextPipelineParam @@ -463,34 +342,13 @@ 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 serviceAccountName: test-sa taskRef: name: unit-test-task kind: Task `) // ignore IgnoreUnexported ignore both after and before steps fields - if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { + if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta); d != "" { t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } // test taskrun is able to recreate correct pipeline-pvc-name @@ -506,9 +364,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 @@ -927,7 +782,6 @@ spec: `, config.DefaultServiceAccountValue)) expectedTaskRun.ObjectMeta = taskRunObjectMeta("test-pipeline-run-success-unit-test-task-spec", "foo", "test-pipeline-run-success", "test-pipeline", "unit-test-task-spec", false) - expectedTaskRun.Spec.Resources = &v1beta1.TaskRunResources{} // ignore IgnoreUnexported ignore both after and before steps fields if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta, cmpopts.SortSlices(func(x, y v1beta1.TaskSpec) bool { return len(x.Steps) == len(y.Steps) })); d != "" { @@ -981,16 +835,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, ` @@ -1013,23 +857,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 @@ -1039,10 +866,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: @@ -1147,58 +970,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, ` @@ -1252,35 +1023,13 @@ spec: value: - "a" - "b" -`), + `), reason: ReasonParamArrayIndexingInvalid, permanentError: true, wantEvents: []string{ "Normal Started", "Warning Failed PipelineRun foo/pipeline-param-array-out-of-bound failed validation: failed to validate Pipeline foo/a-pipeline-with-array-indexing-params's parameter which has an invalid index while referring to an array: non-existent param references:[$(params.some-param[2]", }, - }, { - 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, ` @@ -2553,7 +2302,6 @@ status: trs := []*v1beta1.TaskRun{mustParseTaskRunWithObjectMeta(t, taskRunObjectMeta("test-pipeline-run-with-timeout-hello-world-1", "foo", "test-pipeline-run-with-timeout", "test-pipeline", "hello-world-1", false), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -2642,7 +2390,6 @@ status: trs := []*v1beta1.TaskRun{mustParseTaskRunWithObjectMeta(t, taskRunObjectMeta("test-pipeline-run-with-timeout-hello-world-1", "foo", "test-pipeline-run-with-timeout", "test-pipeline", "hello-world-1", false), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -2764,7 +2511,7 @@ status: mustParseTaskRunWithObjectMeta(t, taskRunObjectMeta("test-pipeline-run-with-timeout-finaltask-1", "foo", "test-pipeline-run-with-timeout", "test-pipeline", "finaltask-1", false), ` spec: - resources: {} + serviceAccountName: test-sa taskRef: name: hello-world @@ -3143,7 +2890,6 @@ spec: expectedObjectMeta.Annotations["PipelineRunAnnotation"] = "PipelineRunValue" expected := mustParseTaskRunWithObjectMeta(t, expectedObjectMeta, ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -3280,7 +3026,6 @@ metadata: taskRunObjectMeta(taskRunNames[0], "foo", "test-pipeline-run-different-service-accs", "test-pipeline", "hello-world-0", false), ` spec: - resources: {} serviceAccountName: test-sa-0 taskRef: name: hello-world-task @@ -3290,7 +3035,6 @@ spec: taskRunObjectMeta(taskRunNames[1], "foo", "test-pipeline-run-different-service-accs", "test-pipeline", "hello-world-1", false), ` spec: - resources: {} serviceAccountName: test-sa-1 taskRef: name: hello-world-task @@ -3416,7 +3160,6 @@ spec: podTemplate: nodeSelector: workloadtype: tekton - resources: {} serviceAccountName: custom-sa sidecarOverrides: - name: bar @@ -3574,7 +3317,6 @@ spec: "test-pipeline", "a-task", true), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -3609,7 +3351,6 @@ status: taskRunObjectMeta(expectedTaskRunName, "foo", "test-pipeline-run-different-service-accs", "test-pipeline", "b-task", false), ` spec: - resources: {} serviceAccountName: test-sa-0 taskRef: name: b-task @@ -3800,7 +3541,6 @@ spec: "test-pipeline", taskName, false), fmt.Sprintf(` spec: - resources: {} serviceAccountName: test-sa-0 taskRef: name: %s @@ -3936,7 +3676,6 @@ spec: true), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -4441,7 +4180,6 @@ spec: "test-pipeline-run-different-service-accs", "test-pipeline", "a-task", true), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -4476,7 +4214,6 @@ spec: params: - name: bParam value: aResultValue - resources: {} serviceAccountName: test-sa-0 taskRef: name: b-task @@ -4565,7 +4302,6 @@ spec: "test-pipeline-run-different-service-accs", "test-pipeline-run-different-service-accs", "a-task", false), ` spec: - resources: {} serviceAccountName: test-sa-0 taskRef: kind: Task @@ -4944,7 +4680,6 @@ spec: "test-failed-pr-with-task-results", "test-pipeline", "a-task", true), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -4961,7 +4696,6 @@ status: "test-failed-pr-with-task-results", "test-pipeline", "b-task", true), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: hello-world @@ -6307,7 +6041,6 @@ spec: taskRunObjectMeta(pipelineRunName+"-task1-xxyy", "foo", pipelineRunName, pipelineName, "task1", false), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -6338,7 +6071,6 @@ spec: params: - name: pipelineRun-tasks-task1 value: Failed - resources: {} serviceAccountName: test-sa taskRef: name: finaltask @@ -6517,7 +6249,6 @@ spec: params: - name: finalParam value: aResultValue - resources: {} serviceAccountName: test-sa-0 taskRef: name: final-task @@ -6691,7 +6422,6 @@ metadata: "test-pipeline", "unit-test-1", false), fmt.Sprintf(` spec: - resources: {} serviceAccountName: test-sa taskRef: bundle: %s @@ -6699,7 +6429,7 @@ spec: name: unit-test-task `, ref)) - if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { + if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta); d != "" { t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } @@ -6764,7 +6494,6 @@ spec: "test-pipeline-run-success", "unit-test-1", false), ` spec: - resources: {} serviceAccountName: test-sa taskSpec: steps: @@ -6774,7 +6503,7 @@ spec: optional: true `) - if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { + if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta); d != "" { t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } @@ -7189,7 +6918,6 @@ func getTaskRunWithTaskSpec(tr, pr, p, t string, labels, annotations map[string] }}, }, ServiceAccountName: config.DefaultServiceAccountValue, - Resources: &v1beta1.TaskRunResources{}, }, } } @@ -7660,7 +7388,6 @@ spec: expectedTaskRunObjectMeta.Annotations["PipelineTaskRunSpecAnnotation"] = "PipelineTaskRunSpecValue" expectedTaskRun := mustParseTaskRunWithObjectMeta(t, expectedTaskRunObjectMeta, ` spec: - resources: {} serviceAccountName: custom-sa taskRef: name: hello-world @@ -7731,7 +7458,6 @@ spec: expectedTaskRunObjectMeta.Annotations["TestPrecedenceAnnotation"] = "PipelineTaskRunSpecValue" expectedTaskRun := mustParseTaskRunWithObjectMeta(t, expectedTaskRunObjectMeta, ` spec: - resources: {} serviceAccountName: custom-sa taskSpec: steps: @@ -7776,7 +7502,6 @@ spec: value: chrome - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7794,7 +7519,6 @@ spec: value: chrome - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7812,7 +7536,6 @@ spec: value: chrome - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7830,7 +7553,6 @@ spec: value: safari - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7848,7 +7570,6 @@ spec: value: safari - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7866,7 +7587,6 @@ spec: value: safari - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7884,7 +7604,6 @@ spec: value: firefox - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7902,7 +7621,6 @@ spec: value: firefox - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -7920,7 +7638,6 @@ spec: value: firefox - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8091,7 +7808,6 @@ spec: value: chrome - name: version value: v0.22.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8310,7 +8026,6 @@ spec: value: chrome - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8328,7 +8043,6 @@ spec: value: chrome - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8346,7 +8060,6 @@ spec: value: chrome - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8364,7 +8077,6 @@ spec: value: safari - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8382,7 +8094,6 @@ spec: value: safari - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8400,7 +8111,6 @@ spec: value: safari - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8418,7 +8128,6 @@ spec: value: firefox - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8436,7 +8145,6 @@ spec: value: firefox - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8454,7 +8162,6 @@ spec: value: firefox - name: version value: v0.33.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8515,7 +8222,6 @@ spec: "pr", "p-dag", "pt-with-result", false), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: taskwithresults @@ -8679,7 +8385,6 @@ spec: "pr", "p-finally", "pt-with-result", false), ` spec: - resources: {} serviceAccountName: test-sa taskRef: name: taskwithresults @@ -8898,7 +8603,6 @@ spec: value: linux - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -8923,7 +8627,6 @@ spec: value: mac - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9034,7 +8737,6 @@ spec: value: linux - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9059,7 +8761,6 @@ spec: value: mac - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9084,7 +8785,6 @@ spec: value: linux - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9109,7 +8809,6 @@ spec: value: mac - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9224,7 +8923,6 @@ spec: value: linux - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9249,7 +8947,6 @@ spec: value: mac - name: browser value: chrome - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9346,7 +9043,6 @@ spec: value: chrome - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9366,7 +9062,6 @@ spec: value: chrome - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9386,7 +9081,6 @@ spec: value: chrome - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9406,7 +9100,6 @@ spec: value: safari - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9426,7 +9119,6 @@ spec: value: safari - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9446,7 +9138,6 @@ spec: value: safari - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9466,7 +9157,6 @@ spec: value: firefox - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9486,7 +9176,6 @@ spec: value: firefox - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9506,7 +9195,6 @@ spec: value: firefox - name: version value: v0.1 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9677,7 +9365,6 @@ spec: value: chrome - name: version value: v0.0 - resources: {} serviceAccountName: test-sa taskRef: name: mytask @@ -9838,10 +9525,6 @@ spec: } } -func lessTaskResourceBindings(i, j v1beta1.TaskResourceBinding) bool { - return i.Name < j.Name -} - func TestReconcile_SetDefaults(t *testing.T) { names.TestingSeed() prs := []*v1beta1.PipelineRun{parse.MustParseV1beta1PipelineRun(t, ` @@ -9940,10 +9623,9 @@ spec: taskRef: name: unit-test-task kind: Task - resources: {} `) // ignore IgnoreUnexported ignore both after and before steps fields - if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { + if d := cmp.Diff(expectedTaskRun, actual, ignoreTypeMeta); d != "" { t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } diff --git a/pkg/reconciler/pipelinerun/resources/input_output_steps.go b/pkg/reconciler/pipelinerun/resources/input_output_steps.go deleted file mode 100644 index 7405e1983ab..00000000000 --- a/pkg/reconciler/pipelinerun/resources/input_output_steps.go +++ /dev/null @@ -1,115 +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 ( - "path/filepath" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" -) - -// GetOutputSteps will add the correct `path` to the output resources for pt -func GetOutputSteps(outputs map[string]*resourcev1alpha1.PipelineResource, taskName, storageBasePath string) []v1beta1.TaskResourceBinding { - var taskOutputResources []v1beta1.TaskResourceBinding - - for name, outputResource := range outputs { - taskOutputResource := v1beta1.TaskResourceBinding{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: name, - }, - Paths: []string{filepath.Join(storageBasePath, 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 - if outputResource.SelfLink != "" { - taskOutputResource.ResourceRef = &v1beta1.PipelineResourceRef{ - Name: outputResource.Name, - APIVersion: outputResource.APIVersion, - } - } else if outputResource.Spec.Type != "" { - taskOutputResource.ResourceSpec = &resourcev1alpha1.PipelineResourceSpec{ - Type: outputResource.Spec.Type, - Params: outputResource.Spec.Params, - SecretParams: outputResource.Spec.SecretParams, - } - } - taskOutputResources = append(taskOutputResources, taskOutputResource) - } - return taskOutputResources -} - -// 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 { - var taskInputResources []v1beta1.TaskResourceBinding - - for name, inputResource := range inputs { - taskInputResource := v1beta1.TaskResourceBinding{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: 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 - if inputResource.SelfLink != "" { - taskInputResource.ResourceRef = &v1beta1.PipelineResourceRef{ - Name: inputResource.Name, - APIVersion: inputResource.APIVersion, - } - } else if inputResource.Spec.Type != "" { - taskInputResource.ResourceSpec = &resourcev1alpha1.PipelineResourceSpec{ - Type: inputResource.Spec.Type, - Params: inputResource.Spec.Params, - SecretParams: inputResource.Spec.SecretParams, - } - } - - // 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) { - if pt == nil { - return - } - if tr.Resources == nil { - tr.Resources = &v1beta1.TaskRunResources{} - } - if pt.Resources != nil { - // Add presteps to setup updated input - tr.Resources.Inputs = append(tr.Resources.Inputs, GetInputSteps(inputs, pt.Resources.Inputs, storageBasePath)...) - } - - // Add poststeps to setup outputs - tr.Resources.Outputs = append(tr.Resources.Outputs, GetOutputSteps(outputs, pt.Name, storageBasePath)...) -} diff --git a/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go b/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go deleted file mode 100644 index 12c8787e0ea..00000000000 --- a/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go +++ /dev/null @@ -1,355 +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/google/go-cmp/cmp/cmpopts" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" - "github.com/tektoncd/pipeline/test/diff" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -var pvcDir = "/pvc" - -func TestGetOutputSteps(t *testing.T) { - r1 := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "resource1", - SelfLink: "/apis/tekton.dev/pipelineresources/resource1", - }, - } - r2 := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "resource2", - 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 - expectedtaskOuputResources []v1beta1.TaskResourceBinding - pipelineTaskName string - }{{ - name: "single output", - outputs: map[string]*resourcev1alpha1.PipelineResource{"test-output": r1}, - expectedtaskOuputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "test-output", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, - }, - Paths: []string{"/pvc/test-taskname/test-output"}, - }}, - pipelineTaskName: "test-taskname", - }, { - name: "multiple-outputs", - outputs: map[string]*resourcev1alpha1.PipelineResource{ - "test-output": r1, - "test-output-2": r2, - }, - expectedtaskOuputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "test-output", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, - }, - Paths: []string{"/pvc/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"}, - }}, - 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) - if d := cmp.Diff(tc.expectedtaskOuputResources, postTasks, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { - t.Errorf("error comparing post steps %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestGetInputSteps(t *testing.T) { - r1 := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "resource1", - 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 - pipelineTask *v1beta1.PipelineTask - expectedtaskInputResources []v1beta1.TaskResourceBinding - }{ - { - name: "task-with-a-constraint", - inputs: map[string]*resourcev1alpha1.PipelineResource{"test-input": r1}, - pipelineTask: &v1beta1.PipelineTask{ - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "test-input", - From: []string{"prev-task-1"}, - }}, - }, - }, - expectedtaskInputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, - Name: "test-input", - }, - Paths: []string{"/pvc/prev-task-1/test-input"}, - }}, - }, { - name: "task-with-no-input-constraint", - inputs: map[string]*resourcev1alpha1.PipelineResource{"test-input": r1}, - expectedtaskInputResources: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{Name: "resource1"}, - Name: "test-input", - }, - }}, - pipelineTask: &v1beta1.PipelineTask{ - Name: "sample-test-task", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "test-input", - }}, - }, - }, - }, { - name: "task-with-multiple-constraints", - inputs: map[string]*resourcev1alpha1.PipelineResource{"test-input": r1}, - 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{ - 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) - if d := cmp.Diff(tc.expectedtaskInputResources, taskInputResources, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { - t.Errorf("error comparing task resource inputs %s", diff.PrintWantGot(d)) - } - }) - } -} - -func TestWrapSteps(t *testing.T) { - r1 := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "resource1", - 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, - } - - pt := &v1beta1.PipelineTask{ - Name: "test-task", - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "test-input", - From: []string{"prev-task"}, - }}, - }, - } - - taskRunSpec := &v1beta1.TaskRunSpec{} - resources.WrapSteps(taskRunSpec, pt, inputs, outputs, pvcDir) - - 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"}, - }} - - if d := cmp.Diff(taskRunSpec.Resources.Inputs, expectedtaskInputResources, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { - t.Errorf("error comparing input resources %s", diff.PrintWantGot(d)) - } - if d := cmp.Diff(taskRunSpec.Resources.Outputs, expectedtaskOuputResources, cmpopts.SortSlices(lessTaskResourceBindings)); d != "" { - t.Errorf("error comparing output resources %s", diff.PrintWantGot(d)) - } -} - -func lessTaskResourceBindings(i, j v1beta1.TaskResourceBinding) bool { - return i.Name < j.Name -} diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go index c0b28df0ecd..25fe155b477 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go @@ -25,8 +25,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" - "github.com/tektoncd/pipeline/pkg/list" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" "github.com/tektoncd/pipeline/pkg/remote" "github.com/tektoncd/pipeline/pkg/trustedresources" @@ -544,51 +542,6 @@ func (t *ResolvedPipelineTask) IsFinallySkipped(facts *PipelineRunFacts) TaskSki // GetRun is a function that will retrieve a Run by name. type GetRun func(name string) (v1beta1.RunObject, error) -// GetResourcesFromBindings will retrieve all Resources bound in PipelineRun pr and return a map -// from the declared name of the PipelineResource (which is how the PipelineResource will -// be referred to in the PipelineRun) to the PipelineResource, obtained via getResource. -func GetResourcesFromBindings(pr *v1beta1.PipelineRun, getResource resources.GetResource) (map[string]*resourcev1alpha1.PipelineResource, error) { - rs := map[string]*resourcev1alpha1.PipelineResource{} - for _, resource := range pr.Spec.Resources { - r, err := resources.GetResourceFromBinding(resource, getResource) - if err != nil { - return rs, err - } - rs[resource.Name] = r - } - return rs, nil -} - -// ValidateResourceBindings validate that the PipelineResources declared in Pipeline p are bound in PipelineRun. -func ValidateResourceBindings(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) error { - required := make([]string, 0, len(p.Resources)) - optional := make([]string, 0, len(p.Resources)) - for _, resource := range p.Resources { - if resource.Optional { - // create a list of optional resources - optional = append(optional, resource.Name) - } else { - // create a list of required resources - required = append(required, resource.Name) - } - } - provided := make([]string, 0, len(pr.Spec.Resources)) - for _, resource := range pr.Spec.Resources { - provided = append(provided, resource.Name) - } - // verify that the list of required resources exists in the provided resources - missing := list.DiffLeft(required, provided) - if len(missing) > 0 { - return fmt.Errorf("Pipeline's declared required resources are missing from the PipelineRun: %s", missing) - } - // verify that the list of provided resources does not have any extra resources (outside of required and optional resources combined) - extra := list.DiffLeft(provided, append(required, optional...)) - if len(extra) > 0 { - return fmt.Errorf("PipelineRun's declared resources didn't match usage in Pipeline: %s", extra) - } - return nil -} - // ValidateWorkspaceBindings validates that the Workspaces expected by a Pipeline are provided by a PipelineRun. func ValidateWorkspaceBindings(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) error { pipelineRunWorkspaces := make(map[string]v1beta1.WorkspaceBinding) @@ -646,7 +599,6 @@ func ResolvePipelineTask( getTaskRun resources.GetTaskRun, getRun GetRun, pipelineTask v1beta1.PipelineTask, - providedResources map[string]*resourcev1alpha1.PipelineResource, ) (*ResolvedPipelineTask, error) { rpt := ResolvedPipelineTask{ PipelineTask: &pipelineTask, @@ -676,13 +628,13 @@ func ResolvePipelineTask( case rpt.IsMatrixed(): rpt.TaskRunNames = GetNamesOfTaskRuns(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name, pipelineTask.GetMatrixCombinationsCount()) for _, taskRunName := range rpt.TaskRunNames { - if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, taskRunName, getTask, getTaskRun, pipelineTask, providedResources); err != nil { + if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, taskRunName, getTask, getTaskRun, pipelineTask); err != nil { return nil, err } } default: rpt.TaskRunName = GetTaskRunName(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name) - if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, rpt.TaskRunName, getTask, getTaskRun, pipelineTask, providedResources); err != nil { + if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, rpt.TaskRunName, getTask, getTaskRun, pipelineTask); err != nil { return nil, err } } @@ -695,7 +647,6 @@ func (t *ResolvedPipelineTask) resolvePipelineRunTaskWithTaskRun( getTask resources.GetTask, getTaskRun resources.GetTaskRun, pipelineTask v1beta1.PipelineTask, - providedResources map[string]*resourcev1alpha1.PipelineResource, ) error { taskRun, err := getTaskRun(taskRunName) if err != nil { @@ -711,7 +662,7 @@ func (t *ResolvedPipelineTask) resolvePipelineRunTaskWithTaskRun( } } - if err := t.resolveTaskResources(ctx, getTask, pipelineTask, providedResources, taskRun); err != nil { + if err := t.resolveTaskResources(ctx, getTask, pipelineTask, taskRun); err != nil { return err } @@ -722,7 +673,6 @@ func (t *ResolvedPipelineTask) resolveTaskResources( ctx context.Context, getTask resources.GetTask, pipelineTask v1beta1.PipelineTask, - providedResources map[string]*resourcev1alpha1.PipelineResource, taskRun *v1beta1.TaskRun, ) error { spec, taskName, kind, err := resolveTask(ctx, taskRun, getTask, pipelineTask) @@ -731,7 +681,7 @@ func (t *ResolvedPipelineTask) resolveTaskResources( } spec.SetDefaults(ctx) - rtr, err := resolvePipelineTaskResources(pipelineTask, &spec, taskName, kind, providedResources) + rtr, err := resolvePipelineTaskResources(pipelineTask, &spec, taskName, kind) if err != nil { return fmt.Errorf("couldn't match referenced resources with declared resources: %w", err) } @@ -859,43 +809,11 @@ func getRunNamesFromChildRefs(childRefs []v1beta1.ChildStatusReference, ptName s // resolvePipelineTaskResources matches PipelineResources referenced by pt inputs and outputs with the // providedResources and returns an instance of ResolvedTaskResources. -func resolvePipelineTaskResources(pt v1beta1.PipelineTask, ts *v1beta1.TaskSpec, taskName string, kind v1beta1.TaskKind, providedResources map[string]*resourcev1alpha1.PipelineResource) (*resources.ResolvedTaskResources, error) { +func resolvePipelineTaskResources(pt v1beta1.PipelineTask, ts *v1beta1.TaskSpec, taskName string, kind v1beta1.TaskKind) (*resources.ResolvedTaskResources, error) { rtr := resources.ResolvedTaskResources{ TaskName: taskName, TaskSpec: ts, Kind: kind, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, - } - if pt.Resources != nil { - for _, taskInput := range pt.Resources.Inputs { - if resource, ok := providedResources[taskInput.Resource]; ok { - rtr.Inputs[taskInput.Name] = resource - } else { - if ts.Resources == nil || ts.Resources.Inputs == nil { - return nil, fmt.Errorf("pipelineTask tried to use input resource %s not present in declared resources", taskInput.Resource) - } - for _, r := range ts.Resources.Inputs { - if r.Name == taskInput.Name && !r.Optional { - return nil, fmt.Errorf("pipelineTask tried to use input resource %s not present in declared resources", taskInput.Resource) - } - } - } - } - for _, taskOutput := range pt.Resources.Outputs { - if resource, ok := providedResources[taskOutput.Resource]; ok { - rtr.Outputs[taskOutput.Name] = resource - } else { - if ts.Resources == nil || ts.Resources.Outputs == nil { - return nil, fmt.Errorf("pipelineTask tried to use output resource %s not present in declared resources", taskOutput.Resource) - } - for _, r := range ts.Resources.Outputs { - if r.Name == taskOutput.Name && !r.Optional { - return nil, fmt.Errorf("pipelineTask tried to use output resource %s not present in declared resources", taskOutput.Resource) - } - } - } - } } return &rtr, nil } diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index 8c458840241..71e638344d3 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -29,7 +29,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "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" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" "github.com/tektoncd/pipeline/pkg/trustedresources" @@ -241,16 +240,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"}, -} - var matrixedPipelineTask = &v1beta1.PipelineTask{ Name: "task", Matrix: &v1beta1.Matrix{ @@ -744,67 +733,6 @@ var taskCancelledMatrix = PipelineRunState{{ }, }} -var taskWithOptionalResourcesDeprecated = &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task", - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "step1", - }}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-input", - Type: "git", - Optional: true, - }}, {ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "required-input", - Type: "git", - Optional: false, - }}}, - Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-output", - Type: "git", - Optional: true, - }}, {ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "required-output", - Type: "git", - Optional: false, - }}}, - }, - }, -} -var taskWithOptionalResources = &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task", - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "step1", - }}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-input", - Type: "git", - Optional: true, - }}, {ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "required-input", - Type: "git", - Optional: false, - }}}, - Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-output", - Type: "git", - Optional: true, - }}, {ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "required-output", - Type: "git", - Optional: false, - }}}, - }, - }, -} - func dagFromState(state PipelineRunState) (*dag.Graph, error) { pts := []v1beta1.PipelineTask{} for _, rpt := range state { @@ -1871,210 +1799,6 @@ func getExpectedMessage(runName string, specStatus v1beta1.PipelineRunSpecStatus successful+failed+cancelled, failed, cancelled, incomplete, skipped) } -func TestGetResourcesFromBindings(t *testing.T) { - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - Resources: []v1beta1.PipelineResourceBinding{ - gitSweetResourceBinding, - }, - }, - } - r := &resourcev1alpha1.PipelineResource{ObjectMeta: metav1.ObjectMeta{Name: "sweet-resource"}} - getResource := func(name string) (*resourcev1alpha1.PipelineResource, error) { - if name != "sweet-resource" { - return nil, fmt.Errorf("request for unexpected resource %s", name) - } - return r, nil - } - m, err := GetResourcesFromBindings(pr, getResource) - if err != nil { - t.Fatalf("didn't expect error getting resources from bindings but got: %v", err) - } - - r1, ok := m["git-resource"] - if !ok { - t.Errorf("Missing expected resource git-resource: %v", m) - } else if d := cmp.Diff(r, r1); d != "" { - t.Errorf("Expected resources didn't match actual %s", diff.PrintWantGot(d)) - } -} - -func TestGetResourcesFromBindings_Missing(t *testing.T) { - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - Resources: []v1beta1.PipelineResourceBinding{gitSweetResourceBinding}, - }, - } - getResource := func(name string) (*resourcev1alpha1.PipelineResource, error) { - return nil, kerrors.NewNotFound(resourcev1alpha1.Resource("pipelineresources"), name) - } - _, err := GetResourcesFromBindings(pr, getResource) - if err == nil { - t.Fatalf("Expected error indicating `image-resource` was missing but got no error") - } else if !kerrors.IsNotFound(err) { - t.Fatalf("GetResourcesFromBindings() = %v, wanted IsNotFound", err) - } -} - -func TestGetResourcesFromBindings_ErrorGettingResource(t *testing.T) { - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - Resources: []v1beta1.PipelineResourceBinding{gitSweetResourceBinding}, - }, - } - getResource := func(name string) (*resourcev1alpha1.PipelineResource, error) { - return nil, fmt.Errorf("iT HAS ALL GONE WRONG") - } - _, err := GetResourcesFromBindings(pr, getResource) - if err == nil { - t.Fatalf("Expected error indicating resource couldnt be retrieved but got no error") - } -} - -func TestResolvePipelineRun(t *testing.T) { - names.TestingSeed() - - p := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{gitDeclaredResource}, - Tasks: []v1beta1.PipelineTask{ - { - Name: "mytask1", - TaskRef: &v1beta1.TaskRef{Name: "task"}, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, - }, - { - Name: "mytask2", - TaskRef: &v1beta1.TaskRef{Name: "task"}, - Resources: &v1beta1.PipelineTaskResources{ - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "output1", - Resource: "git-resource", - }}, - }, - }, - { - Name: "mytask3", - TaskRef: &v1beta1.TaskRef{Name: "task"}, - Resources: &v1beta1.PipelineTaskResources{ - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "output1", - Resource: "git-resource", - }}, - }, - }, - { - Name: "mytask4", - TaskSpec: &v1beta1.EmbeddedTask{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{Name: "step1"}}, - }, - }, - }, - }, - }, - } - - r := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "someresource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - } - providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} - pr := v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun", - }, - } - // The Task "task" doesn't actually take any inputs or outputs, but validating - // that is not done as part of Run resolution - getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { - return task, nil, nil - } - getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return nil, nil } - - pipelineState := PipelineRunState{} - for _, task := range p.Spec.Tasks { - ps, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, task, providedResources) - if err != nil { - t.Fatalf("Error getting tasks for fake pipeline %s: %s", p.ObjectMeta.Name, err) - } - pipelineState = append(pipelineState, ps) - } - expectedState := PipelineRunState{{ - PipelineTask: &p.Spec.Tasks[0], - TaskRunName: "pipelinerun-mytask1", - TaskRun: nil, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskName: task.Name, - TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{ - "input1": r, - }, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, - }, - }, { - PipelineTask: &p.Spec.Tasks[1], - TaskRunName: "pipelinerun-mytask2", - TaskRun: nil, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskName: task.Name, - TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{ - "output1": r, - }, - }, - }, { - PipelineTask: &p.Spec.Tasks[2], - TaskRunName: "pipelinerun-mytask3", - TaskRun: nil, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskName: task.Name, - TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{ - "output1": r, - }, - }, - }, { - PipelineTask: &p.Spec.Tasks[3], - TaskRunName: "pipelinerun-mytask4", - TaskRun: nil, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskName: "", - TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, - }, - }} - - if d := cmp.Diff(expectedState, pipelineState, cmpopts.IgnoreUnexported(v1beta1.TaskRunSpec{})); d != "" { - t.Errorf("Expected to get current pipeline state %v, but actual differed %s", expectedState, diff.PrintWantGot(d)) - } -} - func TestResolvePipelineRun_CustomTask(t *testing.T) { names.TestingSeed() pts := []v1beta1.PipelineTask{{ @@ -2107,7 +1831,7 @@ func TestResolvePipelineRun_CustomTask(t *testing.T) { cfg := config.NewStore(logtesting.TestLogger(t)) ctx = cfg.ToContext(ctx) for _, task := range pts { - ps, err := ResolvePipelineTask(ctx, pr, nopGetTask, nopGetTaskRun, getRun, task, nil) + ps, err := ResolvePipelineTask(ctx, pr, nopGetTask, nopGetTaskRun, getRun, task) if err != nil { t.Fatalf("ResolvePipelineTask: %v", err) } @@ -2146,7 +1870,6 @@ func TestResolvePipelineRun_PipelineTaskHasNoResources(t *testing.T) { Name: "mytask3", TaskRef: &v1beta1.TaskRef{Name: "task"}, }} - providedResources := map[string]*resourcev1alpha1.PipelineResource{} getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { return task, nil, nil @@ -2159,7 +1882,7 @@ func TestResolvePipelineRun_PipelineTaskHasNoResources(t *testing.T) { } pipelineState := PipelineRunState{} for _, task := range pts { - ps, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, task, providedResources) + ps, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, task) if err != nil { t.Errorf("Error getting tasks for fake pipeline %s: %s", p.ObjectMeta.Name, err) } @@ -2171,8 +1894,6 @@ func TestResolvePipelineRun_PipelineTaskHasNoResources(t *testing.T) { expectedTaskResources := &resources.ResolvedTaskResources{ TaskName: task.Name, TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, } if d := cmp.Diff(pipelineState[0].ResolvedTaskResources, expectedTaskResources, cmpopts.IgnoreUnexported(v1beta1.TaskRunSpec{})); d != "" { t.Fatalf("Expected resources where only Tasks were resolved but actual differed %s", diff.PrintWantGot(d)) @@ -2198,7 +1919,6 @@ func TestResolvePipelineRun_TaskDoesntExist(t *testing.T) { Value: *v1beta1.NewStructuredValues("b", "a", "r"), }}, }}} - providedResources := map[string]*resourcev1alpha1.PipelineResource{} // Return an error when the Task is retrieved, as if it didn't exist getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { @@ -2213,7 +1933,7 @@ func TestResolvePipelineRun_TaskDoesntExist(t *testing.T) { }, } for _, pt := range pts { - _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, pt, providedResources) + _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, pt) switch err := err.(type) { case nil: t.Fatalf("Expected error getting non-existent Tasks for Pipeline %s but got none", p.Name) @@ -2241,7 +1961,6 @@ func TestResolvePipelineRun_VerificationFailed(t *testing.T) { Value: *v1beta1.NewStructuredValues("b", "a", "r"), }}, }}} - providedResources := map[string]*resourcev1alpha1.PipelineResource{} getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { return nil, nil, trustedresources.ErrorResourceVerificationFailed @@ -2253,7 +1972,7 @@ func TestResolvePipelineRun_VerificationFailed(t *testing.T) { }, } for _, pt := range pts { - _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, pt, providedResources) + _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, pt) if err == nil { t.Errorf("expected to get err but got nil") } @@ -2263,285 +1982,6 @@ func TestResolvePipelineRun_VerificationFailed(t *testing.T) { } } -func TestResolvePipelineRun_ResourceBindingsDontExist(t *testing.T) { - tests := []struct { - name string - p *v1beta1.Pipeline - }{{ - name: "input doesnt exist", - p: &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{{ - Name: "mytask1", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, - }}, - }, - }, - }, { - name: "output doesnt exist", - p: &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{{ - Name: "mytask1", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, - }}, - }, - }, - }} - providedResources := map[string]*resourcev1alpha1.PipelineResource{} - - getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { - return task, nil, nil - } - getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return &trs[0], nil } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - pr := v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun", - }, - } - pipelineState := PipelineRunState{} - ps, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, tt.p.Spec.Tasks[0], providedResources) - if err == nil { - t.Fatalf("Expected error when bindings are in incorrect state for Pipeline %s but got none: %s", p.ObjectMeta.Name, err) - } - pipelineState = append(pipelineState, ps) - }) - } -} - -func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { - names.TestingSeed() - - p := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{gitDeclaredResource}, - Tasks: []v1beta1.PipelineTask{{ - Name: "mytask-with-a-really-long-name-to-trigger-truncation", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, - }}, - }, - } - - r := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "someresource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - } - providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} - - pr := v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun", - }, - Status: v1beta1.PipelineRunStatus{ - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - ChildReferences: []v1beta1.ChildStatusReference{{ - Name: "pipelinerun-mytask-with-a-really-long-name-to-trigger-tru", - PipelineTaskName: "mytask-with-a-really-long-name-to-trigger-truncation", - TypeMeta: runtime.TypeMeta{Kind: "TaskRun"}, - }}, - }, - }, - } - - // The Task "task" doesn't actually take any inputs or outputs, but validating - // that is not done as part of Run resolution - getTask := func(_ context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { - return task, nil, nil - } - getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return nil, nil } - resolvedTask, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, p.Spec.Tasks[0], providedResources) - if err != nil { - t.Fatalf("Error getting tasks for fake pipeline %s: %s", p.ObjectMeta.Name, err) - } - expectedTask := &ResolvedPipelineTask{ - PipelineTask: &p.Spec.Tasks[0], - TaskRunName: "pipelinerun-mytask-with-a-really-long-name-to-trigger-tru", - TaskRun: nil, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskName: task.Name, - TaskSpec: &task.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{ - "input1": r, - }, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, - }, - } - - if d := cmp.Diff(resolvedTask, expectedTask, cmpopts.IgnoreUnexported(v1beta1.TaskRunSpec{})); d != "" { - t.Fatalf("Expected to get current pipeline state %v, but actual differed %s", expectedTask, diff.PrintWantGot(d)) - } -} -func TestResolvedPipelineRun_PipelineTaskHasOptionalResources(t *testing.T) { - names.TestingSeed() - p := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{{ - Name: "mytask1", - TaskRef: &v1beta1.TaskRef{ - Name: "task", - }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "required-input", - Resource: "git-resource", - }}, - Outputs: []v1beta1.PipelineTaskOutputResource{{ - Name: "required-output", - Resource: "git-resource", - }}, - }, - }}, - }, - } - - r := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "someresource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - } - providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} - pr := v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun", - }, - } - - getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { - return taskWithOptionalResourcesDeprecated, nil, nil - } - getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return nil, nil } - - actualTask, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, p.Spec.Tasks[0], providedResources) - if err != nil { - t.Fatalf("Error getting tasks for fake pipeline %s: %s", p.ObjectMeta.Name, err) - } - expectedTask := &ResolvedPipelineTask{ - PipelineTask: &p.Spec.Tasks[0], - TaskRunName: "pipelinerun-mytask1", - TaskRun: nil, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskName: taskWithOptionalResources.Name, - TaskSpec: &taskWithOptionalResources.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{ - "required-input": r, - }, - Outputs: map[string]*resourcev1alpha1.PipelineResource{ - "required-output": r, - }, - }, - } - - if d := cmp.Diff(expectedTask, actualTask, cmpopts.IgnoreUnexported(v1beta1.TaskRunSpec{})); d != "" { - t.Errorf("Expected to get current pipeline state %v, but actual differed %s", expectedTask, diff.PrintWantGot(d)) - } -} - -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, - }, - }, - } - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{Name: "pipeline"}, - Resources: []v1beta1.PipelineResourceBinding{}, - }, - } - err := ValidateResourceBindings(&p.Spec, pr) - if err == nil { - t.Fatalf("Expected error indicating `git-resource` was missing but got no error") - } -} - -func TestGetResourcesFromBindings_Extra(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, - { - Name: "image-resource", - ResourceRef: &v1beta1.PipelineResourceRef{Name: "sweet-resource2"}, - }, - }, - }, - } - err := ValidateResourceBindings(&p.Spec, pr) - if err == nil { - t.Fatalf("Expected error indicating `image-resource` was extra but got no error") - } -} - func TestValidateWorkspaceBindingsWithValidWorkspaces(t *testing.T) { for _, tc := range []struct { name string @@ -2630,12 +2070,6 @@ func TestValidateTaskRunSpecs(t *testing.T) { TaskRef: &v1beta1.TaskRef{ Name: "task", }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, }}, }, }, @@ -2666,12 +2100,6 @@ func TestValidateTaskRunSpecs(t *testing.T) { TaskRef: &v1beta1.TaskRef{ Name: "task", }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, }}, Finally: []v1beta1.PipelineTask{{ Name: "myfinaltask1", @@ -2708,12 +2136,6 @@ func TestValidateTaskRunSpecs(t *testing.T) { TaskRef: &v1beta1.TaskRef{ Name: "task", }, - Resources: &v1beta1.PipelineTaskResources{ - Inputs: []v1beta1.PipelineTaskInputResource{{ - Name: "input1", - Resource: "git-resource", - }}, - }, }}, Finally: []v1beta1.PipelineTask{{ Name: "myfinaltask1", @@ -2777,8 +2199,6 @@ func TestResolvePipeline_WhenExpressions(t *testing.T) { WhenExpressions: []v1beta1.WhenExpression{ptwe1}, } - providedResources := map[string]*resourcev1alpha1.PipelineResource{} - getTask := func(_ context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { return task, nil, nil } @@ -2799,7 +2219,7 @@ func TestResolvePipeline_WhenExpressions(t *testing.T) { } t.Run("When Expressions exist", func(t *testing.T) { - _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, pt, providedResources) + _, err := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetRun, pt) if err != nil { t.Fatalf("Did not expect error when resolving PipelineRun: %v", err) } @@ -2916,7 +2336,7 @@ func TestIsCustomTask(t *testing.T) { ctx := context.Background() cfg := config.NewStore(logtesting.TestLogger(t)) ctx = cfg.ToContext(ctx) - rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt, nil) + rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt) if err != nil { t.Fatalf("Did not expect error when resolving PipelineRun: %v", err) } @@ -3644,7 +3064,7 @@ func TestIsMatrixed(t *testing.T) { }, }) ctx = cfg.ToContext(ctx) - rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt, nil) + rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt) if err != nil { t.Fatalf("Did not expect error when resolving PipelineRun: %v", err) } @@ -3711,8 +3131,6 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) { TaskSpec: &v1beta1.TaskSpec{Steps: []v1beta1.Step{{ Name: "step1", }}}, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, } getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, *v1beta1.ConfigSource, error) { @@ -3754,7 +3172,7 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) { }, }) ctx = cfg.ToContext(ctx) - rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt, nil) + rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt) if err != nil { t.Fatalf("Did not expect error when resolving PipelineRun: %v", err) } @@ -3874,7 +3292,7 @@ func TestResolvePipelineRunTask_WithMatrixedCustomTask(t *testing.T) { if tc.getRun == nil { tc.getRun = getRun } - rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, tc.getRun, tc.pt, nil) + rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, tc.getRun, tc.pt) if err != nil { t.Fatalf("Did not expect error when resolving PipelineRun: %v", err) } diff --git a/pkg/reconciler/taskrun/controller.go b/pkg/reconciler/taskrun/controller.go index 18d1e89aa24..040974f53e9 100644 --- a/pkg/reconciler/taskrun/controller.go +++ b/pkg/reconciler/taskrun/controller.go @@ -28,7 +28,6 @@ import ( taskrunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/taskrun" resolutionclient "github.com/tektoncd/pipeline/pkg/client/resolution/injection/client" resolutioninformer "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest" - resourceinformer "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource" "github.com/tektoncd/pipeline/pkg/pod" cloudeventclient "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim" @@ -53,7 +52,6 @@ func NewController(opts *pipeline.Options, clock clock.PassiveClock, tracerProvi pipelineclientset := pipelineclient.Get(ctx) taskRunInformer := taskruninformer.Get(ctx) podInformer := filteredpodinformer.Get(ctx, v1beta1.ManagedByLabelKey) - resourceInformer := resourceinformer.Get(ctx) limitrangeInformer := limitrangeinformer.Get(ctx) verificationpolicyInformer := verificationpolicyinformer.Get(ctx) resolutionInformer := resolutioninformer.Get(ctx) @@ -71,7 +69,6 @@ func NewController(opts *pipeline.Options, clock clock.PassiveClock, tracerProvi Images: opts.Images, Clock: clock, taskRunLister: taskRunInformer.Lister(), - resourceLister: resourceInformer.Lister(), limitrangeLister: limitrangeInformer.Lister(), verificationPolicyLister: verificationpolicyInformer.Lister(), cloudEventClient: cloudeventclient.Get(ctx), diff --git a/pkg/reconciler/taskrun/resources/apply.go b/pkg/reconciler/taskrun/resources/apply.go index 2d7ad75304a..bad25e43e41 100644 --- a/pkg/reconciler/taskrun/resources/apply.go +++ b/pkg/reconciler/taskrun/resources/apply.go @@ -125,37 +125,6 @@ func paramsFromTaskRun(ctx context.Context, tr *v1beta1.TaskRun) (map[string]str return stringReplacements, arrayReplacements } -// ApplyResources applies the substitution from values in resources which are referenced in spec as subitems -// of the replacementStr. -func ApplyResources(spec *v1beta1.TaskSpec, resolvedResources map[string]v1beta1.PipelineResourceInterface, replacementStr string) *v1beta1.TaskSpec { - replacements := map[string]string{} - for name, r := range resolvedResources { - for k, v := range r.Replacements() { - replacements[fmt.Sprintf("resources.%s.%s.%s", replacementStr, name, k)] = v - // FIXME(vdemeester) Remove that with deprecating v1beta1 - replacements[fmt.Sprintf("%s.resources.%s.%s", replacementStr, name, k)] = v - } - } - - // We always add replacements for 'path' - if spec.Resources != nil && spec.Resources.Inputs != nil { - for _, r := range spec.Resources.Inputs { - replacements[fmt.Sprintf("resources.inputs.%s.path", r.Name)] = v1beta1.InputResourcePath(r.ResourceDeclaration) - // FIXME(vdemeester) Remove that with deprecating v1beta1 - replacements[fmt.Sprintf("inputs.resources.%s.path", r.Name)] = v1beta1.InputResourcePath(r.ResourceDeclaration) - } - } - if spec.Resources != nil && spec.Resources.Outputs != nil { - for _, r := range spec.Resources.Outputs { - replacements[fmt.Sprintf("resources.outputs.%s.path", r.Name)] = v1beta1.OutputResourcePath(r.ResourceDeclaration) - // FIXME(vdemeester) Remove that with deprecating v1beta1 - replacements[fmt.Sprintf("outputs.resources.%s.path", r.Name)] = v1beta1.OutputResourcePath(r.ResourceDeclaration) - } - } - - return ApplyReplacements(spec, replacements, map[string][]string{}) -} - func getContextReplacements(taskName string, tr *v1beta1.TaskRun) map[string]string { return map[string]string{ "context.taskRun.name": tr.Name, diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index 0041912e215..38573878215 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -24,8 +24,6 @@ import ( "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/pkg/reconciler/taskrun/resources" "github.com/tektoncd/pipeline/pkg/workspace" "github.com/tektoncd/pipeline/test/diff" @@ -40,9 +38,7 @@ 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", } simpleTaskSpec = &v1beta1.TaskSpec{ @@ -185,13 +181,6 @@ var ( }, }, }}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace", - }, - }}, - }, } // a taskspec for testing object var in all places i.e. Sidecars, StepTemplate, Steps and Volumns @@ -456,28 +445,6 @@ var ( }, }, }}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "workspace", - }, - }}, - }, - } - - 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{ @@ -656,43 +623,6 @@ var ( }}, }, } - - inputs = map[string]v1beta1.PipelineResourceInterface{ - "workspace": gitResource, - } - - outputs = map[string]v1beta1.PipelineResourceInterface{ - "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) - - 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 { @@ -1015,61 +945,6 @@ func TestApplyObjectParameters(t *testing.T) { } } -func TestApplyResources(t *testing.T) { - tests := []struct { - name string - ts *v1beta1.TaskSpec - r map[string]v1beta1.PipelineResourceInterface - rStr string - want *v1beta1.TaskSpec - }{{ - name: "no replacements specified", - ts: simpleTaskSpec, - r: make(map[string]v1beta1.PipelineResourceInterface), - rStr: "inputs", - want: applyMutation(simpleTaskSpec, func(spec *v1beta1.TaskSpec) { - spec.Steps[1].WorkingDir = "/workspace/workspace" - spec.Steps[3].WorkingDir = "/workspace/workspace" - }), - }, { - 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[3].WorkingDir = "/workspace/workspace" - spec.Steps[3].Args = []string{"https://git-repo"} - }), - }, { - name: "output resource specified", - ts: simpleTaskSpec, - r: outputs, - rStr: "outputs", - want: applyMutation(simpleTaskSpec, func(spec *v1beta1.TaskSpec) { - spec.Steps[1].WorkingDir = "/workspace/workspace" - spec.Steps[3].WorkingDir = "/workspace/workspace" - }), - }, { - 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) { - got := resources.ApplyResources(tt.ts, tt.r, tt.rStr) - if d := cmp.Diff(tt.want, got); d != "" { - t.Errorf("ApplyResources() %s", diff.PrintWantGot(d)) - } - }) - } -} - func TestApplyWorkspaces(t *testing.T) { names.TestingSeed() ts := &v1beta1.TaskSpec{ 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 176d0489523..00000000000 --- a/pkg/reconciler/taskrun/resources/input_resource_test.go +++ /dev/null @@ -1,1363 +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", - } - 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 deleted file mode 100644 index 83a99092942..00000000000 --- a/pkg/reconciler/taskrun/resources/output_resource.go +++ /dev/null @@ -1,136 +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" - "k8s.io/client-go/kubernetes" -) - -var ( - outputDir = "/workspace/output/" -) - -// 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. -// Steps executed: -// 1. If taskrun has owner reference as pipelinerun then all outputs are copied to parents PVC -// -// and also runs any custom upload steps (upload to blob store) -// 2. If taskrun does not have pipelinerun as owner reference then all outputs resources execute their custom -// -// upload steps (like upload to blob store ) -// -// Resource source path determined -// 1. If resource has a targetpath that is used. Otherwise: -// 2. If resource is declared in outputs only then the default is /output/resource_name -func AddOutputResources( - ctx context.Context, - kubeclient kubernetes.Interface, - images pipeline.Images, - taskName string, - taskSpec *v1beta1.TaskSpec, - taskRun *v1beta1.TaskRun, - outputResources map[string]v1beta1.PipelineResourceInterface, -) (*v1beta1.TaskSpec, error) { - if taskSpec == nil || taskSpec.Resources == nil || taskSpec.Resources.Outputs == nil { - return taskSpec, nil - } - - 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 { - continue - } - return nil, fmt.Errorf("couldnt find resource named %q, no bounded resources", output.Name) - } - boundResource, err := getBoundResource(output.Name, taskRun.Spec.Resources.Outputs) - // 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 output.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 := outputResources[boundResource.Name] - if !ok || resource == nil { - return nil, fmt.Errorf("failed to get output pipeline Resource for task %q resource %v", taskName, boundResource) - } - - var sourcePath string - if output.TargetPath == "" { - sourcePath = filepath.Join(outputDir, boundResource.Name) - } else { - 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. - modifier, err := resource.GetOutputTaskModifier(taskSpec, sourcePath) - 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) - } - } - // 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 deleted file mode 100644 index 76e2efc1131..00000000000 --- a/pkg/reconciler/taskrun/resources/output_resource_test.go +++ /dev/null @@ -1,1651 +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 ( - outputTestResources map[string]v1beta1.PipelineResourceInterface -) - -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", - }}, - }, - }} - - outputTestResources = make(map[string]v1beta1.PipelineResourceInterface) - for _, r := range rs { - ri, _ := resource.FromType(r.Name, r, images) - outputTestResources[r.Name] = ri - } -} - -func TestValidOutputResources(t *testing.T) { - for _, c := range []struct { - name string - 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", - 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: "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: "git resource in output only", - 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: "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: "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"}, - }}, - }, { - 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", - }, - }, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-gcs", - }, - }, - Paths: []string{"pipeline-task-path"}, - }}, - }, - }, - }, - 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-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", - 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"}, - }}, - }, - }, - }, - 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: "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", - }, - }, - }, - }, - }, { - 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", - 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"}, - }}, - }, - }, - }, - 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: "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: "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-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", - TargetPath: "/workspace", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/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-git", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace-1", - 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", - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace-1", - Type: "git", - }}}, - }, - }, - }, - 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, - }}}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-required-output", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - }, - wantErr: true, - }} { - t.Run(c.desc, func(t *testing.T) { - outputTestResourceSetup() - fakekubeclient := fakek8s.NewSimpleClientset() - _, err := AddOutputResources(context.Background(), fakekubeclient, images, c.task.Name, &c.task.Spec, c.taskRun, resolveOutputResources(c.taskRun)) - if (err != nil) != c.wantErr { - t.Fatalf("Test AddOutputResourceSteps %v : error%v", c.desc, err) - } - }) - } -} - -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 { - return resolved - } - for _, r := range taskRun.Spec.Resources.Outputs { - 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(r.Name, &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: r.Name, - }, - Spec: *r.ResourceSpec, - }, images) - resolved[r.Name] = i - } - } - 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.go b/pkg/reconciler/taskrun/resources/taskresourceresolution.go index e67dbdf7a60..7099598cc57 100644 --- a/pkg/reconciler/taskrun/resources/taskresourceresolution.go +++ b/pkg/reconciler/taskrun/resources/taskresourceresolution.go @@ -17,11 +17,7 @@ limitations under the License. package resources import ( - "errors" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // ResolvedTaskResources contains all the data that is needed to execute @@ -30,66 +26,4 @@ type ResolvedTaskResources struct { TaskName string Kind v1beta1.TaskKind TaskSpec *v1beta1.TaskSpec - // Inputs is a map from the name of the input required by the Task - // to the actual Resource to use for it - Inputs map[string]*resourcev1alpha1.PipelineResource - // Outputs is a map from the name of the output required by the Task - // to the actual Resource to use for it - Outputs map[string]*resourcev1alpha1.PipelineResource -} - -// GetResource is a function used to retrieve PipelineResources. -type GetResource func(string) (*resourcev1alpha1.PipelineResource, error) - -// ResolveTaskResources looks up PipelineResources referenced by inputs and outputs and returns -// a structure that unites the resolved references and the Task Spec. If referenced PipelineResources -// can't be found, an error is returned. -func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.TaskKind, inputs []v1beta1.TaskResourceBinding, outputs []v1beta1.TaskResourceBinding, gr GetResource) (*ResolvedTaskResources, error) { - rtr := ResolvedTaskResources{ - TaskName: taskName, - TaskSpec: ts, - Kind: kind, - Inputs: map[string]*resourcev1alpha1.PipelineResource{}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{}, - } - - for _, r := range inputs { - rr, err := GetResourceFromBinding(r.PipelineResourceBinding, gr) - if err != nil { - return nil, err - } - - rtr.Inputs[r.Name] = rr - } - - for _, r := range outputs { - rr, err := GetResourceFromBinding(r.PipelineResourceBinding, gr) - - if err != nil { - return nil, err - } - - rtr.Outputs[r.Name] = rr - } - return &rtr, nil -} - -// GetResourceFromBinding will return an instance of a PipelineResource to use for r, either by getting it with getter or by -// instantiating it from the embedded spec. -func GetResourceFromBinding(r v1beta1.PipelineResourceBinding, getter GetResource) (*resourcev1alpha1.PipelineResource, error) { - if (r.ResourceRef != nil && r.ResourceRef.Name != "") && r.ResourceSpec != nil { - return nil, errors.New("Both ResourceRef and ResourceSpec are defined. Expected only one") - } - if r.ResourceRef != nil && r.ResourceRef.Name != "" { - return getter(r.ResourceRef.Name) - } - if r.ResourceSpec != nil { - return &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: r.Name, - }, - Spec: *r.ResourceSpec, - }, nil - } - return nil, errors.New("Neither ResourceRef nor ResourceSpec is defined") } diff --git a/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go b/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go deleted file mode 100644 index b565eda553f..00000000000 --- a/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go +++ /dev/null @@ -1,362 +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 ( - "fmt" - "testing" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - kerrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestResolveTaskRun(t *testing.T) { - inputs := []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "repoToBuildFrom", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "git-repo", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "clusterToUse", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "k8s-cluster", - }, - }, - }} - - outputs := []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "imageToBuild", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "image", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "gitRepoToUpdate", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "another-git-repo", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "gitspecToUse", - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - }} - - taskName := "orchestrate" - kind := v1beta1.NamespacedTaskKind - taskSpec := v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "step1", - }, - }} - - resources := []*resourcev1alpha1.PipelineResource{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-repo", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "k8s-cluster", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "image", - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "another-git-repo", - }, - }} - resourceIndex := 0 - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - r := resources[resourceIndex] - resourceIndex++ - return r, nil - } - - rtr, err := ResolveTaskResources(&taskSpec, taskName, kind, inputs, outputs, gr) - if err != nil { - t.Fatalf("Did not expect error trying to resolve TaskRun: %s", err) - } - - if rtr.TaskName != "orchestrate" { - t.Errorf("Expected task name `orchestrate` Task but got: %v", rtr.TaskName) - } - if rtr.TaskSpec == nil || len(rtr.TaskSpec.Steps) != 1 || rtr.TaskSpec.Steps[0].Name != "step1" { - t.Errorf("Task not resolved, expected task's spec to be used but spec was: %v", rtr.TaskSpec) - } - - if len(rtr.Inputs) == 2 { - r, ok := rtr.Inputs["repoToBuildFrom"] - if !ok { - t.Errorf("Expected value present in map for `repoToBuildFrom' but it was missing") - } else if r.Name != "git-repo" { - t.Errorf("Expected to use resource `git-repo` for `repoToBuildFrom` but used %s", r.Name) - } - r, ok = rtr.Inputs["clusterToUse"] - if !ok { - t.Errorf("Expected value present in map for `clusterToUse' but it was missing") - } else if r.Name != "k8s-cluster" { - t.Errorf("Expected to use resource `k8s-cluster` for `clusterToUse` but used %s", r.Name) - } - } else { - t.Errorf("Expected 2 resolved inputs but instead had: %v", rtr.Inputs) - } - - if len(rtr.Outputs) == 3 { - r, ok := rtr.Outputs["imageToBuild"] - if !ok { - t.Errorf("Expected value present in map for `imageToBuild' but it was missing") - } else if r.Name != "image" { - t.Errorf("Expected to use resource `image` for `imageToBuild` but used %s", r.Name) - } - r, ok = rtr.Outputs["gitRepoToUpdate"] - if !ok { - t.Errorf("Expected value present in map for `gitRepoToUpdate' but it was missing") - } 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) - } -} - -func TestResolveTaskRun_missingOutput(t *testing.T) { - outputs := []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "repoToUpdate", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "another-git-repo", - }, - }}} - - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return nil, kerrors.NewNotFound(resourcev1alpha1.Resource("pipelineresources"), n) - } - _, err := ResolveTaskResources(&v1beta1.TaskSpec{}, "orchestrate", v1beta1.NamespacedTaskKind, []v1beta1.TaskResourceBinding{}, outputs, gr) - if err == nil { - t.Fatalf("Expected to get error because output resource couldn't be resolved") - } else if !kerrors.IsNotFound(err) { - t.Fatalf("ResolveTaskResources() = %v, wanted not found", err) - } -} - -func TestResolveTaskRun_missingInput(t *testing.T) { - inputs := []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "repoToBuildFrom", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "git-repo", - }, - }}} - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return nil, kerrors.NewNotFound(resourcev1alpha1.Resource("pipelineresources"), n) - } - - _, err := ResolveTaskResources(&v1beta1.TaskSpec{}, "orchestrate", v1beta1.NamespacedTaskKind, inputs, []v1beta1.TaskResourceBinding{}, gr) - if err == nil { - t.Fatalf("Expected to get error because output resource couldn't be resolved") - } else if !kerrors.IsNotFound(err) { - t.Fatalf("ResolveTaskResources() = %v, wanted not found", err) - } -} - -func TestResolveTaskRun_noResources(t *testing.T) { - taskSpec := v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "step1", - }, - }} - - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return &resourcev1alpha1.PipelineResource{}, nil - } - - rtr, err := ResolveTaskResources(&taskSpec, "orchestrate", v1beta1.NamespacedTaskKind, []v1beta1.TaskResourceBinding{}, []v1beta1.TaskResourceBinding{}, gr) - if err != nil { - t.Fatalf("Did not expect error trying to resolve TaskRun: %s", err) - } - - if rtr.TaskName != "orchestrate" { - t.Errorf("Task not resolved, expected `orchestrate` Task but got: %v", rtr.TaskName) - } - if rtr.TaskSpec == nil || len(rtr.TaskSpec.Steps) != 1 || rtr.TaskSpec.Steps[0].Name != "step1" { - t.Errorf("Task not resolved, expected task's spec to be used but spec was: %v", rtr.TaskSpec) - } - - if len(rtr.Inputs) != 0 { - t.Errorf("Did not expect any outputs to be resolved when none specified but had %v", rtr.Inputs) - } - if len(rtr.Outputs) != 0 { - t.Errorf("Did not expect any outputs to be resolved when none specified but had %v", rtr.Outputs) - } -} - -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{ - Name: "repoToBuildFrom", - }, - }} - 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 neither spec or ref were used") - } -} - -func TestGetResourceFromBinding_Ref(t *testing.T) { - r := &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-repo", - }, - } - binding := v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "foo-resource", - }, - } - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return r, nil - } - - rr, err := GetResourceFromBinding(binding, gr) - if err != nil { - t.Fatalf("Did not expect error trying to get resource from binding: %s", err) - } - if rr != r { - t.Errorf("Didn't get expected resource, got %v", rr) - } -} - -func TestGetResourceFromBinding_Spec(t *testing.T) { - binding := v1beta1.PipelineResourceBinding{ - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "url", - Value: "github.com/mycoolorg/mycoolrepo", - }}, - }, - } - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return nil, fmt.Errorf("shouldnt be called! but was for %s", n) - } - - rr, err := GetResourceFromBinding(binding, gr) - if err != nil { - t.Fatalf("Did not expect error trying to get resource from binding: %s", err) - } - if rr.Spec.Type != resourcev1alpha1.PipelineResourceTypeGit { - 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" { - t.Errorf("Got unexpected params %v", rr.Spec.Params) - } -} - -func TestGetResourceFromBinding_NoNameOrSpec(t *testing.T) { - binding := v1beta1.PipelineResourceBinding{} - 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_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{ - Name: "foo-resource", - }, - } - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return nil, fmt.Errorf("it has all gone wrong") - } - _, err := GetResourceFromBinding(binding, gr) - if err == nil { - t.Fatalf("Expected error when error retrieving resource but got none") - } -} 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 870e8fabf78..ce1c282989f 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -31,13 +31,10 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" clientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" taskrunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/taskrun" alphalisters "github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1alpha1" listers "github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1beta1" - resourcelisters "github.com/tektoncd/pipeline/pkg/client/resource/listers/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/internal/affinityassistant" "github.com/tektoncd/pipeline/pkg/internal/computeresources" resolutionutil "github.com/tektoncd/pipeline/pkg/internal/resolution" @@ -83,7 +80,6 @@ type Reconciler struct { // listers index properties about resources taskRunLister listers.TaskRunLister - resourceLister resourcelisters.PipelineResourceLister limitrangeLister corev1Listers.LimitRangeLister podLister corev1Listers.PodLister verificationPolicyLister alphalisters.VerificationPolicyLister @@ -371,26 +367,10 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1 } } - inputs := []v1beta1.TaskResourceBinding{} - outputs := []v1beta1.TaskResourceBinding{} - if tr.Spec.Resources != nil { - inputs = tr.Spec.Resources.Inputs - outputs = tr.Spec.Resources.Outputs - } - rtr, err := resources.ResolveTaskResources(taskSpec, taskMeta.Name, resources.GetTaskKind(tr), inputs, outputs, c.resourceLister.PipelineResources(tr.Namespace).Get) - if err != nil { - if k8serrors.IsNotFound(err) && tknreconciler.IsYoungResource(tr) { - // For newly created resources, don't fail immediately. - // Instead return an (non-permanent) error, which will prompt the - // controller to requeue the key with backoff. - logger.Warnf("References for taskrun %s not found: %v", tr.Name, err) - tr.Status.MarkResourceOngoing(podconvert.ReasonFailedResolution, - fmt.Sprintf("Unable to resolve dependencies for %q: %v", tr.Name, err)) - return nil, nil, err - } - logger.Errorf("Failed to resolve references for taskrun %s: %v", tr.Name, err) - tr.Status.MarkResourceFailed(podconvert.ReasonFailedResolution, err) - return nil, nil, controller.NewPermanentError(err) + rtr := &resources.ResolvedTaskResources{ + TaskName: taskMeta.Name, + TaskSpec: taskSpec, + Kind: resources.GetTaskKind(tr), } if err := validateTaskSpecRequestResources(taskSpec); err != nil { @@ -726,32 +706,6 @@ func (c *Reconciler) createPod(ctx context.Context, ts *v1beta1.TaskSpec, tr *v1 ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "createPod") defer span.End() logger := logging.FromContext(ctx) - inputResources, err := resourceImplBinding(rtr.Inputs, c.Images) - if err != nil { - logger.Errorf("Failed to initialize input resources: %v", err) - return nil, err - } - outputResources, err := resourceImplBinding(rtr.Outputs, c.Images) - if err != nil { - logger.Errorf("Failed to initialize output resources: %v", err) - 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) - return nil, err - } - - // Apply bound resource substitution from the taskrun. - ts = resources.ApplyResources(ts, inputResources, "inputs") - ts = resources.ApplyResources(ts, outputResources, "outputs") // By this time, params and workspaces should be propagated down so we can // validate that all parameter variables and workspaces used in the TaskSpec are declared by the Task. @@ -761,6 +715,7 @@ func (c *Reconciler) createPod(ctx context.Context, ts *v1beta1.TaskSpec, tr *v1 return nil, validateErr } + var err error ts, err = workspace.Apply(ctx, *ts, tr.Spec.Workspaces, workspaceVolumes) if err != nil { @@ -858,19 +813,6 @@ func isTaskRunValidationFailed(err error) bool { return err != nil && strings.Contains(err.Error(), "TaskRun validation failed") } -// resourceImplBinding maps pipeline resource names to the actual resource type implementations -func resourceImplBinding(resources map[string]*resourcev1alpha1.PipelineResource, images pipeline.Images) (map[string]v1beta1.PipelineResourceInterface, error) { - p := make(map[string]v1beta1.PipelineResourceInterface) - for rName, r := range resources { - i, err := resource.FromType(rName, r, images) - if err != nil { - return nil, fmt.Errorf("failed to create resource %s : %v with error: %w", rName, r, err) - } - p[rName] = i - } - return p, nil -} - // updateStoppedSidecarStatus updates SidecarStatus for sidecars that were // terminated by nop image func updateStoppedSidecarStatus(pod *corev1.Pod, tr *v1beta1.TaskRun) error { diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 742c0a4a88c..008a7742b2b 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -37,7 +37,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" "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" podconvert "github.com/tektoncd/pipeline/pkg/pod" "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" @@ -70,7 +69,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" _ "knative.dev/pkg/system/testing" // Setup system.Namespace() @@ -87,9 +85,7 @@ 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", } now = time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC) ignoreLastTransitionTime = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time") @@ -182,35 +178,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{ @@ -245,20 +212,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: "workspace", - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }}, - }, Steps: []v1beta1.Step{ { Image: "myimage", @@ -292,27 +245,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", - }}, - }, - } - binVolume = corev1.Volume{ Name: "tekton-internal-bin", VolumeSource: corev1.VolumeSource{ @@ -361,10 +293,6 @@ var ( EmptyDir: &corev1.EmptyDirVolumeSource{}, }, } - - gitResourceSecurityContext = &corev1.SecurityContext{ - RunAsUser: ptr.Int64(0), - } ) const fakeVersion string = "unknown" @@ -682,60 +610,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: workspace - resourceRef: - name: git-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: @@ -745,56 +619,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 @@ -878,17 +715,15 @@ 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}, - ClusterTasks: []*v1beta1.ClusterTask{clustertask}, - PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource}, + TaskRuns: taskruns, + Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask}, + ClusterTasks: []*v1beta1.ClusterTask{clustertask}, } for _, tc := range []struct { name string @@ -919,61 +754,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-workspace-mz4c7", - image: "busybox", - cmd: "mkdir", - args: []string{"-p", "/workspace/output/workspace"}, - }, - { - 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", - "--my-arg-with-default=bar", - "--my-arg-with-default2=thedefault", - "--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: "taskrun-with-taskspec", taskRun: taskRunWithTaskSpec, @@ -982,26 +762,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", - }, }, }), }, { @@ -1016,35 +780,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, @@ -1188,11 +923,10 @@ spec: }, }} d := test.Data{ - ConfigMaps: cms, - TaskRuns: taskruns, - Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask, outputTask}, - ClusterTasks: []*v1beta1.ClusterTask{clustertask}, - PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource}, + ConfigMaps: cms, + TaskRuns: taskruns, + Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask}, + ClusterTasks: []*v1beta1.ClusterTask{clustertask}, } for _, tc := range []struct { name string @@ -2045,10 +1779,9 @@ spec: name: test-task `) d := test.Data{ - TaskRuns: []*v1beta1.TaskRun{tr}, - Tasks: []*v1beta1.Task{simpleTask}, - ClusterTasks: []*v1beta1.ClusterTask{}, - PipelineResources: []*resourcev1alpha1.PipelineResource{}, + TaskRuns: []*v1beta1.TaskRun{tr}, + Tasks: []*v1beta1.Task{simpleTask}, + ClusterTasks: []*v1beta1.ClusterTask{}, } testAssets, cancel := getTaskRunController(t, d) defer cancel() @@ -2840,7 +2573,6 @@ spec: PipelineClientSet: testAssets.Clients.Pipeline, Clock: testClock, taskRunLister: testAssets.Informers.TaskRun.Lister(), - resourceLister: testAssets.Informers.PipelineResource.Lister(), limitrangeLister: testAssets.Informers.LimitRange.Lister(), cloudEventClient: testAssets.Clients.CloudEvents, metrics: nil, // Not used @@ -2950,7 +2682,6 @@ spec: PipelineClientSet: testAssets.Clients.Pipeline, Clock: testClock, taskRunLister: testAssets.Informers.TaskRun.Lister(), - resourceLister: testAssets.Informers.PipelineResource.Lister(), limitrangeLister: testAssets.Informers.LimitRange.Lister(), cloudEventClient: testAssets.Clients.CloudEvents, metrics: nil, // Not used @@ -3004,7 +2735,6 @@ status: PipelineClientSet: testAssets.Clients.Pipeline, Clock: testClock, taskRunLister: testAssets.Informers.TaskRun.Lister(), - resourceLister: testAssets.Informers.PipelineResource.Lister(), limitrangeLister: testAssets.Informers.LimitRange.Lister(), cloudEventClient: testAssets.Clients.CloudEvents, metrics: nil, // Not used @@ -3205,10 +2935,9 @@ spec: name: test-task-with-workspace `) d := test.Data{ - Tasks: []*v1beta1.Task{taskWithWorkspace}, - TaskRuns: []*v1beta1.TaskRun{taskRun}, - ClusterTasks: nil, - PipelineResources: nil, + Tasks: []*v1beta1.Task{taskWithWorkspace}, + TaskRuns: []*v1beta1.TaskRun{taskRun}, + ClusterTasks: nil, } testAssets, cancel := getTaskRunController(t, d) defer cancel() @@ -3266,10 +2995,9 @@ spec: name: test-task-with-workspace `) d := test.Data{ - Tasks: []*v1beta1.Task{taskWithWorkspace}, - TaskRuns: []*v1beta1.TaskRun{taskRun}, - ClusterTasks: nil, - PipelineResources: nil, + Tasks: []*v1beta1.Task{taskWithWorkspace}, + TaskRuns: []*v1beta1.TaskRun{taskRun}, + ClusterTasks: nil, } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ @@ -3331,10 +3059,9 @@ spec: name: test-task-with-workspace `) d := test.Data{ - Tasks: []*v1beta1.Task{taskWithWorkspace}, - TaskRuns: []*v1beta1.TaskRun{taskRun}, - ClusterTasks: nil, - PipelineResources: nil, + Tasks: []*v1beta1.Task{taskWithWorkspace}, + TaskRuns: []*v1beta1.TaskRun{taskRun}, + ClusterTasks: nil, } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ @@ -3439,159 +3166,6 @@ spec: } } -func TestReconcileTaskResourceResolutionAndValidation(t *testing.T) { - for _, tt := range []struct { - desc string - d test.Data - wantFailedReason string - wantEvents []string - }{{ - desc: "Fail ResolveTaskResources", - d: test.Data{ - Tasks: []*v1beta1.Task{parse.MustParseV1beta1Task(t, ` -metadata: - name: test-task-missing-resource - namespace: foo -spec: - resources: - inputs: - - name: workspace - type: git -`)}, - TaskRuns: []*v1beta1.TaskRun{parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-taskrun-missing-resource - namespace: foo -spec: - resources: - inputs: - - name: workspace - resourceRef: - name: git - taskRef: - apiVersion: a1 - name: test-task-missing-resource -`)}, - ClusterTasks: nil, - PipelineResources: nil, - }, - wantFailedReason: podconvert.ReasonFailedResolution, - wantEvents: []string{ - "Normal Started ", - "Warning Failed", // Event about the TaskRun state changed - "Warning InternalError", // Event about the error (generated by the genreconciler) - }, - }, { - desc: "Fail ValidateResolvedTaskResources", - d: test.Data{ - Tasks: []*v1beta1.Task{parse.MustParseV1beta1Task(t, ` -metadata: - name: test-task-missing-resource - namespace: foo -spec: - resources: - inputs: - - name: workspace - type: git -`)}, - TaskRuns: []*v1beta1.TaskRun{parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-taskrun-missing-resource - namespace: foo -spec: - taskRef: - apiVersion: a1 - name: test-task-missing-resource -`)}, - ClusterTasks: nil, - PipelineResources: nil, - }, - wantFailedReason: podconvert.ReasonFailedValidation, - wantEvents: []string{ - "Normal Started ", - "Warning Failed", // Event about the TaskRun state changed - "Warning InternalError", // Event about the error (generated by the genreconciler) - }, - }, { - desc: "Fail ValidateTaskSpecRequestResources", - d: test.Data{ - Tasks: []*v1beta1.Task{parse.MustParseV1beta1Task(t, ` -metadata: - name: test-task-invalid-taskspec-resource - namespace: foo -spec: - steps: - - command: - - cmd - image: image - resources: - limits: - cpu: "8" - memory: 4Gi - requests: - cpu: "8" - memory: 8Gi - workspaces: - - description: a test task workspace - name: ws1 - readOnly: true -`)}, - TaskRuns: []*v1beta1.TaskRun{parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-taskrun-invalid-taskspec-resource - namespace: foo -spec: - taskRef: - apiVersion: a1 - name: test-task-invalid-taskspec-resource -`)}, - ClusterTasks: nil, - PipelineResources: nil, - }, - wantFailedReason: podconvert.ReasonFailedValidation, - wantEvents: []string{ - "Normal Started ", - "Warning Failed", // Event about the TaskRun state changed - "Warning InternalError", // Event about the error (generated by the genreconciler) - }, - }} { - t.Run(tt.desc, func(t *testing.T) { - testAssets, cancel := getTaskRunController(t, tt.d) - defer cancel() - clients := testAssets.Clients - c := testAssets.Controller - - reconcileErr := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(tt.d.TaskRuns[0])) - - // When a TaskRun is invalid and can't run, we return a permanent error because - // a regular error will tell the Reconciler to keep trying to reconcile; instead we want to stop - // and forget about the Run. - if reconcileErr == nil { - t.Fatalf("Expected to see error when reconciling invalid TaskRun but none") - } - if !controller.IsPermanentError(reconcileErr) { - t.Fatalf("Expected to see a permanent error when reconciling invalid TaskRun, got %s instead", reconcileErr) - } - - tr, err := clients.Pipeline.TektonV1beta1().TaskRuns(tt.d.TaskRuns[0].Namespace).Get(testAssets.Ctx, tt.d.TaskRuns[0].Name, metav1.GetOptions{}) - if err != nil { - t.Fatalf("Expected TaskRun %s to exist but instead got error when getting it: %v", tt.d.TaskRuns[0].Name, err) - } - - for _, c := range tr.Status.Conditions { - if c.Type != apis.ConditionSucceeded || c.Status != corev1.ConditionFalse || c.Reason != tt.wantFailedReason { - t.Errorf("Expected TaskRun to \"%s\" but it did not. Final conditions were:\n%#v", tt.wantFailedReason, tr.Status.Conditions) - } - } - - err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, tt.desc, tt.wantEvents) - if !(err == nil) { - t.Errorf(err.Error()) - } - }) - } -} - // TestReconcileWithWorkspacesIncompatibleWithAffinityAssistant tests that a TaskRun used with an associated // Affinity Assistant is validated and that the validation fails for a TaskRun that is incompatible with // Affinity Assistant; e.g. using more than one PVC-backed workspace. @@ -3629,10 +3203,9 @@ spec: `) d := test.Data{ - Tasks: []*v1beta1.Task{taskWithTwoWorkspaces}, - TaskRuns: []*v1beta1.TaskRun{taskRun}, - ClusterTasks: nil, - PipelineResources: nil, + Tasks: []*v1beta1.Task{taskWithTwoWorkspaces}, + TaskRuns: []*v1beta1.TaskRun{taskRun}, + ClusterTasks: nil, } testAssets, cancel := getTaskRunController(t, d) defer cancel() @@ -3695,10 +3268,9 @@ spec: name: mypvc `) d := test.Data{ - Tasks: []*v1beta1.Task{taskWithWorkspace}, - TaskRuns: []*v1beta1.TaskRun{taskRun}, - ClusterTasks: nil, - PipelineResources: nil, + Tasks: []*v1beta1.Task{taskWithWorkspace}, + TaskRuns: []*v1beta1.TaskRun{taskRun}, + ClusterTasks: nil, } testAssets, cancel := getTaskRunController(t, d) defer cancel() @@ -4074,7 +3646,6 @@ status: PipelineClientSet: testAssets.Clients.Pipeline, Clock: testClock, taskRunLister: testAssets.Informers.TaskRun.Lister(), - resourceLister: testAssets.Informers.PipelineResource.Lister(), limitrangeLister: testAssets.Informers.LimitRange.Lister(), cloudEventClient: testAssets.Clients.CloudEvents, metrics: nil, // Not used diff --git a/pkg/reconciler/taskrun/validate_resources.go b/pkg/reconciler/taskrun/validate_resources.go index afad7a58d1b..cf3addd6638 100644 --- a/pkg/reconciler/taskrun/validate_resources.go +++ b/pkg/reconciler/taskrun/validate_resources.go @@ -24,52 +24,12 @@ import ( "github.com/hashicorp/go-multierror" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/list" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" "k8s.io/apimachinery/pkg/util/sets" ) -func validateResources(requiredResources []v1beta1.TaskResource, providedResources map[string]*resourcev1alpha1.PipelineResource) error { - required := make([]string, 0, len(requiredResources)) - optional := make([]string, 0, len(requiredResources)) - for _, resource := range requiredResources { - if resource.Optional { - // create a list of optional resources - optional = append(optional, resource.Name) - } else { - // create a list of required resources - required = append(required, resource.Name) - } - } - provided := make([]string, 0, len(providedResources)) - for resource := range providedResources { - provided = append(provided, resource) - } - // verify that the list of required resources does exist in the provided resources - missing := list.DiffLeft(required, provided) - if len(missing) > 0 { - return fmt.Errorf("Task's declared required resources are missing from the TaskRun: %s", missing) - } - // verify that the list of provided resources does not have any extra resources (outside of required and optional resources combined) - extra := list.DiffLeft(provided, append(required, optional...)) - if len(extra) > 0 { - return fmt.Errorf("TaskRun's declared resources didn't match usage in Task: %s", extra) - } - for _, resource := range requiredResources { - r := providedResources[resource.Name] - if !resource.Optional && r == nil { - // This case should never be hit due to the check for missing resources at the beginning of the function - return fmt.Errorf("resource %q is missing", resource.Name) - } - if r != nil && resource.Type != r.Spec.Type { - return fmt.Errorf("resource %q should be type %q but was %q", resource.Name, r.Spec.Type, resource.Type) - } - } - return nil -} - func validateParams(ctx context.Context, paramSpecs []v1beta1.ParamSpec, params []v1beta1.Param, matrix *v1beta1.Matrix) error { neededParamsNames, neededParamsTypes := neededParamsNamesAndTypes(paramSpecs) var matrixParams []v1beta1.Param @@ -211,19 +171,6 @@ func ValidateResolvedTaskResources(ctx context.Context, params []v1beta1.Param, if err := validateParams(ctx, rtr.TaskSpec.Params, params, matrix); err != nil { return fmt.Errorf("invalid input params for task %s: %w", rtr.TaskName, err) } - inputs := []v1beta1.TaskResource{} - outputs := []v1beta1.TaskResource{} - if rtr.TaskSpec.Resources != nil { - inputs = rtr.TaskSpec.Resources.Inputs - outputs = rtr.TaskSpec.Resources.Outputs - } - if err := validateResources(inputs, rtr.Inputs); err != nil { - return fmt.Errorf("invalid input resources for task %s: %w", rtr.TaskName, err) - } - if err := validateResources(outputs, rtr.Outputs); err != nil { - return fmt.Errorf("invalid output resources for task %s: %w", rtr.TaskName, err) - } - return nil } diff --git a/pkg/reconciler/taskrun/validate_resources_test.go b/pkg/reconciler/taskrun/validate_resources_test.go index 7091a3596bb..32a32ae7de6 100644 --- a/pkg/reconciler/taskrun/validate_resources_test.go +++ b/pkg/reconciler/taskrun/validate_resources_test.go @@ -24,101 +24,9 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" ) -func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { - ctx := context.Background() - task := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Image: "myimage", - 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{ - Name: "resource-to-provide", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: false, - }, - }, - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-resource-to-provide", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: true, - }, - }, - }, - }, - }, - } - 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", - }}, - }, - }, - }, - Outputs: map[string]*resourcev1alpha1.PipelineResource{ - "resource-to-provide": { - ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - "optional-resource-to-provide": { - ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }, - }, - } - if err := ValidateResolvedTaskResources(ctx, []v1beta1.Param{}, &v1beta1.Matrix{}, rtr); err != nil { - t.Fatalf("Did not expect to see error when validating valid resolved TaskRun but saw %v", err) - } -} - func TestValidateResolvedTaskResources_ValidParams(t *testing.T) { ctx := context.Background() task := &v1beta1.Task{ @@ -337,188 +245,6 @@ 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"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeGit, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "foo", - Value: "bar", - }}, - }, - } - testinput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "testinput", - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }}, - }, - }, - } - testrequiredgitinput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredgitinput", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: false, - }, - }}, - }, - }, - } - testoutput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "testoutput", - Type: resourcev1alpha1.PipelineResourceTypeGit, - }, - }}, - }, - }, - } - testrequiredgitoutput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredgitoutput", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: false, - }, - }}, - }, - }, - } - testrequiredinputandoutput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredgitinput", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: false, - }, - }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredgitoutput", - Type: resourcev1alpha1.PipelineResourceTypeGit, - Optional: false, - }, - }}, - }, - }, - } - tcs := []struct { - 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: &testinput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{"testimageinput": r}, - }, - }, { - name: "input-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testinput.Spec, - }, - }, { - name: "output-resource-mismatch", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testoutput.Spec, - Outputs: map[string]*resourcev1alpha1.PipelineResource{"testimageoutput": r}, - }, - }, { - name: "output-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testoutput.Spec, - }, - }, { - name: "extra-input-resource", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testinput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{ - "testinput": r, - "someextrainput": r, - }, - }, - }, { - name: "extra-output-resource", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testoutput.Spec, - Outputs: map[string]*resourcev1alpha1.PipelineResource{ - "testoutput": r, - "someextraoutput": r, - }, - }, - }, { - name: "extra-input-resource-none-required", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testoutput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{"someextrainput": r}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{"testoutput": r}, - }, - }, { - name: "extra-output-resource-none-required", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testinput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{"testinput": r}, - Outputs: map[string]*resourcev1alpha1.PipelineResource{"someextraoutput": r}, - }, - }, { - name: "required-input-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testrequiredgitinput.Spec, - }, - }, { - name: "required-output-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testrequiredgitoutput.Spec, - }, - }, { - name: "required-input-and-output-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testrequiredinputandoutput.Spec, - }, - }} - - for _, tc := range tcs { - t.Run(tc.name, func(t *testing.T) { - if err := ValidateResolvedTaskResources(ctx, []v1beta1.Param{}, &v1beta1.Matrix{Params: []v1beta1.Param{}}, tc.rtr); err == nil { - t.Errorf("Expected to see error when validating invalid resolved TaskRun but saw none") - } - }) - } -} - func TestValidateOverrides(t *testing.T) { tcs := []struct { name string diff --git a/pkg/spire/spire_mock_test.go b/pkg/spire/spire_mock_test.go index 093dc02c4d0..a04e6965c53 100644 --- a/pkg/spire/spire_mock_test.go +++ b/pkg/spire/spire_mock_test.go @@ -563,7 +563,6 @@ func testTaskRuns() []*v1beta1.TaskRun { Spec: v1beta1.TaskRunSpec{ TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"}, ServiceAccountName: "test-sa", - Resources: &v1beta1.TaskRunResources{}, Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, }, Status: v1beta1.TaskRunStatus{ @@ -582,7 +581,6 @@ func testTaskRuns() []*v1beta1.TaskRun { Spec: v1beta1.TaskRunSpec{ TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"}, ServiceAccountName: "test-sa", - Resources: &v1beta1.TaskRunResources{}, Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, }, Status: v1beta1.TaskRunStatus{ @@ -607,7 +605,6 @@ func testTaskRuns() []*v1beta1.TaskRun { Spec: v1beta1.TaskRunSpec{ TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"}, ServiceAccountName: "test-sa", - Resources: &v1beta1.TaskRunResources{}, Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, }, Status: v1beta1.TaskRunStatus{ 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 b07d2897733..00000000000 --- a/test/artifact_bucket_test.go +++ /dev/null @@ -1,356 +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/pkg/apis/config" - "github.com/tektoncd/pipeline/test/parse" - 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/clients.go b/test/clients.go index 39a5c561daa..e003b537dbe 100644 --- a/test/clients.go +++ b/test/clients.go @@ -48,8 +48,6 @@ import ( "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1" resolutionversioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1" - resourceversioned "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1" "k8s.io/client-go/kubernetes" knativetest "knative.dev/pkg/test" ) @@ -64,7 +62,6 @@ type clients struct { V1beta1TaskRunClient v1beta1.TaskRunInterface V1beta1PipelineRunClient v1beta1.PipelineRunInterface V1beta1CustomRunClient v1beta1.CustomRunInterface - V1alpha1PipelineResourceClient resourcev1alpha1.PipelineResourceInterface V1alpha1RunClient v1alpha1.RunInterface V1alpha1ResolutionRequestclient resolutionv1alpha1.ResolutionRequestInterface V1alpha1VerificationPolicyClient v1alpha1.VerificationPolicyInterface @@ -97,10 +94,6 @@ func newClients(t *testing.T, configPath, clusterName, namespace string) *client if err != nil { t.Fatalf("failed to create pipeline clientset from config file at %s: %s", configPath, err) } - rcs, err := resourceversioned.NewForConfig(cfg) - if err != nil { - t.Fatalf("failed to create pipeline resource clientset from config file at %s: %s", configPath, err) - } rrcs, err := resolutionversioned.NewForConfig(cfg) if err != nil { t.Fatalf("failed to create resolution clientset from config file at %s: %s", configPath, err) @@ -111,7 +104,6 @@ func newClients(t *testing.T, configPath, clusterName, namespace string) *client c.V1beta1TaskRunClient = cs.TektonV1beta1().TaskRuns(namespace) c.V1beta1PipelineRunClient = cs.TektonV1beta1().PipelineRuns(namespace) c.V1beta1CustomRunClient = cs.TektonV1beta1().CustomRuns(namespace) - c.V1alpha1PipelineResourceClient = rcs.TektonV1alpha1().PipelineResources(namespace) c.V1alpha1RunClient = cs.TektonV1alpha1().Runs(namespace) c.V1alpha1ResolutionRequestclient = rrcs.ResolutionV1alpha1().ResolutionRequests(namespace) c.V1alpha1VerificationPolicyClient = cs.TektonV1alpha1().VerificationPolicies(namespace) diff --git a/test/controller.go b/test/controller.go index 32e09b34446..960e7364963 100644 --- a/test/controller.go +++ b/test/controller.go @@ -27,7 +27,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" fakepipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake" informersv1alpha1 "github.com/tektoncd/pipeline/pkg/client/informers/externalversions/pipeline/v1alpha1" informersv1beta1 "github.com/tektoncd/pipeline/pkg/client/informers/externalversions/pipeline/v1beta1" @@ -44,10 +43,6 @@ import ( resolutioninformersv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1beta1" fakeresolutionrequestclient "github.com/tektoncd/pipeline/pkg/client/resolution/injection/client/fake" fakeresolutionrequestinformer "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/fake" - fakeresourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/fake" - resourceinformersv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resource/informers/externalversions/resource/v1alpha1" - fakeresourceclient "github.com/tektoncd/pipeline/pkg/client/resource/injection/client/fake" - fakeresourceinformer "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource/fake" cloudeventclient "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -77,7 +72,6 @@ type Data struct { TaskRuns []*v1beta1.TaskRun Tasks []*v1beta1.Task ClusterTasks []*v1beta1.ClusterTask - PipelineResources []*resourcev1alpha1.PipelineResource Runs []*v1alpha1.Run CustomRuns []*v1beta1.CustomRun Pods []*corev1.Pod @@ -93,7 +87,6 @@ type Data struct { // Clients holds references to clients which are useful for reconciler tests. type Clients struct { Pipeline *fakepipelineclientset.Clientset - Resource *fakeresourceclientset.Clientset Kube *fakekubeclientset.Clientset CloudEvents cloudeventclient.CEClient ResolutionRequests *fakeresolutionclientset.Clientset @@ -108,7 +101,6 @@ type Informers struct { CustomRun informersv1beta1.CustomRunInformer Task informersv1beta1.TaskInformer ClusterTask informersv1beta1.ClusterTaskInformer - PipelineResource resourceinformersv1alpha1.PipelineResourceInformer Pod coreinformers.PodInformer ConfigMap coreinformers.ConfigMapInformer ServiceAccount coreinformers.ServiceAccountInformer @@ -180,7 +172,6 @@ func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers c := Clients{ Kube: fakekubeclient.Get(ctx), Pipeline: fakepipelineclient.Get(ctx), - Resource: fakeresourceclient.Get(ctx), CloudEvents: cloudeventclient.Get(ctx), ResolutionRequests: fakeresolutionrequestclient.Get(ctx), } @@ -195,7 +186,6 @@ func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers CustomRun: fakecustomruninformer.Get(ctx), Task: faketaskinformer.Get(ctx), ClusterTask: fakeclustertaskinformer.Get(ctx), - PipelineResource: fakeresourceinformer.Get(ctx), Pod: fakefilteredpodinformer.Get(ctx, v1beta1.ManagedByLabelKey), ConfigMap: fakeconfigmapinformer.Get(ctx), ServiceAccount: fakeserviceaccountinformer.Get(ctx), @@ -242,13 +232,6 @@ func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers t.Fatal(err) } } - c.Resource.PrependReactor("*", "pipelineresources", AddToInformer(t, i.PipelineResource.Informer().GetIndexer())) - for _, r := range d.PipelineResources { - r := r.DeepCopy() // Avoid assumptions that the informer's copy is modified. - if _, err := c.Resource.TektonV1alpha1().PipelineResources(r.Namespace).Create(ctx, r, metav1.CreateOptions{}); err != nil { - t.Fatal(err) - } - } c.Pipeline.PrependReactor("*", "runs", AddToInformer(t, i.Run.Informer().GetIndexer())) for _, run := range d.Runs { run := run.DeepCopy() // Avoid assumptions that the informer's copy is modified. @@ -354,7 +337,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 +345,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 +367,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 7742ebc973f..9f31948c32c 100644 --- a/test/conversion_test.go +++ b/test/conversion_test.go @@ -152,21 +152,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 ` 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}]}' - } spec: steps: - name: step @@ -303,18 +294,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: @@ -376,13 +361,6 @@ spec: type: string serviceAccountName: default taskSpec: - resources: - inputs: - - name: skaffold - type: git - outputs: - - name: skaffoldout - type: git steps: - name: echo image: ubuntu @@ -398,25 +376,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 = ` @@ -505,10 +464,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 @@ -549,14 +505,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: @@ -586,18 +534,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 = ` @@ -677,9 +613,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 017b268a237..d5443fc6972 100644 --- a/test/dag_test.go +++ b/test/dag_test.go @@ -63,13 +63,6 @@ metadata: name: %s namespace: %s spec: - resources: - inputs: - - name: repo - type: git - outputs: - - name: repo - type: git params: - name: text type: string @@ -81,27 +74,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(` @@ -109,82 +86,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)) @@ -198,11 +137,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 e9fdc2d3267..00000000000 --- a/test/embed_test.go +++ /dev/null @@ -1,114 +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/pipeline/v1beta1" - "github.com/tektoncd/pipeline/test/parse" - 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/hermetic_taskrun_test.go b/test/hermetic_taskrun_test.go index cd5a5c20045..f88ee7cf5a9 100644 --- a/test/hermetic_taskrun_test.go +++ b/test/hermetic_taskrun_test.go @@ -95,7 +95,7 @@ spec: steps: - image: gcr.io/cloud-builders/curl name: access-network - resources: {} + script: |- #!/bin/bash set -ex @@ -119,7 +119,7 @@ spec: steps: - image: gcr.io/cloud-builders/curl name: curl - resources: {} + script: |- #!/bin/bash set -ex diff --git a/test/init_test.go b/test/init_test.go index c63455729da..ea21a337fb0 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -219,15 +219,6 @@ func getCRDYaml(ctx context.Context, cs *clients, ns string) ([]byte, error) { printOrAdd(i) } - v1alpha1PipelineResources, err := cs.V1alpha1PipelineResourceClient.List(ctx, metav1.ListOptions{}) - if err != nil { - return nil, fmt.Errorf("could not get v1alpha1 pipelinerun resource: %w", err) - } - for _, i := range v1alpha1PipelineResources.Items { - i.SetManagedFields(nil) - printOrAdd(i) - } - v1beta1PipelineRuns, err := cs.V1beta1PipelineRunClient.List(ctx, metav1.ListOptions{}) if err != nil { return nil, fmt.Errorf("could not get v1beta1 pipelinerun: %w", err) diff --git a/test/larger_results_sidecar_logs_test.go b/test/larger_results_sidecar_logs_test.go index 9c9297e8b14..ef31475eaa4 100644 --- a/test/larger_results_sidecar_logs_test.go +++ b/test/larger_results_sidecar_logs_test.go @@ -107,7 +107,6 @@ func TestLargerResultsSidecarLogs(t *testing.T) { ignoreTaskRunStatus, ignoreContainerStates, ignoreStepState, - ignoreTaskRunSpec, ignoreTaskRunStatusFields, ignoreSidecarState, ) diff --git a/test/parse/yaml.go b/test/parse/yaml.go index c1eeed0fb99..13150c62e60 100644 --- a/test/parse/yaml.go +++ b/test/parse/yaml.go @@ -19,7 +19,6 @@ import ( v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "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" "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" "k8s.io/apimachinery/pkg/runtime" ) @@ -145,17 +144,6 @@ kind: Pipeline return &pipeline } -// MustParsePipelineResource takes YAML and parses it into a *resourcev1alpha1.PipelineResource -func MustParsePipelineResource(t *testing.T, yaml string) *resourcev1alpha1.PipelineResource { - t.Helper() - var resource resourcev1alpha1.PipelineResource - yaml = `apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -` + yaml - mustParseYAML(t, yaml, &resource) - return &resource -} - // MustParseVerificationPolicy takes YAML and parses it into a *v1alpha1.VerificationPolicy func MustParseVerificationPolicy(t *testing.T, yaml string) *v1alpha1.VerificationPolicy { t.Helper() diff --git a/test/pipelinerun_test.go b/test/pipelinerun_test.go index d12a3dc9b53..1d3646c7ef6 100644 --- a/test/pipelinerun_test.go +++ b/test/pipelinerun_test.go @@ -29,14 +29,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" @@ -53,15 +49,15 @@ func TestPipelineRunStatusSpec(t *testing.T) { t.Parallel() type tests struct { name string - testSetup func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) (map[string]*v1alpha1.PipelineResource, *v1beta1.Pipeline) + testSetup func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) *v1beta1.Pipeline expectedTaskRuns []string expectedNumberOfEvents int - pipelineRunFunc func(*testing.T, int, string, string, map[string]*v1alpha1.PipelineResource) *v1beta1.PipelineRun + pipelineRunFunc func(*testing.T, int, string, string) *v1beta1.PipelineRun } tds := []tests{{ name: "pipeline status spec updated", - testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, _ int) (map[string]*v1alpha1.PipelineResource, *v1beta1.Pipeline) { + testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, _ int) *v1beta1.Pipeline { t.Helper() task := parse.MustParseV1beta1Task(t, fmt.Sprintf(` metadata: @@ -86,7 +82,7 @@ spec: t.Fatalf("Failed to create Pipeline `%s`: %s", p.Name, err) } - return nil, p + return p }, expectedTaskRuns: []string{"task1"}, // 1 from PipelineRun; 0 from taskrun since it should not be executed due to condition failing @@ -108,9 +104,9 @@ spec: defer tearDown(ctx, t, c, namespace) t.Logf("Setting up test resources for %q test in namespace %s", td.name, namespace) - resources, p := td.testSetup(ctx, t, c, namespace, i) + p := td.testSetup(ctx, t, c, namespace, i) - pipelineRun := td.pipelineRunFunc(t, i, namespace, p.Name, resources) + pipelineRun := td.pipelineRunFunc(t, i, namespace, p.Name) prName := pipelineRun.Name _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}) if err != nil { @@ -179,44 +175,15 @@ func TestPipelineRun(t *testing.T) { t.Parallel() type tests struct { name string - testSetup func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) (map[string]*v1alpha1.PipelineResource, *v1beta1.Pipeline) + testSetup func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) *v1beta1.Pipeline expectedTaskRuns []string expectedNumberOfEvents int - pipelineRunFunc func(*testing.T, int, string, string, map[string]*v1alpha1.PipelineResource) *v1beta1.PipelineRun + pipelineRunFunc func(*testing.T, int, string, string) *v1beta1.PipelineRun } 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) { + testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) *v1beta1.Pipeline { t.Helper() t.Skip("build-crd-testing project got removed, the secret-sauce doesn't exist anymore, skipping") if _, err := c.KubeClient.CoreV1().Secrets(namespace).Create(ctx, getPipelineRunSecret(index, namespace), metav1.CreateOptions{}); err != nil { @@ -251,7 +218,7 @@ spec: t.Fatalf("Failed to create Pipeline `%s`: %s", p.Name, err) } - return nil, p + return p }, expectedTaskRuns: []string{task1Name}, // 1 from PipelineRun and 1 from Tasks defined in pipelinerun @@ -259,7 +226,7 @@ spec: pipelineRunFunc: getHelloWorldPipelineRun, }, { name: "pipelinerun succeeds with LimitRange minimum in namespace", - testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) (map[string]*v1alpha1.PipelineResource, *v1beta1.Pipeline) { + testSetup: func(ctx context.Context, t *testing.T, c *clients, namespace string, index int) *v1beta1.Pipeline { t.Helper() t.Skip("build-crd-testing project got removed, the secret-sauce doesn't exist anymore, skipping") if _, err := c.KubeClient.CoreV1().LimitRanges(namespace).Create(ctx, getLimitRange("prlimitrange", namespace, "100m", "99Mi", "100m"), metav1.CreateOptions{}); err != nil { @@ -299,7 +266,7 @@ spec: t.Fatalf("Failed to create Pipeline `%s`: %s", p.Name, err) } - return nil, p + return p }, expectedTaskRuns: []string{task1Name}, // 1 from PipelineRun and 1 from Tasks defined in pipelinerun @@ -321,9 +288,9 @@ spec: defer tearDown(ctx, t, c, namespace) t.Logf("Setting up test resources for %q test in namespace %s", td.name, namespace) - resources, p := td.testSetup(ctx, t, c, namespace, i) + p := td.testSetup(ctx, t, c, namespace, i) - pipelineRun := td.pipelineRunFunc(t, i, namespace, p.Name, resources) + pipelineRun := td.pipelineRunFunc(t, i, namespace, p.Name) prName := pipelineRun.Name _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}) if err != nil { @@ -382,22 +349,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 +555,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 +566,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: @@ -828,7 +596,7 @@ func getPipelineRunSecret(suffix int, namespace string) *corev1.Secret { } } -func getUpdatedStatusSpecPipelineRun(t *testing.T, _ int, namespace string, pipelineName string, _ map[string]*v1alpha1.PipelineResource) *v1beta1.PipelineRun { +func getUpdatedStatusSpecPipelineRun(t *testing.T, _ int, namespace string, pipelineName string) *v1beta1.PipelineRun { t.Helper() return parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` metadata: @@ -844,7 +612,7 @@ spec: // `, helpers.ObjectNameForTest(t), namespace, pipelineName)) } -func getHelloWorldPipelineRun(t *testing.T, suffix int, namespace string, pipelineName string, _ map[string]*v1alpha1.PipelineResource) *v1beta1.PipelineRun { +func getHelloWorldPipelineRun(t *testing.T, suffix int, namespace string, pipelineName string) *v1beta1.PipelineRun { t.Helper() return parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` metadata: diff --git a/test/propagated_params_test.go b/test/propagated_params_test.go index 227aaff6e8a..039399b8b7b 100644 --- a/test/propagated_params_test.go +++ b/test/propagated_params_test.go @@ -44,7 +44,6 @@ var ( ignoreConditions = cmpopts.IgnoreFields(duckv1.Status{}, "Conditions") ignoreContainerStates = cmpopts.IgnoreFields(corev1.ContainerState{}, "Terminated") ignoreStepState = cmpopts.IgnoreFields(v1beta1.StepState{}, "ImageID") - ignoreTaskRunSpec = cmpopts.IgnoreFields(v1beta1.TaskRunSpec{}, "Resources") ) func TestPropagatedParams(t *testing.T) { @@ -123,7 +122,6 @@ func TestPropagatedParams(t *testing.T) { ignoreConditions, ignoreContainerStates, ignoreStepState, - ignoreTaskRunSpec, ) if d != "" { t.Fatalf(`The expected taskrun does not match created taskrun. Here is the diff: %v`, d) @@ -209,7 +207,6 @@ metadata: spec: serviceAccountName: default timeout: 1h - resources: taskSpec: steps: - name: echo @@ -403,7 +400,6 @@ metadata: spec: serviceAccountName: default timeout: 1h - resources: taskSpec: params: - name: HELLO 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 ( From 58ba806c6769a0de60a747a213b13309050de93d Mon Sep 17 00:00:00 2001 From: Jerome Ju Date: Fri, 3 Mar 2023 17:34:21 +0000 Subject: [PATCH 2/2] replace fan-in-fan-out --- test/pipelinerun_test.go | 152 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/test/pipelinerun_test.go b/test/pipelinerun_test.go index 1d3646c7ef6..1e0741f4898 100644 --- a/test/pipelinerun_test.go +++ b/test/pipelinerun_test.go @@ -171,7 +171,8 @@ spec: } } -func TestPipelineRun(t *testing.T) { +// TODO +func TestPipelineRunaaa(t *testing.T) { t.Parallel() type tests struct { name string @@ -182,6 +183,28 @@ 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) *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) + } + } + + 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 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) *v1beta1.Pipeline { t.Helper() @@ -555,6 +578,133 @@ 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: + params: + - name: workspacepath-create + steps: + - args: ['-c', 'mkdir $(params.workspacepath-create)', + 'echo stuff > $(params.workspacepath-create)/stuff'] + command: ['/bin/bash'] + image: ubuntu + name: write-data-task-0-step-0 + - args: ['-c', 'mkdir $(params.workspacepath-create)', + 'echo other > $(params.workspacepath-create)/other'] + command: ['/bin/bash'] + image: ubuntu + name: write-data-task-0-step-1 + results: + - name: +`, helpers.ObjectNameForTest(t), namespace)), + "check-create-files-exists": parse.MustParseV1beta1Task(t, fmt.Sprintf(` +metadata: + name: %s + namespace: %s +spec: + params: + - name: workspacepath-check + steps: + - args: ['-c', '[[ stuff == $(cat $(params.workspacepath-check)/stuff) ]]'] + command: ['/bin/bash'] + image: ubuntu + name: read-from-task-0 + - args: ['-c', 'mkdir $(params.workspacepath-check)', + 'echo something > $(params.workspacepath-check)/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: + params: + - name: workspacepath-check + steps: + - args: ['-c', '[[ other == $(cat $(params.workspacepath-check)/other) ]]'] + command: ['/bin/bash'] + image: ubuntu + name: read-from-task-0 + - args: ['-c', 'echo else > $(params.workspacepath-check)/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: + params: + - name: workspacepath-read + steps: + - args: ['-c', '[[ something == $(cat $(params.workspacepath-read)/something) ]]'] + command: ['/bin/bash'] + image: ubuntu + name: read-from-task-0 + - args: ['-c', '[[ else == $(cat $(params.workspacepath-read)/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: + tasks: + - name: create-file-kritis + taskRef: + name: %s + params: + - name: workspacepath-create + value: brandnewspace + - name: create-fan-out-1 + taskRef: + name: %s + params: + - name: workspacepath-check + value: brandnewspace + - name: create-fan-out-2 + taskRef: + name: %s + params: + - name: workspacepath-check + value: brandnewspace + - name: check-fan-in + taskRef: + name: %s + params: + - name: workspacepath-read + value: readingspace +`, 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 getFanInFanOutPipelineRun(t *testing.T, _ int, namespace string, pipelineName string) *v1beta1.PipelineRun { + t.Helper() + return parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` +metadata: + name: %s + namespace: %s +spec: + pipelineRef: + name: %s +`, helpers.ObjectNameForTest(t), namespace, pipelineName)) +} + func getPipelineRunServiceAccount(suffix int, namespace string) *corev1.ServiceAccount { return &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{