diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 549c0483f4a..ab44517f99f 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -73,7 +73,6 @@ func main() { 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.ImageDigestExporterImage, "imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.") flag.StringVar(&opts.Images.WorkingDirInitImage, "workingdirinit-image", "", "The container image containing our working dir init binary.") // This parses flags. diff --git a/cmd/imagedigestexporter/digest.go b/cmd/imagedigestexporter/digest.go deleted file mode 100644 index 6e8ea6f232c..00000000000 --- a/cmd/imagedigestexporter/digest.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - v1 "github.com/google/go-containerregistry/pkg/v1" -) - -// GetDigest returns the digest of an OCI image index. If there is only one image in the index, the -// digest of the image is returned; otherwise, the digest of the whole index is returned. -func GetDigest(ii v1.ImageIndex) (v1.Hash, error) { - im, err := ii.IndexManifest() - if err != nil { - return v1.Hash{}, err - } - if len(im.Manifests) == 1 { - return im.Manifests[0].Digest, nil - } - return ii.Digest() -} diff --git a/cmd/imagedigestexporter/digest_test.go b/cmd/imagedigestexporter/digest_test.go deleted file mode 100644 index 44607e264b7..00000000000 --- a/cmd/imagedigestexporter/digest_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - v1 "github.com/google/go-containerregistry/pkg/v1" - "github.com/google/go-containerregistry/pkg/v1/empty" - "github.com/google/go-containerregistry/pkg/v1/random" -) - -func TestGetDigest(t *testing.T) { - mustGetIndex := func(ii v1.ImageIndex, err error) v1.ImageIndex { - if err != nil { - t.Fatalf("must get image: %s", err) - } - return ii - } - mustGetManifest := func(im *v1.IndexManifest, err error) *v1.IndexManifest { - if err != nil { - t.Fatalf("must get manifest: %s", err) - } - return im - } - mustGetDigest := func(h v1.Hash, err error) v1.Hash { - if err != nil { - t.Fatalf("must get digest: %s", err) - } - return h - } - indexSingleImage := mustGetIndex(random.Index(1024, 4, 1)) - indexMultipleImages := mustGetIndex(random.Index(1024, 4, 4)) - tests := []struct { - name string - index v1.ImageIndex - expected v1.Hash - }{ - { - name: "empty index", - index: empty.Index, - expected: mustGetDigest(empty.Index.Digest()), - }, - { - name: "index with single image", - index: indexSingleImage, - expected: mustGetManifest(indexSingleImage.IndexManifest()).Manifests[0].Digest, - }, - { - name: "index with multiple images", - index: indexMultipleImages, - expected: mustGetDigest(indexMultipleImages.Digest()), - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - digest, err := GetDigest(test.index) - if err != nil { - t.Fatalf("cannot get digest: %s", err) - } - if diff := cmp.Diff(digest, test.expected); diff != "" { - t.Errorf("get digest: -want +got: %s", diff) - } - }) - } -} diff --git a/cmd/imagedigestexporter/kodata/LICENSE b/cmd/imagedigestexporter/kodata/LICENSE deleted file mode 120000 index 5853aaea53b..00000000000 --- a/cmd/imagedigestexporter/kodata/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../../../LICENSE \ No newline at end of file diff --git a/cmd/imagedigestexporter/kodata/third_party b/cmd/imagedigestexporter/kodata/third_party deleted file mode 120000 index 6bfa480c09a..00000000000 --- a/cmd/imagedigestexporter/kodata/third_party +++ /dev/null @@ -1 +0,0 @@ -../../../third_party \ No newline at end of file diff --git a/cmd/imagedigestexporter/main.go b/cmd/imagedigestexporter/main.go deleted file mode 100644 index 6a24780b6c3..00000000000 --- a/cmd/imagedigestexporter/main.go +++ /dev/null @@ -1,83 +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 main - -import ( - "encoding/json" - "flag" - - "github.com/tektoncd/pipeline/pkg/termination" - "knative.dev/pkg/logging" - - "github.com/google/go-containerregistry/pkg/v1/layout" - v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" -) - -var ( - images = flag.String("images", "", "List of images resources built by task in json format") - terminationMessagePath = flag.String("terminationMessagePath", "/tekton/termination", "Location of file containing termination message") -) - -/* - The input of this go program will be a JSON string with all the output PipelineResources of type - -Image, which will include the path to where the index.json file will be located. The program will -read the related index.json file(s) and log another JSON string including the name of the image resource -and the digests. -The input is an array of ImageResource, ex: [{"name":"srcimg1","type":"image","url":"gcr.io/some-image-1","digest":""}] -The output is an array of PipelineResourceResult, ex: [{"name":"image","digest":"sha256:eed29..660"}] -*/ -func main() { - flag.Parse() - logger, _ := logging.NewLogger("", "image-digest-exporter") - defer func() { - _ = logger.Sync() - }() - - imageResources := []*image.Resource{} - if err := json.Unmarshal([]byte(*images), &imageResources); err != nil { - logger.Fatalf("Error reading images array: %v", err) - } - - output := []v1beta1.PipelineResourceResult{} - for _, imageResource := range imageResources { - ii, err := layout.ImageIndexFromPath(imageResource.OutputImageDir) - if err != nil { - logger.Infof("No index.json found for: %s", imageResource.Name) - continue - } - digest, err := GetDigest(ii) - if err != nil { - logger.Fatalf("Unexpected error getting image digest for %s: %v", imageResource.Name, err) - } - output = append(output, v1beta1.PipelineResourceResult{ - Key: "digest", - Value: digest.String(), - ResourceName: imageResource.Name, - }) - output = append(output, v1beta1.PipelineResourceResult{ - Key: "url", - Value: imageResource.URL, - ResourceName: imageResource.Name, - }) - } - - if err := termination.WriteMessage(*terminationMessagePath, output); err != nil { - logger.Fatalf("Unexpected error writing message %s to %s", *terminationMessagePath, err) - } -} diff --git a/config/controller.yaml b/config/controller.yaml index f32860b55b4..2cada57d46f 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -69,7 +69,6 @@ spec: "-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", - "-imagedigest-exporter-image", "ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter", "-workingdirinit-image", "ko://github.com/tektoncd/pipeline/cmd/workingdirinit", # This is gcr.io/google.com/cloudsdktool/cloud-sdk:302.0.0-slim diff --git a/examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml b/examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml deleted file mode 100644 index 469060123ec..00000000000 --- a/examples/v1beta1/taskruns/optional-resources-with-clustertask.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Note: ClusterTasks are deprecated. Please use the cluster resolver instead. -# https://github.com/tektoncd/pipeline/blob/main/docs/cluster-resolver.md -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -metadata: - name: clustertask-with-optional-resources-v1beta1 -spec: - params: - - name: filename - type: string - default: "README.md" - resources: - inputs: - - name: git-repo - type: git - optional: true - outputs: - - name: optionalimage - type: image - optional: true - steps: - - name: task-echo-success - image: ubuntu - script: | - #!/usr/bin/env bash - echo "success" ---- - -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: clustertask-without-resources -spec: - taskRef: - name: clustertask-with-optional-resources-v1beta1 - kind: ClusterTask diff --git a/examples/v1beta1/taskruns/optional-resources.yaml b/examples/v1beta1/taskruns/optional-resources.yaml deleted file mode 100644 index a5a055eb20a..00000000000 --- a/examples/v1beta1/taskruns/optional-resources.yaml +++ /dev/null @@ -1,133 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: task-check-optional-resources -spec: - params: - - name: filename - type: string - default: "README.md" - resources: - inputs: - - name: git-repo - type: git - description: "The input is code from a git repository" - optional: true - outputs: - - name: optionalimage - type: image - description: "The output is a Docker image" - optional: true - steps: - - name: check-git-repo - image: ubuntu - script: | - #!/usr/bin/env bash - if [ -d $(resources.inputs.git-repo.path) ]; then - echo "Git repo was cloned at $(resources.inputs.git-repo.path)" - if [ -f $(resources.inputs.git-repo.path)/$(inputs.params.filename) ]; then - echo "$(inputs.params.filename) does exist at $(resources.inputs.git-repo.path)" - else - echo "$(inputs.params.filename) does not exist at $(resources.inputs.git-repo.path)" - fi - else - echo "Git repo was not cloned at $(resources.inputs.git-repo.path)" - fi - if [ "$(outputs.resources.optionalimage.url)" != "" ]; then - echo "Image URL: $(outputs.resources.optionalimage.url)" - else - echo "No image URL specified." - fi - echo "Yay, Input and Output Resources can be Optional!" ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-with-resources -spec: - params: - - name: filename - value: "README.md" - resources: - inputs: - - name: git-repo - resourceSpec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline.git - outputs: - - name: optionalimage - resourceSpec: - type: image - params: - - name: url - value: gcr.io/foo/bar - taskRef: - name: task-check-optional-resources ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-invalid-filename -spec: - params: - - name: filename - value: "invalid.md" - resources: - inputs: - - name: git-repo - resourceSpec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline.git - taskRef: - name: task-check-optional-resources ---- - -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-without-resources -spec: - params: - - name: filename - value: "README.md" - taskRef: - name: task-check-optional-resources ---- - -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-inputs-resources-without-resources-and-params -spec: - taskRef: - name: task-check-optional-resources ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: demo-optional-outputs-resources-with-input-resources -spec: - params: - - name: filename - value: "README.md" - resources: - inputs: - - name: git-repo - resourceSpec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline.git - taskRef: - name: task-check-optional-resources ---- diff --git a/examples/v1beta1/taskruns/task-multiple-output-image.yaml b/examples/v1beta1/taskruns/task-multiple-output-image.yaml deleted file mode 100644 index 2ba605ad9c1..00000000000 --- a/examples/v1beta1/taskruns/task-multiple-output-image.yaml +++ /dev/null @@ -1,124 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-image-leeroy-web-1 -spec: - type: image - params: - - name: url - value: gcr.io/dlorenc-vmtest2/leeroy-web # Replace this URL with $KO_DOCKER_REPO ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-image-leeroy-web-2 -spec: - type: image - params: - - name: url - value: gcr.io/christiewilson-catfactory/leeroy-web # Replace this URL with $KO_DOCKER_REPO ---- -# This demo modifies the cluster (deploys to it) you must use a service -# account with permission to admin the cluster (or make your default user an admin -# of the `default` namespace with default-cluster-admin). -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - generateName: default-cluster-admin- -subjects: - - kind: ServiceAccount - name: default - namespace: default -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: rbac.authorization.k8s.io ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-git-multiple-output-image -spec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# This task is currently hardcoding a index.json file instead of -# building an image since kaniko and other easy to use tools don't -# support exporting this file yet -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: multiple-build-push-kaniko -spec: - resources: - inputs: - - name: sourcerepo - type: git - outputs: - - name: builtImage1 - type: image - - name: builtImage2 - type: image - steps: - - name: build-and-push-1 - image: busybox - script: | - set -ex - mkdir -p /tekton/home/image-outputs/builtImage1 - cat < /tekton/home/image-outputs/builtImage1/index.json - { - "schemaVersion": 2, - "manifests": [ - { - "mediaType": "application/vnd.oci.image.index.v1+json", - "size": 314, - "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5" - } - ] - } - - name: build-and-push-2 - image: busybox - script: | - set -e - mkdir -p /tekton/home/image-outputs/builtImage2 - cat < /tekton/home/image-outputs/builtImage2/index.json - { - "schemaVersion": 2, - "manifests": [ - { - "mediaType": "application/vnd.oci.image.index.v1+json", - "size": 314, - "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5" - } - ] - } ---- -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: multiple-build-push-kaniko-run -spec: - taskRef: - name: multiple-build-push-kaniko - resources: - inputs: - - name: sourcerepo - resourceRef: - name: skaffold-git-multiple-output-image - outputs: - - name: builtImage1 - resourceRef: - name: skaffold-image-leeroy-web-1 - - name: builtImage2 - resourceRef: - name: skaffold-image-leeroy-web-2 diff --git a/examples/v1beta1/taskruns/task-output-image.yaml b/examples/v1beta1/taskruns/task-output-image.yaml deleted file mode 100644 index ad5407acfbe..00000000000 --- a/examples/v1beta1/taskruns/task-output-image.yaml +++ /dev/null @@ -1,97 +0,0 @@ -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-image-leeroy-web-output-image -spec: - type: image - params: - - name: url - value: gcr.io/christiewilson-catfactory/leeroy-web # Replace this URL with $KO_DOCKER_REPO ---- -# This demo modifies the cluster (deploys to it) you must use a service -# account with permission to admin the cluster (or make your default user an admin -# of the `default` namespace with default-cluster-admin). -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - generateName: default-cluster-admin- -subjects: - - kind: ServiceAccount - name: default - namespace: default -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: rbac.authorization.k8s.io ---- -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1alpha1 -kind: PipelineResource -metadata: - name: skaffold-git-output-image -spec: - type: git - params: - - name: revision - value: v0.32.0 - - name: url - value: https://github.com/GoogleContainerTools/skaffold ---- -# This task is currently hardcoding a index.json file instead of -# building an image since kaniko and other easy to use tools don't -# support exporting this file yet -# -# `PipelineResources` are deprecated, consider using `Tasks` and other replacement features instead -# https://github.com/tektoncd/pipeline/blob/main/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks -apiVersion: tekton.dev/v1beta1 -kind: Task -metadata: - name: build-push-kaniko-output-image -spec: - resources: - inputs: - - name: sourcerepo - type: git - outputs: - - name: builtImage - type: image - targetPath: /workspace/sourcerepo - steps: - - name: build-and-push - image: busybox - script: | - set -e - cat < $(resources.inputs.sourcerepo.path)/index.json - { - "schemaVersion": 2, - "manifests": [ - { - "mediaType": "application/vnd.oci.image.index.v1+json", - "size": 314, - "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5" - } - ] - } - - name: echo - image: busybox - script: cat $(resources.inputs.sourcerepo.path)/index.json ---- -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: build-push-run-output-image -spec: - taskRef: - name: build-push-kaniko-output-image - resources: - inputs: - - name: sourcerepo - resourceRef: - name: skaffold-git-output-image - outputs: - - name: builtImage - resourceRef: - name: skaffold-image-leeroy-web-output-image diff --git a/pkg/apis/pipeline/images.go b/pkg/apis/pipeline/images.go index f489e9441a8..0e904183ba5 100644 --- a/pkg/apis/pipeline/images.go +++ b/pkg/apis/pipeline/images.go @@ -38,8 +38,6 @@ type Images struct { ShellImageWin string // GsutilImage is the container image containing gsutil. GsutilImage string - // ImageDigestExporterImage is the container image containing our image digest exporter binary. - ImageDigestExporterImage string // WorkingDirInitImage is the container image containing our working dir init binary. WorkingDirInitImage string @@ -59,7 +57,6 @@ func (i Images) Validate() error { {i.ShellImage, "shell-image"}, {i.ShellImageWin, "shell-image-win"}, {i.GsutilImage, "gsutil-image"}, - {i.ImageDigestExporterImage, "imagedigest-exporter-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 2cff4555ec2..109c95528e1 100644 --- a/pkg/apis/pipeline/images_test.go +++ b/pkg/apis/pipeline/images_test.go @@ -8,29 +8,27 @@ import ( func TestValidate(t *testing.T) { valid := pipeline.Images{ - EntrypointImage: "set", - SidecarLogResultsImage: "set", - NopImage: "set", - GitImage: "set", - ShellImage: "set", - ShellImageWin: "set", - GsutilImage: "set", - ImageDigestExporterImage: "set", - WorkingDirInitImage: "set", + EntrypointImage: "set", + SidecarLogResultsImage: "set", + NopImage: "set", + GitImage: "set", + ShellImage: "set", + ShellImageWin: "set", + GsutilImage: "set", + WorkingDirInitImage: "set", } if err := valid.Validate(); err != nil { t.Errorf("valid Images returned error: %v", err) } invalid := pipeline.Images{ - EntrypointImage: "set", - SidecarLogResultsImage: "set", - NopImage: "set", - GitImage: "", // unset! - ShellImage: "", // unset! - ShellImageWin: "set", - GsutilImage: "set", - ImageDigestExporterImage: "set", + 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]" if err := invalid.Validate(); err == nil { diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go index 43b751bdd6e..63cadb6bbb1 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go @@ -662,7 +662,7 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { Resources: []PipelineDeclaredResource{{ Name: "great-resource", Type: PipelineResourceTypeGit, }, { - Name: "wonderful-resource", Type: PipelineResourceTypeImage, + Name: "wonderful-resource", Type: PipelineResourceTypeGit, }}, Tasks: []PipelineTask{{ Name: "bar", @@ -955,7 +955,7 @@ func TestValidateDeclaredResources_Success(t *testing.T) { resources: []PipelineDeclaredResource{{ Name: "great-resource", Type: PipelineResourceTypeGit, }, { - Name: "wonderful-resource", Type: PipelineResourceTypeImage, + Name: "wonderful-resource", Type: PipelineResourceTypeGit, }}, tasks: []PipelineTask{{ Name: "bar", @@ -965,7 +965,7 @@ func TestValidateDeclaredResources_Success(t *testing.T) { Name: "some-workspace", Resource: "great-resource", }}, Outputs: []PipelineTaskOutputResource{{ - Name: "some-imagee", Resource: "wonderful-resource", + Name: "some-workspace", Resource: "wonderful-resource", }}, }, }, { @@ -982,11 +982,11 @@ func TestValidateDeclaredResources_Success(t *testing.T) { resources: []PipelineDeclaredResource{{ Name: "great-resource", Type: PipelineResourceTypeGit, }, { - Name: "awesome-resource", Type: PipelineResourceTypeImage, + Name: "awesome-resource", Type: PipelineResourceTypeGit, }, { Name: "yet-another-great-resource", Type: PipelineResourceTypeGit, }, { - Name: "yet-another-awesome-resource", Type: PipelineResourceTypeImage, + Name: "yet-another-awesome-resource", Type: PipelineResourceTypeGit, }}, tasks: []PipelineTask{{ Name: "foo", @@ -2380,7 +2380,7 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { Resources: []PipelineDeclaredResource{{ Name: "great-resource", Type: PipelineResourceTypeGit, }, { - Name: "wonderful-resource", Type: PipelineResourceTypeImage, + Name: "wonderful-resource", Type: PipelineResourceTypeGit, }}, Tasks: []PipelineTask{{ Name: "non-final-task", diff --git a/pkg/apis/pipeline/v1beta1/resource_types.go b/pkg/apis/pipeline/v1beta1/resource_types.go index 41ad57bd345..2658793ab23 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types.go +++ b/pkg/apis/pipeline/v1beta1/resource_types.go @@ -42,9 +42,6 @@ const ( // PipelineResourceTypeStorage indicates that this source is a storage blob resource. PipelineResourceTypeStorage PipelineResourceType = resource.PipelineResourceTypeStorage - - // PipelineResourceTypeImage indicates that this source is a docker Image. - PipelineResourceTypeImage PipelineResourceType = resource.PipelineResourceTypeImage ) // AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types. diff --git a/pkg/apis/resource/resource.go b/pkg/apis/resource/resource.go index d9038dd29f7..91fbb0cf93b 100644 --- a/pkg/apis/resource/resource.go +++ b/pkg/apis/resource/resource.go @@ -23,7 +23,6 @@ import ( pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/git" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" ) @@ -34,8 +33,6 @@ func FromType(name string, r *resourcev1alpha1.PipelineResource, images pipeline switch r.Spec.Type { case resourcev1alpha1.PipelineResourceTypeGit: return git.NewResource(name, images.GitImage, r) - case resourcev1alpha1.PipelineResourceTypeImage: - return image.NewResource(name, r) case resourcev1alpha1.PipelineResourceTypeStorage: return storage.NewResource(name, images, r) } diff --git a/pkg/apis/resource/v1alpha1/image/image_resource.go b/pkg/apis/resource/v1alpha1/image/image_resource.go deleted file mode 100644 index 028edfb2b3e..00000000000 --- a/pkg/apis/resource/v1alpha1/image/image_resource.go +++ /dev/null @@ -1,95 +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 image - -import ( - "encoding/json" - "fmt" - "strings" - - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" -) - -// Resource defines an endpoint where artifacts can be stored, such as images. -type Resource struct { - Name string `json:"name"` - Type resourcev1alpha1.PipelineResourceType `json:"type"` - URL string `json:"url"` - Digest string `json:"digest"` - OutputImageDir string -} - -// NewResource creates a new ImageResource from a PipelineResourcev1alpha1. -func NewResource(name string, r *resourcev1alpha1.PipelineResource) (*Resource, error) { - if r.Spec.Type != resourcev1alpha1.PipelineResourceTypeImage { - return nil, fmt.Errorf("ImageResource: Cannot create an Image resource from a %s Pipeline Resource", r.Spec.Type) - } - ir := &Resource{ - Name: name, - Type: resourcev1alpha1.PipelineResourceTypeImage, - } - - for _, param := range r.Spec.Params { - switch { - case strings.EqualFold(param.Name, "URL"): - ir.URL = param.Value - case strings.EqualFold(param.Name, "Digest"): - ir.Digest = param.Value - } - } - - return ir, nil -} - -// 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 "image" -func (s Resource) GetType() resourcev1alpha1.PipelineResourceType { - return resourcev1alpha1.PipelineResourceTypeImage -} - -// Replacements is used for template replacement on an ImageResource inside of a Taskrun. -func (s *Resource) Replacements() map[string]string { - return map[string]string{ - "name": s.Name, - "type": s.Type, - "url": s.URL, - "digest": s.Digest, - } -} - -// GetInputTaskModifier returns the TaskModifier to be used when this resource is an input. -func (s *Resource) GetInputTaskModifier(_ *pipelinev1beta1.TaskSpec, _ string) (pipelinev1beta1.TaskModifier, error) { - return &pipelinev1beta1.InternalTaskModifier{}, nil -} - -// GetOutputTaskModifier returns a No-op TaskModifier. -func (s *Resource) GetOutputTaskModifier(_ *pipelinev1beta1.TaskSpec, _ string) (pipelinev1beta1.TaskModifier, error) { - return &pipelinev1beta1.InternalTaskModifier{}, nil -} - -func (s Resource) String() string { - // the String() func implements the Stringer interface, and therefore - // cannot return an error - // if the Marshal func gives an error, the returned string will be empty - json, _ := json.Marshal(s) - return string(json) -} diff --git a/pkg/apis/resource/v1alpha1/image/image_resource_test.go b/pkg/apis/resource/v1alpha1/image/image_resource_test.go deleted file mode 100644 index 0f1f633576e..00000000000 --- a/pkg/apis/resource/v1alpha1/image/image_resource_test.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 image_test - -import ( - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/google/go-cmp/cmp" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" - "github.com/tektoncd/pipeline/test/diff" -) - -func TestNewImageResource_Invalid(t *testing.T) { - r := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-resource", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - }, - } - - _, err := image.NewResource("test-resource", r) - if err == nil { - t.Error("Expected error creating Image resource") - } -} - -func TestNewImageResource_Valid(t *testing.T) { - want := &image.Resource{ - Name: "image-resource", - Type: v1alpha1.PipelineResourceTypeImage, - URL: "https://test.com/test/test", - Digest: "test", - } - - r := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "image-resource", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Params: []v1alpha1.ResourceParam{ - { - Name: "URL", - Value: "https://test.com/test/test", - }, - { - Name: "Digest", - Value: "test", - }, - }, - }, - } - - got, err := image.NewResource("image-resource", r) - if err != nil { - t.Fatalf("Unexpected error creating Image resource: %s", err) - } - - if d := cmp.Diff(want, got); d != "" { - t.Errorf("Mismatch of Image resource: %s", diff.PrintWantGot(d)) - } -} - -func TestImageResource_Replacements(t *testing.T) { - ir := &image.Resource{ - Name: "image-resource", - Type: v1alpha1.PipelineResourceTypeImage, - URL: "https://test.com/test/test", - Digest: "test", - } - - want := map[string]string{ - "name": "image-resource", - "type": v1alpha1.PipelineResourceTypeImage, - "url": "https://test.com/test/test", - "digest": "test", - } - - got := ir.Replacements() - - if d := cmp.Diff(want, got); d != "" { - t.Errorf("Mismatch of ImageResource Replacements %s", diff.PrintWantGot(d)) - } -} diff --git a/pkg/apis/resource/v1alpha1/pipeline_resource_types.go b/pkg/apis/resource/v1alpha1/pipeline_resource_types.go index e588feb9184..abf5ac4005f 100644 --- a/pkg/apis/resource/v1alpha1/pipeline_resource_types.go +++ b/pkg/apis/resource/v1alpha1/pipeline_resource_types.go @@ -40,15 +40,12 @@ const ( // PipelineResourceTypeStorage indicates that this source is a storage blob resource. PipelineResourceTypeStorage PipelineResourceType = "storage" - // PipelineResourceTypeImage indicates that this source is a docker Image. - PipelineResourceTypeImage PipelineResourceType = "image" - // PipelineResourceTypeGCS is the subtype for the GCSResources, which is backed by a GCS blob/directory. PipelineResourceTypeGCS PipelineResourceType = "gcs" ) // AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types. -var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypeImage} +var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage} // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/resource/v1alpha1/storage/gcs_test.go b/pkg/apis/resource/v1alpha1/storage/gcs_test.go index 289b5b9a075..0d15ccbca95 100644 --- a/pkg/apis/resource/v1alpha1/storage/gcs_test.go +++ b/pkg/apis/resource/v1alpha1/storage/gcs_test.go @@ -32,12 +32,11 @@ import ( ) var images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + 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) { diff --git a/pkg/artifacts/artifact_storage_test.go b/pkg/artifacts/artifact_storage_test.go index 238423747c2..d352474a299 100644 --- a/pkg/artifacts/artifact_storage_test.go +++ b/pkg/artifacts/artifact_storage_test.go @@ -38,12 +38,11 @@ import ( var ( images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + 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{ diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index f6b77e8eb59..1f347e7f840 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -73,12 +73,11 @@ import ( var ( images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + 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") diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index 9f335a18761..8c458840241 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -1880,16 +1880,6 @@ func TestGetResourcesFromBindings(t *testing.T) { }, Resources: []v1beta1.PipelineResourceBinding{ gitSweetResourceBinding, - { - Name: "image-resource", - ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, - Params: []v1beta1.ResourceParam{{ - Name: "url", - Value: "gcr.io/sven", - }}, - }, - }, }, }, } @@ -1911,16 +1901,6 @@ func TestGetResourcesFromBindings(t *testing.T) { } else if d := cmp.Diff(r, r1); d != "" { t.Errorf("Expected resources didn't match actual %s", diff.PrintWantGot(d)) } - - r2, ok := m["image-resource"] - if !ok { - t.Errorf("Missing expected resource image-resource: %v", m) - } else if r2.Spec.Type != resourcev1alpha1.PipelineResourceTypeImage || - len(r2.Spec.Params) != 1 || - r2.Spec.Params[0].Name != "url" || - r2.Spec.Params[0].Value != "gcr.io/sven" { - t.Errorf("Did not get expected image resource, got %v", r2.Spec) - } } func TestGetResourcesFromBindings_Missing(t *testing.T) { @@ -2520,10 +2500,6 @@ func TestValidateResourceBindings_Missing(t *testing.T) { Spec: v1beta1.PipelineSpec{ Resources: []v1beta1.PipelineDeclaredResource{ gitDeclaredResource, - { - Name: "image-resource", - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, }, }, } @@ -2531,12 +2507,12 @@ func TestValidateResourceBindings_Missing(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, Spec: v1beta1.PipelineRunSpec{ PipelineRef: &v1beta1.PipelineRef{Name: "pipeline"}, - Resources: []v1beta1.PipelineResourceBinding{gitSweetResourceBinding}, + Resources: []v1beta1.PipelineResourceBinding{}, }, } err := ValidateResourceBindings(&p.Spec, pr) if err == nil { - t.Fatalf("Expected error indicating `image-resource` was missing but got no error") + t.Fatalf("Expected error indicating `git-resource` was missing but got no error") } } diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index 01310f87a9d..0041912e215 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -38,12 +38,11 @@ import ( var ( images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + 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{ @@ -70,10 +69,6 @@ var ( Image: "bat", WorkingDir: "$(inputs.resources.workspace.path)", Args: []string{"$(inputs.resources.workspace.url)"}, - }, { - Name: "qux", - Image: "$(params.something)", - Args: []string{"$(outputs.resources.imageToUse.url)"}, }, { Name: "foo", Image: `$(params["myimage"])`, @@ -82,10 +77,6 @@ var ( Image: "$(params.somethingelse)", WorkingDir: "$(inputs.resources.workspace.path)", Args: []string{"$(inputs.resources.workspace.url)"}, - }, { - Name: "qux", - Image: "quux", - Args: []string{"$(outputs.resources.imageToUse.url)"}, }, { Name: "foo", Image: "busybox:$(params.FOO)", @@ -128,12 +119,6 @@ var ( LocalObjectReference: corev1.LocalObjectReference{Name: "secret-$(params.FOO)"}, }, }}, - }, { - Name: "outputs-resources-path-ab", - Image: "$(outputs.resources.imageToUse-ab.path)", - }, { - Name: "outputs-resources-path-re", - Image: "$(outputs.resources.imageToUse-re.path)", }}, Volumes: []corev1.Volume{{ Name: "$(params.FOO)", @@ -206,17 +191,6 @@ var ( Name: "workspace", }, }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "imageToUse-ab", - TargetPath: "/foo/builtImage", - }, - }, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "imageToUse-re", - TargetPath: "foo/builtImage", - }, - }}, }, } @@ -366,10 +340,6 @@ var ( Image: "bat", WorkingDir: "$(inputs.resources.workspace.path)", Args: []string{"$(inputs.resources.workspace.url)"}, - }, { - Name: "qux", - Image: "$(params.something[0])", - Args: []string{"$(outputs.resources.imageToUse.url)"}, }, { Name: "foo", Image: `$(params["myimage"][0])`, @@ -378,10 +348,6 @@ var ( Image: "$(params.somethingelse)", WorkingDir: "$(inputs.resources.workspace.path)", Args: []string{"$(inputs.resources.workspace.url)"}, - }, { - Name: "qux", - Image: "quux", - Args: []string{"$(outputs.resources.imageToUse.url)"}, }, { Name: "foo", Image: "busybox:$(params.FOO[1])", @@ -424,12 +390,6 @@ var ( LocalObjectReference: corev1.LocalObjectReference{Name: "secret-$(params.FOO[1])"}, }, }}, - }, { - Name: "outputs-resources-path-ab", - Image: "$(outputs.resources.imageToUse-ab.path)", - }, { - Name: "outputs-resources-path-re", - Image: "$(outputs.resources.imageToUse-re.path)", }}, Volumes: []corev1.Volume{{ Name: "$(params.FOO[1])", @@ -502,17 +462,6 @@ var ( Name: "workspace", }, }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "imageToUse-ab", - TargetPath: "/foo/builtImage", - }, - }, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "imageToUse-re", - TargetPath: "foo/builtImage", - }, - }}, }, } @@ -713,8 +662,7 @@ var ( } outputs = map[string]v1beta1.PipelineResourceInterface{ - "imageToUse": imageResource, - "bucket": gcsResource, + "bucket": gcsResource, } gitResource, _ = resource.FromType("git-resource", &resourcev1alpha1.PipelineResource{ @@ -730,19 +678,6 @@ var ( }, }, images) - imageResource, _ = resource.FromType("image-resource", &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "image-resource", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "gcr.io/hans/sandwiches", - }}, - }, - }, images) - gcsResource, _ = resource.FromType("gcs-resource", &resourcev1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ Name: "gcs-resource", @@ -902,26 +837,24 @@ func TestApplyParameters(t *testing.T) { spec.Steps[0].Image = "bar" spec.Steps[2].Image = "mydefault" - spec.Steps[3].Image = "bar" - spec.Steps[4].Image = "" + spec.Steps[2].Image = "bar" + spec.Steps[3].Image = "" - spec.Steps[6].VolumeMounts[0].Name = "world" - spec.Steps[6].VolumeMounts[0].SubPath = "sub/world/path" - spec.Steps[6].VolumeMounts[0].MountPath = "path/to/world" - spec.Steps[6].Image = "busybox:world" + spec.Steps[4].VolumeMounts[0].Name = "world" + spec.Steps[4].VolumeMounts[0].SubPath = "sub/world/path" + spec.Steps[4].VolumeMounts[0].MountPath = "path/to/world" + spec.Steps[4].Image = "busybox:world" - spec.Steps[7].Env[0].Value = "value-world" - spec.Steps[7].Env[1].ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name = "config-world" - spec.Steps[7].Env[1].ValueFrom.ConfigMapKeyRef.Key = "config-key-world" - spec.Steps[7].Env[2].ValueFrom.SecretKeyRef.LocalObjectReference.Name = "secret-world" - spec.Steps[7].Env[2].ValueFrom.SecretKeyRef.Key = "secret-key-world" - spec.Steps[7].EnvFrom[0].Prefix = "prefix-0-world" - spec.Steps[7].EnvFrom[0].ConfigMapRef.LocalObjectReference.Name = "config-world" - spec.Steps[7].EnvFrom[1].Prefix = "prefix-1-world" - spec.Steps[7].EnvFrom[1].SecretRef.LocalObjectReference.Name = "secret-world" - spec.Steps[7].Image = "busybox:world" - spec.Steps[8].Image = "$(outputs.resources.imageToUse-ab.path)" - spec.Steps[9].Image = "$(outputs.resources.imageToUse-re.path)" + spec.Steps[5].Env[0].Value = "value-world" + spec.Steps[5].Env[1].ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name = "config-world" + spec.Steps[5].Env[1].ValueFrom.ConfigMapKeyRef.Key = "config-key-world" + spec.Steps[5].Env[2].ValueFrom.SecretKeyRef.LocalObjectReference.Name = "secret-world" + spec.Steps[5].Env[2].ValueFrom.SecretKeyRef.Key = "secret-key-world" + spec.Steps[5].EnvFrom[0].Prefix = "prefix-0-world" + spec.Steps[5].EnvFrom[0].ConfigMapRef.LocalObjectReference.Name = "config-world" + spec.Steps[5].EnvFrom[1].Prefix = "prefix-1-world" + spec.Steps[5].EnvFrom[1].SecretRef.LocalObjectReference.Name = "secret-world" + spec.Steps[5].Image = "busybox:world" spec.Volumes[0].Name = "world" spec.Volumes[0].VolumeSource.ConfigMap.LocalObjectReference.Name = "world" @@ -970,27 +903,24 @@ func TestApplyParameters_ArrayIndexing(t *testing.T) { spec.StepTemplate.Image = "bar" spec.Steps[0].Image = "bar" - spec.Steps[2].Image = "mydefault" - spec.Steps[3].Image = "bar" - spec.Steps[4].Image = "" + spec.Steps[2].Image = "bar" + spec.Steps[3].Image = "" - spec.Steps[6].VolumeMounts[0].Name = "world" - spec.Steps[6].VolumeMounts[0].SubPath = "sub/world/path" - spec.Steps[6].VolumeMounts[0].MountPath = "path/to/world" - spec.Steps[6].Image = "busybox:world" + spec.Steps[4].VolumeMounts[0].Name = "world" + spec.Steps[4].VolumeMounts[0].SubPath = "sub/world/path" + spec.Steps[4].VolumeMounts[0].MountPath = "path/to/world" + spec.Steps[4].Image = "busybox:world" - spec.Steps[7].Env[0].Value = "value-world" - spec.Steps[7].Env[1].ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name = "config-world" - spec.Steps[7].Env[1].ValueFrom.ConfigMapKeyRef.Key = "config-key-world" - spec.Steps[7].Env[2].ValueFrom.SecretKeyRef.LocalObjectReference.Name = "secret-world" - spec.Steps[7].Env[2].ValueFrom.SecretKeyRef.Key = "secret-key-world" - spec.Steps[7].EnvFrom[0].Prefix = "prefix-0-world" - spec.Steps[7].EnvFrom[0].ConfigMapRef.LocalObjectReference.Name = "config-world" - spec.Steps[7].EnvFrom[1].Prefix = "prefix-1-world" - spec.Steps[7].EnvFrom[1].SecretRef.LocalObjectReference.Name = "secret-world" - spec.Steps[7].Image = "busybox:world" - spec.Steps[8].Image = "$(outputs.resources.imageToUse-ab.path)" - spec.Steps[9].Image = "$(outputs.resources.imageToUse-re.path)" + spec.Steps[5].Env[0].Value = "value-world" + spec.Steps[5].Env[1].ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name = "config-world" + spec.Steps[5].Env[1].ValueFrom.ConfigMapKeyRef.Key = "config-key-world" + spec.Steps[5].Env[2].ValueFrom.SecretKeyRef.LocalObjectReference.Name = "secret-world" + spec.Steps[5].Env[2].ValueFrom.SecretKeyRef.Key = "secret-key-world" + spec.Steps[5].EnvFrom[0].Prefix = "prefix-0-world" + spec.Steps[5].EnvFrom[0].ConfigMapRef.LocalObjectReference.Name = "config-world" + spec.Steps[5].EnvFrom[1].Prefix = "prefix-1-world" + spec.Steps[5].EnvFrom[1].SecretRef.LocalObjectReference.Name = "secret-world" + spec.Steps[5].Image = "busybox:world" spec.Volumes[0].Name = "world" spec.Volumes[0].VolumeSource.ConfigMap.LocalObjectReference.Name = "world" @@ -1099,9 +1029,7 @@ func TestApplyResources(t *testing.T) { rStr: "inputs", want: applyMutation(simpleTaskSpec, func(spec *v1beta1.TaskSpec) { spec.Steps[1].WorkingDir = "/workspace/workspace" - spec.Steps[4].WorkingDir = "/workspace/workspace" - spec.Steps[8].Image = "/foo/builtImage" - spec.Steps[9].Image = "/workspace/foo/builtImage" + spec.Steps[3].WorkingDir = "/workspace/workspace" }), }, { name: "input resource specified", @@ -1111,10 +1039,8 @@ func TestApplyResources(t *testing.T) { want: applyMutation(simpleTaskSpec, func(spec *v1beta1.TaskSpec) { spec.Steps[1].WorkingDir = "/workspace/workspace" spec.Steps[1].Args = []string{"https://git-repo"} - spec.Steps[4].WorkingDir = "/workspace/workspace" - spec.Steps[4].Args = []string{"https://git-repo"} - spec.Steps[8].Image = "/foo/builtImage" - spec.Steps[9].Image = "/workspace/foo/builtImage" + spec.Steps[3].WorkingDir = "/workspace/workspace" + spec.Steps[3].Args = []string{"https://git-repo"} }), }, { name: "output resource specified", @@ -1123,11 +1049,7 @@ func TestApplyResources(t *testing.T) { rStr: "outputs", want: applyMutation(simpleTaskSpec, func(spec *v1beta1.TaskSpec) { spec.Steps[1].WorkingDir = "/workspace/workspace" - spec.Steps[2].Args = []string{"gcr.io/hans/sandwiches"} - spec.Steps[4].WorkingDir = "/workspace/workspace" - spec.Steps[5].Args = []string{"gcr.io/hans/sandwiches"} - spec.Steps[8].Image = "/foo/builtImage" - spec.Steps[9].Image = "/workspace/foo/builtImage" + spec.Steps[3].WorkingDir = "/workspace/workspace" }), }, { name: "output resource specified with path replacement", diff --git a/pkg/reconciler/taskrun/resources/image_exporter.go b/pkg/reconciler/taskrun/resources/image_exporter.go deleted file mode 100644 index 5efe84ec36f..00000000000 --- a/pkg/reconciler/taskrun/resources/image_exporter.go +++ /dev/null @@ -1,100 +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 ( - "encoding/json" - "fmt" - "path/filepath" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" - "github.com/tektoncd/pipeline/pkg/names" -) - -const imageDigestExporterContainerName = "image-digest-exporter" - -// AddOutputImageDigestExporter add a step to check the index.json for all output images -func AddOutputImageDigestExporter( - imageDigestExporterImage string, - tr *v1beta1.TaskRun, - taskSpec *v1beta1.TaskSpec, - gr GetResource, -) error { - output := []*image.Resource{} - if tr.Spec.Resources != nil && len(tr.Spec.Resources.Outputs) > 0 { - for _, trb := range tr.Spec.Resources.Outputs { - boundResource, err := getBoundResource(trb.Name, tr.Spec.Resources.Outputs) - if err != nil { - return fmt.Errorf("failed to get bound resource: %w while adding output image digest exporter", err) - } - - resource, err := GetResourceFromBinding(boundResource.PipelineResourceBinding, gr) - if err != nil { - return fmt.Errorf("failed to get output pipeline Resource for taskRun %q resource %v; error: %w while adding output image digest exporter", tr.Name, boundResource, err) - } - if resource.Spec.Type == v1beta1.PipelineResourceTypeImage { - imageResource, err := image.NewResource(trb.Name, resource) - if err != nil { - return fmt.Errorf("invalid Image Resource for taskRun %q resource %v; error: %w", tr.Name, boundResource, err) - } - if taskSpec.Resources == nil { - // Shouldn't happens as it would be a validation error before - return fmt.Errorf("invalid Image Resource for taskrun %q resource %v; doesn't exists in the task", tr.Name, boundResource) - } - for _, o := range taskSpec.Resources.Outputs { - if o.Name == boundResource.Name { - if o.TargetPath == "" { - imageResource.OutputImageDir = filepath.Join(outputDir, boundResource.Name) - } else { - imageResource.OutputImageDir = o.TargetPath - } - break - } - } - output = append(output, imageResource) - } - } - - fmt.Println(output) - if len(output) > 0 { - augmentedSteps := []v1beta1.Step{} - imagesJSON, err := json.Marshal(output) - if err != nil { - return fmt.Errorf("failed to format image resource data for output image exporter: %w", err) - } - - augmentedSteps = append(augmentedSteps, taskSpec.Steps...) - augmentedSteps = append(augmentedSteps, imageDigestExporterStep(imageDigestExporterImage, imagesJSON)) - - taskSpec.Steps = augmentedSteps - } - } - - return nil -} - -func imageDigestExporterStep(imageDigestExporterImage string, imagesJSON []byte) v1beta1.Step { - return v1beta1.Step{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(imageDigestExporterContainerName), - Image: imageDigestExporterImage, - Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{ - "-images", string(imagesJSON), - }, - } -} diff --git a/pkg/reconciler/taskrun/resources/image_exporter_test.go b/pkg/reconciler/taskrun/resources/image_exporter_test.go deleted file mode 100644 index aba62bf4ab3..00000000000 --- a/pkg/reconciler/taskrun/resources/image_exporter_test.go +++ /dev/null @@ -1,196 +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 ( - "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/test/diff" - "github.com/tektoncd/pipeline/test/names" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestAddOutputImageDigestExporter(t *testing.T) { - for _, c := range []struct { - desc string - task *v1beta1.Task - taskRun *v1beta1.TaskRun - wantSteps []v1beta1.Step - }{{ - desc: "image resource declared as both input and output", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "step1", - }}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-image", - Type: "image", - }, - }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-image", - Type: "image", - }, - }}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image-1", - }, - }, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image-1", - }, - }, - }}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "step1", - }, { - Name: "image-digest-exporter-9l9zj", - Image: "override-with-imagedigest-exporter-image:latest", - Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", "[{\"name\":\"source-image\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/source-image\"}]"}, - }}, - }, { - desc: "image resource in task with multiple steps", - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Steps: []v1beta1.Step{{ - Name: "step1", - }, { - Name: "step2", - }}, - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-image", - Type: "image", - }, - }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-image", - Type: "image", - }, - }}, - }, - }, - }, - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Inputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image-1", - }, - }, - }}, - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image-1", - }, - }, - }}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "step1", - }, { - Name: "step2", - }, { - Name: "image-digest-exporter-9l9zj", - Image: "override-with-imagedigest-exporter-image:latest", - Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", "[{\"name\":\"source-image\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/source-image\"}]"}, - }}, - }} { - t.Run(c.desc, func(t *testing.T) { - names.TestingSeed() - gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { - return &resourcev1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "source-image-1", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "image", - Params: []v1beta1.ResourceParam{{ - Name: "url", - Value: "gcr.io/some-image-1", - }, { - Name: "digest", - Value: "", - }, { - Name: "OutputImageDir", - Value: "/workspace/source-image-1/index.json", - }}, - }, - }, nil - } - err := AddOutputImageDigestExporter("override-with-imagedigest-exporter-image:latest", c.taskRun, &c.task.Spec, gr) - if err != nil { - t.Fatalf("Failed to declare output resources for test %q: error %v", c.desc, err) - } - - if d := cmp.Diff(c.task.Spec.Steps, c.wantSteps); d != "" { - t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) - } - }) - } -} diff --git a/pkg/reconciler/taskrun/resources/input_resource_test.go b/pkg/reconciler/taskrun/resources/input_resource_test.go index 793a4273a19..176d0489523 100644 --- a/pkg/reconciler/taskrun/resources/input_resource_test.go +++ b/pkg/reconciler/taskrun/resources/input_resource_test.go @@ -36,12 +36,11 @@ import ( var ( images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + 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 diff --git a/pkg/reconciler/taskrun/resources/output_resource_test.go b/pkg/reconciler/taskrun/resources/output_resource_test.go index 27ddb5dcd8a..76e2efc1131 100644 --- a/pkg/reconciler/taskrun/resources/output_resource_test.go +++ b/pkg/reconciler/taskrun/resources/output_resource_test.go @@ -139,14 +139,6 @@ func outputTestResourceSetup() { Value: "true", }}, }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "source-image", - Namespace: "marshmallow", - }, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: "image", - }, }} outputTestResources = make(map[string]v1beta1.PipelineResourceInterface) @@ -337,53 +329,6 @@ func TestValidOutputResources(t *testing.T) { }, }, }, - }, { - name: "image resource in output with pipelinerun with owner", - desc: "image resource declared as output with pipelinerun owner reference should not generate any steps", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - 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: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - wantVolumes: nil, }, { name: "git resource in output", desc: "git resource declared in output without pipelinerun owner reference", @@ -761,51 +706,6 @@ func TestValidOutputResources(t *testing.T) { Secret: &corev1.SecretVolumeSource{SecretName: "sname"}, }, }}, - }, { - name: "image resource as output", - desc: "image resource defined only in output", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, }, { name: "Resource with TargetPath as output", desc: "Resource with TargetPath defined only in output", @@ -824,7 +724,7 @@ func TestValidOutputResources(t *testing.T) { PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: "source-workspace", ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", + Name: "source-git", }, }, }}, @@ -841,7 +741,7 @@ func TestValidOutputResources(t *testing.T) { Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace", - Type: "image", + Type: "git", TargetPath: "/workspace", }}}, }, @@ -852,46 +752,6 @@ func TestValidOutputResources(t *testing.T) { Image: "busybox", Command: []string{"mkdir", "-p", "/workspace"}, }}, - }, { - desc: "image output resource with no steps", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, }, { desc: "multiple image output resource with no steps", taskRun: &v1beta1.TaskRun{ @@ -905,14 +765,14 @@ func TestValidOutputResources(t *testing.T) { PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: "source-workspace", ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", + Name: "source-git", }, }, }, { PipelineResourceBinding: v1beta1.PipelineResourceBinding{ Name: "source-workspace-1", ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", + Name: "source-git", }, }, }}, @@ -929,11 +789,11 @@ func TestValidOutputResources(t *testing.T) { Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace", - Type: "image", + Type: "git", }}, { ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "source-workspace-1", - Type: "image", + Type: "git", }}}, }, }, diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 68ed5f06990..0ec2ec2df93 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -737,13 +737,6 @@ func (c *Reconciler) createPod(ctx context.Context, ts *v1beta1.TaskSpec, tr *v1 return nil, err } - // Get actual resource - err = resources.AddOutputImageDigestExporter(c.Images.ImageDigestExporterImage, tr, ts, c.resourceLister.PipelineResources(tr.Namespace).Get) - if err != nil { - logger.Errorf("Failed to create a pod for taskrun: %s due to output image resource error %v", tr.Name, 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) diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index eca7e5a5e90..77a64b2454b 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -87,12 +87,11 @@ const ( var ( defaultActiveDeadlineSeconds = int64(config.DefaultTimeoutMinutes * 60 * 1.5) images = pipeline.Images{ - EntrypointImage: "override-with-entrypoint:latest", - NopImage: "override-with-nop:latest", - GitImage: "override-with-git:latest", - ShellImage: "busybox", - GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", + 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") @@ -257,8 +256,8 @@ var ( }}, Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "myimage", - Type: resourcev1alpha1.PipelineResourceTypeImage, + Name: "workspace", + Type: resourcev1alpha1.PipelineResourceTypeGit, }, }}, }, @@ -271,7 +270,6 @@ var ( "--my-arg=$(inputs.params.myarg)", "--my-arg-with-default=$(inputs.params.myarghasdefault)", "--my-arg-with-default2=$(inputs.params.myarghasdefault2)", - "--my-additional-arg=$(outputs.resources.myimage.url)", "--my-taskname-arg=$(context.task.name)", "--my-taskrun-arg=$(context.taskRun.name)", }, @@ -316,16 +314,6 @@ var ( }}, }, } - imageResource = &resourcev1alpha1.PipelineResource{ - ObjectMeta: objectMeta("image-resource", "foo"), - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, - Params: []resourcev1alpha1.ResourceParam{{ - Name: "URL", - Value: "gcr.io/kristoff/sven", - }}, - }, - } binVolume = corev1.Volume{ Name: "tekton-internal-bin", @@ -715,9 +703,9 @@ spec: resourceRef: name: git-resource outputs: - - name: myimage + - name: workspace resourceRef: - name: image-resource + name: git-resource taskRef: apiVersion: a1 name: test-task-with-substitution @@ -902,7 +890,7 @@ spec: TaskRuns: taskruns, Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask, outputTask}, ClusterTasks: []*v1beta1.ClusterTask{clustertask}, - PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource, imageResource}, + PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource}, } for _, tc := range []struct { name string @@ -951,13 +939,13 @@ spec: }, }}, []stepForExpectedPod{ { - name: "create-dir-myimage-mssqb", + name: "create-dir-workspace-mz4c7", image: "busybox", cmd: "mkdir", - args: []string{"-p", "/workspace/output/myimage"}, + args: []string{"-p", "/workspace/output/workspace"}, }, { - name: "git-source-workspace-mz4c7", + name: "git-source-workspace-9l9zj", image: "override-with-git:latest", cmd: "/ko-app/git-init", args: []string{"-url", "https://foo.git", @@ -977,7 +965,6 @@ spec: "--my-arg=foo", "--my-arg-with-default=bar", "--my-arg-with-default2=thedefault", - "--my-additional-arg=gcr.io/kristoff/sven", "--my-taskname-arg=test-task-with-substitution", "--my-taskrun-arg=test-taskrun-substitution", }, @@ -988,15 +975,6 @@ spec: cmd: "/mycmd", args: []string{"--my-other-arg=https://foo.git"}, }, - { - name: "image-digest-exporter-9l9zj", - image: "override-with-imagedigest-exporter-image:latest", - cmd: "/ko-app/imagedigestexporter", - args: []string{ - "-images", - "[{\"name\":\"myimage\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/myimage\"}]", - }, - }, }), }, { name: "taskrun-with-taskspec", @@ -1216,7 +1194,7 @@ spec: TaskRuns: taskruns, Tasks: []*v1beta1.Task{simpleTask, saTask, templatedTask, outputTask}, ClusterTasks: []*v1beta1.ClusterTask{clustertask}, - PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource, imageResource}, + PipelineResources: []*resourcev1alpha1.PipelineResource{gitResource, anotherGitResource}, } for _, tc := range []struct { name string diff --git a/pkg/reconciler/taskrun/validate_resources_test.go b/pkg/reconciler/taskrun/validate_resources_test.go index 19db70401af..2bd03b35c36 100644 --- a/pkg/reconciler/taskrun/validate_resources_test.go +++ b/pkg/reconciler/taskrun/validate_resources_test.go @@ -65,14 +65,14 @@ func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { { ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "resource-to-provide", - Type: resourcev1alpha1.PipelineResourceTypeImage, + Type: resourcev1alpha1.PipelineResourceTypeGit, Optional: false, }, }, { ResourceDeclaration: v1beta1.ResourceDeclaration{ Name: "optional-resource-to-provide", - Type: resourcev1alpha1.PipelineResourceTypeImage, + Type: resourcev1alpha1.PipelineResourceTypeGit, Optional: true, }, }, @@ -108,13 +108,13 @@ func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { "resource-to-provide": { ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, + Type: resourcev1alpha1.PipelineResourceTypeGit, }, }, "optional-resource-to-provide": { ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, + Type: resourcev1alpha1.PipelineResourceTypeGit, }, }, }, @@ -367,19 +367,6 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, }, } - testimageinput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "testimageinput", - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }}, - }, - }, - } testrequiredgitinput := &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: v1beta1.TaskSpec{ @@ -407,19 +394,6 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, }, } - testimageoutput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "testimageoutput", - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }}, - }, - }, - } testrequiredgitoutput := &v1beta1.Task{ ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: v1beta1.TaskSpec{ @@ -440,15 +414,15 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { Resources: &v1beta1.TaskResources{ Inputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredimageinput", - Type: resourcev1alpha1.PipelineResourceTypeImage, + Name: "requiredgitinput", + Type: resourcev1alpha1.PipelineResourceTypeGit, Optional: false, }, }}, Outputs: []v1beta1.TaskResource{{ ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredimageoutput", - Type: resourcev1alpha1.PipelineResourceTypeImage, + Name: "requiredgitoutput", + Type: resourcev1alpha1.PipelineResourceTypeGit, Optional: false, }, }}, @@ -473,24 +447,24 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, { name: "input-resource-mismatch", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageinput.Spec, + TaskSpec: &testinput.Spec, Inputs: map[string]*resourcev1alpha1.PipelineResource{"testimageinput": r}, }, }, { name: "input-resource-missing", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageinput.Spec, + TaskSpec: &testinput.Spec, }, }, { name: "output-resource-mismatch", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageoutput.Spec, + TaskSpec: &testoutput.Spec, Outputs: map[string]*resourcev1alpha1.PipelineResource{"testimageoutput": r}, }, }, { name: "output-resource-missing", rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageoutput.Spec, + TaskSpec: &testoutput.Spec, }, }, { name: "extra-input-resource", diff --git a/tekton/publish.yaml b/tekton/publish.yaml index 2241212dc04..9d3de725586 100644 --- a/tekton/publish.yaml +++ b/tekton/publish.yaml @@ -11,7 +11,7 @@ spec: default: github.com/tektoncd/pipeline - name: images description: List of cmd/* paths to be published as images - default: "controller webhook entrypoint nop git-init imagedigestexporter workingdirinit resolvers sidecarlogresults" + default: "controller webhook entrypoint nop git-init workingdirinit resolvers sidecarlogresults" - name: versionTag description: The vX.Y.Z version that the artifacts should be tagged with (including `v`) - name: imageRegistry diff --git a/test/conversion_test.go b/test/conversion_test.go index b2c84f3b2e4..fe3e403215b 100644 --- a/test/conversion_test.go +++ b/test/conversion_test.go @@ -159,11 +159,6 @@ spec: type: git description: "The input is code from a git repository" optional: true - outputs: - - name: optionalimage - type: image - description: "The output is a Docker image" - optional: true ` v1TaskYaml = ` @@ -171,7 +166,7 @@ metadata: name: %s namespace: %s annotations: { - tekton.dev/v1beta1Resources: '{"inputs":[{"name":"git-repo","type":"git","description":"The input is code from a git repository","optional":true}],"outputs":[{"name":"optionalimage","type":"image","description":"The output is a Docker image","optional":true}]}' + tekton.dev/v1beta1Resources: '{"inputs":[{"name":"git-repo","type":"git","description":"The input is code from a git repository","optional":true}]}' } spec: steps: diff --git a/test/helm_task_test.go b/test/helm_task_test.go deleted file mode 100644 index 2c13fee478b..00000000000 --- a/test/helm_task_test.go +++ /dev/null @@ -1,371 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package test - -import ( - "context" - "fmt" - "testing" - - "github.com/tektoncd/pipeline/test/parse" - - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/pkg/names" - rbacv1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -var clusterRoleBindings [1]*rbacv1.ClusterRoleBinding - -// TestHelmDeployPipelineRun is an integration test that will verify a pipeline build an image -// and then using helm to deploy it -func TestHelmDeployPipelineRun(t *testing.T) { - repo := ensureDockerRepo(t) - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setup(ctx, t) - setupClusterBindingForHelm(ctx, t, c, namespace) - - var ( - sourceResourceName = helpers.ObjectNameForTest(t) - sourceImageName = helpers.ObjectNameForTest(t) - createImageTaskName = helpers.ObjectNameForTest(t) - helmDeployTaskName = helpers.ObjectNameForTest(t) - checkServiceTaskName = helpers.ObjectNameForTest(t) - helmDeployPipelineName = helpers.ObjectNameForTest(t) - helmDeployPipelineRunName = helpers.ObjectNameForTest(t) - ) - - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - t.Logf("Creating Git PipelineResource %s", sourceResourceName) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, getGoHelloworldGitResource(t, sourceResourceName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", sourceResourceName, err) - } - - t.Logf("Creating Image PipelineResource %s", sourceImageName) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, getHelmImageResource(t, repo, sourceImageName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", sourceImageName, err) - } - - t.Logf("Creating Task %s", createImageTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, getCreateImageTask(t, namespace, createImageTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", createImageTaskName, err) - } - - t.Logf("Creating Task %s", helmDeployTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, getHelmDeployTask(t, namespace, helmDeployTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", helmDeployTaskName, err) - } - - t.Logf("Creating Task %s", checkServiceTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, getCheckServiceTask(t, namespace, checkServiceTaskName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", checkServiceTaskName, err) - } - - t.Logf("Creating Pipeline %s", helmDeployPipelineName) - if _, err := c.V1beta1PipelineClient.Create(ctx, getHelmDeployPipeline(t, namespace, createImageTaskName, helmDeployTaskName, checkServiceTaskName, helmDeployPipelineName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", helmDeployPipelineName, err) - } - - t.Logf("Creating PipelineRun %s", helmDeployPipelineRunName) - if _, err := c.V1beta1PipelineRunClient.Create(ctx, getHelmDeployPipelineRun(t, namespace, sourceResourceName, sourceImageName, helmDeployPipelineRunName, helmDeployPipelineName), metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", helmDeployPipelineRunName, err) - } - - // Verify status of PipelineRun (wait for it) - if err := WaitForPipelineRunState(ctx, c, helmDeployPipelineRunName, timeout, PipelineRunSucceed(helmDeployPipelineRunName), "PipelineRunCompleted", v1beta1Version); err != nil { - t.Errorf("Error waiting for PipelineRun %s to finish: %s", helmDeployPipelineRunName, err) - t.Fatalf("PipelineRun execution failed; helm may or may not have been installed :(") - } - - // cleanup task to remove helm releases from cluster and cluster role bindings, will not fail the test if it fails, just log - knativetest.CleanupOnInterrupt(func() { helmCleanup(ctx, t, c, namespace) }, t.Logf) - defer helmCleanup(ctx, t, c, namespace) -} - -func getGoHelloworldGitResource(t *testing.T, sourceResourceName string) *v1alpha1.PipelineResource { - t.Helper() - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: git - params: - - name: url - value: https://github.com/tektoncd/pipeline -`, sourceResourceName)) -} - -func getHelmImageResource(t *testing.T, dockerRepo, sourceImageName string) *v1alpha1.PipelineResource { - t.Helper() - imageName := fmt.Sprintf("%s/%s", dockerRepo, names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(sourceImageName)) - - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: image - params: - - name: url - value: %s -`, sourceImageName, imageName)) -} - -func getCreateImageTask(t *testing.T, namespace, createImageTaskName string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: gitsource - type: git - outputs: - - name: builtimage - type: image - steps: - - name: kaniko - image: %s - args: ['--dockerfile=/workspace/gitsource/test/gohelloworld/Dockerfile', - '--context=/workspace/gitsource/', - '--destination=$(outputs.resources.builtimage.url)'] -`, createImageTaskName, namespace, getTestImage(kanikoImage))) -} - -func getHelmDeployTask(t *testing.T, namespace, helmDeployTaskName string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: gitsource - type: git - - name: image - type: image - params: - - name: pathToHelmCharts - type: string - description: 'Path to the helm charts' - - name: chartname - type: string - default: "" - steps: - - image: alpine/helm:3.5.4 - args: ['upgrade', - '--wait', - '--debug', - '--install', - '--namespace', - '%s', - '$(inputs.params.chartname)', - '$(inputs.params.pathToHelmCharts)', - '--set', - 'image.repository=$(inputs.resources.image.url)', - '--set', - 'service.type=ClusterIP'] - - image: lachlanevenson/k8s-kubectl - command: ['kubectl'] - args: ['get', - 'all', - '--namespace', - '%s'] -`, helmDeployTaskName, namespace, namespace, namespace)) -} - -func getCheckServiceTask(t *testing.T, namespace, checkServiceTaskName string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - params: - - name: serviceUrl - type: string - description: 'Service url' - steps: - - image: %s - args: ['-wait', '$(inputs.params.serviceUrl)', '-timeout', '1m'] -`, checkServiceTaskName, namespace, getTestImage(dockerizeImage))) -} - -func getHelmDeployPipeline(t *testing.T, namespace, createImageTaskName, helmDeployTaskName, checkServiceTaskName, helmDeployPipelineName string) *v1beta1.Pipeline { - t.Helper() - return parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - params: - - name: chartname - type: string - resources: - - name: git-repo - type: git - - name: the-image - type: image - tasks: - - name: push-image - taskRef: - name: %s - resources: - inputs: - - name: gitsource - resource: git-repo - outputs: - - name: builtimage - resource: the-image - - name: helm-deploy - taskRef: - name: %s - resources: - inputs: - - name: gitsource - resource: git-repo - - name: image - resource: the-image - params: - - name: pathToHelmCharts - value: /workspace/gitsource/test/gohelloworld/gohelloworld-chart - - name: chartname - value: '$(params.chartname)' - - name: check-service - taskRef: - name: %s - params: - - name: serviceUrl - value: http://gohelloworld-chart:8080 - runAfter: ['helm-deploy'] -`, helmDeployPipelineName, namespace, createImageTaskName, helmDeployTaskName, checkServiceTaskName)) -} - -func getHelmDeployPipelineRun(t *testing.T, namespace, sourceResourceName, sourceImageName, helmDeployPipelineRunName, helmDeployPipelineName string) *v1beta1.PipelineRun { - t.Helper() - return parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - pipelineRef: - name: %s - params: - - name: chartname - value: gohelloworld - resources: - - name: git-repo - resourceRef: - name: %s - - name: the-image - resourceRef: - name: %s -`, helmDeployPipelineRunName, namespace, helmDeployPipelineName, sourceResourceName, sourceImageName)) -} - -func setupClusterBindingForHelm(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - clusterRoleBindings[0] = &rbacv1.ClusterRoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("default-tiller"), - }, - RoleRef: rbacv1.RoleRef{ - APIGroup: "rbac.authorization.k8s.io", - Kind: "ClusterRole", - Name: "cluster-admin", - }, - Subjects: []rbacv1.Subject{{ - Kind: "ServiceAccount", - Name: "default", - Namespace: namespace, - }}, - } - - for _, crb := range clusterRoleBindings { - t.Logf("Creating Cluster Role binding %s for helm", crb.Name) - if _, err := c.KubeClient.RbacV1().ClusterRoleBindings().Create(ctx, crb, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create cluster role binding for Helm %s", err) - } - } -} - -func helmCleanup(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - t.Logf("Cleaning up helm from cluster...") - - removeAllHelmReleases(ctx, t, c, namespace) - - for _, crb := range clusterRoleBindings { - t.Logf("Deleting Cluster Role binding %s for helm", crb.Name) - if err := c.KubeClient.RbacV1().ClusterRoleBindings().Delete(ctx, crb.Name, metav1.DeleteOptions{}); err != nil { - t.Fatalf("Failed to delete cluster role binding for Helm %s", err) - } - } -} - -func removeAllHelmReleases(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - helmRemoveAllTaskName := "helm-remove-all-task" - helmRemoveAllTask := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - steps: - - name: helm-remove-all - image: alpine/helm:3.5.4 - command: ['/bin/sh'] - args: ['-c', 'helm ls --short --all --namespace %s | xargs -n1 helm delete --namespace %s'] -`, helmRemoveAllTaskName, namespace, namespace, namespace)) - - helmRemoveAllTaskRunName := "helm-remove-all-taskrun" - helmRemoveAllTaskRun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - taskRef: - name: %s -`, helmRemoveAllTaskRunName, namespace, helmRemoveAllTaskName)) - - t.Logf("Creating Task %s", helmRemoveAllTaskName) - if _, err := c.V1beta1TaskClient.Create(ctx, helmRemoveAllTask, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", helmRemoveAllTaskName, err) - } - - t.Logf("Creating TaskRun %s", helmRemoveAllTaskRunName) - if _, err := c.V1beta1TaskRunClient.Create(ctx, helmRemoveAllTaskRun, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", helmRemoveAllTaskRunName, err) - } - - t.Logf("Waiting for TaskRun %s in namespace %s to complete", helmRemoveAllTaskRunName, namespace) - if err := WaitForTaskRunState(ctx, c, helmRemoveAllTaskRunName, TaskRunSucceed(helmRemoveAllTaskRunName), "TaskRunSuccess", v1beta1Version); err != nil { - t.Logf("TaskRun %s failed to finish: %s", helmRemoveAllTaskRunName, err) - } -} diff --git a/test/kaniko_task_test.go b/test/kaniko_task_test.go deleted file mode 100644 index 94e89fb638f..00000000000 --- a/test/kaniko_task_test.go +++ /dev/null @@ -1,256 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package test - -import ( - "context" - "fmt" - "strings" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "github.com/tektoncd/pipeline/test/parse" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" - "knative.dev/pkg/test/helpers" -) - -const ( - // This is a random revision chosen on 2020/10/09 - revision = "a310cc6d1cd449f95cedd23393de766fdc649651" -) - -// TestTaskRun is an integration test that will verify a TaskRun using kaniko -func TestKanikoTaskRun(t *testing.T) { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - if skipRootUserTests { - t.Skip("Skip test as skipRootUserTests set to true") - } - - c, namespace := setup(ctx, t, withRegistry) - t.Parallel() - - repo := fmt.Sprintf("registry.%s:5000/kanikotasktest", namespace) - - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - git := getGitResource(t) - t.Logf("Creating Git PipelineResource %s", git.Name) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, git, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", git.Name, err) - } - - image := getImageResource(t, repo) - t.Logf("Creating Image PipelineResource %s", repo) - if _, err := c.V1alpha1PipelineResourceClient.Create(ctx, image, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline Resource `%s`: %s", git.Name, err) - } - - task := getTask(t, repo, namespace) - t.Logf("Creating Task %s", task.Name) - if _, err := c.V1beta1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", task.Name, err) - } - - tr := getTaskRun(t, namespace, task.Name, git.Name, image.Name) - t.Logf("Creating TaskRun %s", tr.Name) - if _, err := c.V1beta1TaskRunClient.Create(ctx, tr, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", tr.Name, err) - } - - // Verify status of TaskRun (wait for it) - - if err := WaitForTaskRunState(ctx, c, tr.Name, Succeed(tr.Name), "TaskRunCompleted", v1beta1Version); err != nil { - t.Errorf("Error waiting for TaskRun %s to finish: %s", tr.Name, err) - } - - tr, err := c.V1beta1TaskRunClient.Get(ctx, tr.Name, metav1.GetOptions{}) - if err != nil { - t.Errorf("Error retrieving taskrun: %s", err) - } - digest := "" - commit := "" - url := "" - for _, rr := range tr.Status.ResourcesResult { - switch rr.Key { - case "digest": - digest = rr.Value - case "commit": - commit = rr.Value - case "url": - url = rr.Value - } - // Every resource should have a resource name - if rr.ResourceName == "" { - t.Errorf("Resource ref not set for %v in TaskRun: %v", rr, tr) - } - } - if digest == "" { - t.Errorf("Digest not found in TaskRun.Status: %v", tr.Status) - } - if commit == "" { - t.Errorf("Commit not found in TaskRun.Status: %v", tr.Status) - } - if url == "" { - t.Errorf("Url not found in TaskRun.Status: %v", tr.Status) - } - - if revision != commit { - t.Fatalf("Expected remote commit to match local revision: %s, %s", commit, revision) - } - - // match the local digest, which is first capture group against the remote image - remoteDigest, err := getRemoteDigest(t, c, namespace, repo) - if err != nil { - t.Fatalf("Expected to get digest for remote image %s: %v", repo, err) - } - if d := cmp.Diff(digest, remoteDigest); d != "" { - t.Fatalf("Expected local digest %s to match remote digest %s: %s", digest, remoteDigest, d) - } -} - -func getGitResource(t *testing.T) *v1alpha1.PipelineResource { - t.Helper() - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: git - params: - - name: Url - value: https://github.com/GoogleContainerTools/kaniko - - name: Revision - value: %s -`, helpers.ObjectNameForTest(t), revision)) -} - -func getImageResource(t *testing.T, repo string) *v1alpha1.PipelineResource { - t.Helper() - return parse.MustParsePipelineResource(t, fmt.Sprintf(` -metadata: - name: %s -spec: - type: image - params: - - name: url - value: %s -`, helpers.ObjectNameForTest(t), repo)) -} - -func getTask(t *testing.T, repo, namespace string) *v1beta1.Task { - t.Helper() - return parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - resources: - inputs: - - name: gitsource - type: git - outputs: - - name: builtImage - type: image - steps: - - name: kaniko - image: %s - args: ['--dockerfile=/workspace/gitsource/integration/dockerfiles/Dockerfile_test_label', - '--destination=%s', - '--context=/workspace/gitsource', - '--oci-layout-path=/workspace/output/builtImage', - '--insecure', - '--insecure-pull', - '--insecure-registry=registry.%s:5000/'] - securityContext: - runAsUser: 0 - sidecars: - - name: registry - image: %s -`, helpers.ObjectNameForTest(t), namespace, getTestImage(kanikoImage), repo, namespace, getTestImage(registryImage))) -} - -func getTaskRun(t *testing.T, namespace, task, git, image string) *v1beta1.TaskRun { - t.Helper() - return parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` -metadata: - name: %s - namespace: %s -spec: - taskRef: - name: %s - timeout: 5m - resources: - inputs: - - name: gitsource - resourceRef: - name: %s - outputs: - - name: builtImage - resourceRef: - name: %s -`, helpers.ObjectNameForTest(t), namespace, task, git, image)) -} - -// getRemoteDigest starts a pod to query the registry from the namespace itself, using skopeo (and jq). -// The reason we have to do that is because the image is pushed on a local registry that is not exposed -// to the "outside" of the test, this means it can be query by the test itself. It can only be query from -// a pod in the namespace. skopeo is able to do that query and we use jq to extract the digest from its -// output. The image used for this pod is build in the tektoncd/plumbing repository. -func getRemoteDigest(t *testing.T, c *clients, namespace, image string) (string, error) { - t.Helper() - podName := "skopeo-jq" - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - if _, err := c.KubeClient.CoreV1().Pods(namespace).Create(ctx, &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: podName, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Name: "skopeo", - Image: "gcr.io/tekton-releases/dogfooding/skopeo:latest", - Command: []string{"/bin/sh", "-c"}, - Args: []string{"skopeo inspect --tls-verify=false docker://" + image + ":latest| jq '.Digest'"}, - }}, - RestartPolicy: corev1.RestartPolicyNever, - }, - }, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create the skopeo-jq pod: %v", err) - } - if err := WaitForPodState(ctx, c, podName, namespace, func(pod *corev1.Pod) (bool, error) { - return pod.Status.Phase == "Succeeded" || pod.Status.Phase == "Failed", nil - }, "PodContainersTerminated"); err != nil { - t.Fatalf("Error waiting for Pod %q to terminate: %v", podName, err) - } - logs, err := getContainerLogsFromPod(ctx, c.KubeClient, podName, "skopeo", namespace) - if err != nil { - t.Fatalf("Could not get logs for pod %s: %s", podName, err) - } - return strings.TrimSpace(strings.ReplaceAll(logs, "\"", "")), nil -} diff --git a/test/ko_test.go b/test/ko_test.go deleted file mode 100644 index 1a364ebb66d..00000000000 --- a/test/ko_test.go +++ /dev/null @@ -1,53 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package test - -import ( - "errors" - "fmt" - "os" - "testing" -) - -// missingKoFatal makes missing KO_DOCKER_REPO envvar fatal or optional -var missingKoFatal = "true" - -func ensureDockerRepo(t *testing.T) string { - t.Helper() - repo, err := getDockerRepo() - if err != nil { - if missingKoFatal == "false" { - t.Skip("KO_DOCKER_REPO env variable is required") - } - t.Fatal("KO_DOCKER_REPO env variable is required") - } - return repo -} - -func getDockerRepo() (string, error) { - // according to knative/test-infra readme (https://github.com/knative/test-infra/blob/13055d769cc5e1756e605fcb3bcc1c25376699f1/scripts/README.md) - // the KO_DOCKER_REPO will be set with according to the project where the cluster is created - // it is used here to dynamically get the docker registry to push the image to - dockerRepo := os.Getenv("KO_DOCKER_REPO") - if dockerRepo == "" { - return "", errors.New("KO_DOCKER_REPO env variable is required") - } - return fmt.Sprintf("%s/kanikotasktest", dockerRepo), nil -}