diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 5aacc36f247..0db3ab96bb6 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -17,12 +17,10 @@ limitations under the License. package main import ( - "context" "flag" "log" "net/http" "os" - "time" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -39,23 +37,11 @@ import ( "knative.dev/pkg/injection" "knative.dev/pkg/injection/sharedmain" "knative.dev/pkg/signals" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.12.0" - "go.opentelemetry.io/otel/trace" ) const ( // ControllerLogKey is the name of the logger for the controller cmd ControllerLogKey = "tekton-pipelines-controller" - // TracerProviderPipelineRun is the name of TraceProvider used pipeline reconciler - TracerProviderPipelineRun = "pipeline-reconciler" - // TracerProviderTaskRun is the name of TracerProvider used in taskrun reconciler - TracerProviderTaskRun = "taskrun-reconciler" ) func main() { @@ -117,83 +103,16 @@ func main() { log.Fatal(http.ListenAndServe(":"+port, mux)) // #nosec G114 -- see https://github.com/securego/gosec#available-rules }() - // initialize opentelemetry - tpPipelineRun, err := tracerProvider(TracerProviderPipelineRun) - if err != nil { - log.Printf("failed to initialize tracerProvider for pipelinerun, falling back to no-op provider, %s", err.Error()) - tpPipelineRun = trace.NewNoopTracerProvider() - } - tpTaskrun, err := tracerProvider(TracerProviderTaskRun) - if err != nil { - log.Printf("failed to initialize tracerProvider for taskrun, falling back to no-op provider, %s", err.Error()) - tpTaskrun = trace.NewNoopTracerProvider() - } - otel.SetTextMapPropagator(propagation.TraceContext{}) - ctx, cancel := context.WithCancel(ctx) - defer cancel() - ctx = filteredinformerfactory.WithSelectors(ctx, v1beta1.ManagedByLabelKey) sharedmain.MainWithConfig(ctx, ControllerLogKey, cfg, - taskrun.NewController(opts, clock.RealClock{}, tpTaskrun), - pipelinerun.NewController(opts, clock.RealClock{}, tpPipelineRun), + taskrun.NewController(opts, clock.RealClock{}), + pipelinerun.NewController(opts, clock.RealClock{}), run.NewController(), resolutionrequest.NewController(clock.RealClock{}), customrun.NewController(), ) - - // Cleanly shutdown and flush telemetry when the application exits. - defer func(ctx context.Context) { - // Do not make the application hang when it is shutdown. - ctx, cancel = context.WithTimeout(ctx, time.Second*5) - defer cancel() - - // shutdown is only needed when tracerProvider is inialized with jaeger - // not needed when tracerProvider is NewNoopTracerProvider - if tp, ok := tpPipelineRun.(*tracesdk.TracerProvider); ok { - if err := tp.Shutdown(ctx); err != nil { - log.Printf("Unable to shutdown tracerProvider for pipelinerun, %s", err.Error()) - } - } - if tp, ok := tpTaskrun.(*tracesdk.TracerProvider); ok { - if err := tp.Shutdown(ctx); err != nil { - log.Printf("Unable to shutdown tracerProvider for taskrun, %s", err.Error()) - } - } - }(ctx) } func handler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } - -// tracerProvider returns an OpenTelemetry TracerProvider configured to use -// the Jaeger exporter that will send spans to the provided url. The returned -// TracerProvider will also use a Resource configured with all the information -// about the application. -func tracerProvider(service string) (trace.TracerProvider, error) { - // Create the Jaeger exporter - // The following env variables are used by the sdk for creating the exporter - // - OTEL_EXPORTER_JAEGER_ENDPOINT is the HTTP endpoint for sending spans directly to a collector. - // - OTEL_EXPORTER_JAEGER_USER is the username to be sent as authentication to the collector endpoint. - // - OTEL_EXPORTER_JAEGER_PASSWORD is the password to be sent as authentication to the collector endpoint. - - if _, e := os.LookupEnv("OTEL_EXPORTER_JAEGER_ENDPOINT"); !e { - // jaeger endpoint is not defined, disable tracing and return no-op tracerProvider - return trace.NewNoopTracerProvider(), nil - } - - exp, err := jaeger.New(jaeger.WithCollectorEndpoint()) - if err != nil { - return nil, err - } - // Initialize tracerProvider with the jaeger exporter - tp := tracesdk.NewTracerProvider( - tracesdk.WithBatcher(exp), - // Record information about the service in a Resource. - tracesdk.WithResource(resource.NewWithAttributes( - semconv.SchemaURL, - semconv.ServiceNameKey.String(service), - )), - ) - return tp, nil -} diff --git a/config/controller.yaml b/config/controller.yaml index 29dd74cf59a..add35b73b68 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", "-pr-image", "ko://github.com/tektoncd/pipeline/cmd/pullrequest-init", "-workingdirinit-image", "ko://github.com/tektoncd/pipeline/cmd/workingdirinit", diff --git a/docs/install.md b/docs/install.md index d1955b41dd8..4cc9e8727dd 100644 --- a/docs/install.md +++ b/docs/install.md @@ -710,12 +710,6 @@ which results in: "sha256": "83d5ec6addece4aac79898c9631ee669f5fee5a710a2ed1f98a6d40c19fb88f7" } }, - { - "name": "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter", - "digest": { - "sha256": "e4d77b5b8902270f37812f85feb70d57d6d0e1fed2f3b46f86baf534f19cd9c0" - } - }, { "name": "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop", "digest": { @@ -779,7 +773,6 @@ Similarly, you can verify the rest of the images which were published as part of gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop -gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook ``` 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 68e7a9cd813..fd327c994f6 100644 --- a/pkg/apis/pipeline/images.go +++ b/pkg/apis/pipeline/images.go @@ -40,8 +40,7 @@ type Images struct { GsutilImage string // PRImage is the container image that we use to implement the PR source step. PRImage 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 @@ -62,7 +61,6 @@ func (i Images) Validate() error { {i.ShellImageWin, "shell-image-win"}, {i.GsutilImage, "gsutil-image"}, {i.PRImage, "pr-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 0f942cfb417..4163708d2d2 100644 --- a/pkg/apis/pipeline/images_test.go +++ b/pkg/apis/pipeline/images_test.go @@ -8,31 +8,29 @@ import ( func TestValidate(t *testing.T) { valid := pipeline.Images{ - EntrypointImage: "set", - SidecarLogResultsImage: "set", - NopImage: "set", - GitImage: "set", - ShellImage: "set", - ShellImageWin: "set", - GsutilImage: "set", - PRImage: "set", - ImageDigestExporterImage: "set", - WorkingDirInitImage: "set", + EntrypointImage: "set", + SidecarLogResultsImage: "set", + NopImage: "set", + GitImage: "set", + ShellImage: "set", + ShellImageWin: "set", + GsutilImage: "set", + PRImage: "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", - PRImage: "", // unset! - ImageDigestExporterImage: "set", + EntrypointImage: "set", + SidecarLogResultsImage: "set", + NopImage: "set", + GitImage: "", // unset! + ShellImage: "", // unset! + ShellImageWin: "set", + GsutilImage: "set", + PRImage: "", // unset! } wantErr := "found unset image flags: [git-image pr-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 e1c2d6b42ff..ca73ea8f2b2 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go @@ -656,39 +656,6 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { Message: `missing field(s)`, Paths: []string{"tasks[1].when[0]", "finally[0].when[0]"}, }, - }, { - name: "invalid pipeline with pipeline task having reference to resources which does not exist", - ps: &PipelineSpec{ - Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "wonderful-resource", Type: PipelineResourceTypeImage, - }}, - Tasks: []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "missing-great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-imagee", Resource: "missing-wonderful-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-image", Resource: "wonderful-resource", - }}, - }, - }}, - }, - expectedError: apis.FieldError{ - Message: `invalid value: pipeline declared resources didn't match usage in Tasks: Didn't provide required values: [missing-great-resource missing-wonderful-resource]`, - Paths: []string{"resources"}, - }, }, { name: "invalid pipeline spec - from referring to a pipeline task which does not exist", ps: &PipelineSpec{ @@ -945,72 +912,6 @@ func TestValidateFrom_Failure(t *testing.T) { } } -func TestValidateDeclaredResources_Success(t *testing.T) { - tests := []struct { - name string - resources []PipelineDeclaredResource - tasks []PipelineTask - }{{ - name: "valid resource declarations and usage", - resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "wonderful-resource", Type: PipelineResourceTypeImage, - }}, - tasks: []PipelineTask{{ - Name: "bar", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-imagee", Resource: "wonderful-resource", - }}, - }, - }, { - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-image", Resource: "wonderful-resource", From: []string{"bar"}, - }}, - }, - }}, - }, { - name: "valid resource declarations with extra resources, not used in any pipeline task", - resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "awesome-resource", Type: PipelineResourceTypeImage, - }, { - Name: "yet-another-great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "yet-another-awesome-resource", Type: PipelineResourceTypeImage, - }}, - tasks: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "the-resource", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "the-awesome-resource", Resource: "awesome-resource", - }}, - }, - }}, - }} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := validateDeclaredResources(tt.resources, tt.tasks, []PipelineTask{}) - if err != nil { - t.Errorf("Pipeline.validateDeclaredResources() returned error for valid resource declarations: %v", err) - } - }) - } -} - func TestValidateDeclaredResources_Failure(t *testing.T) { tests := []struct { name string @@ -2372,42 +2273,6 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { }}, }, }, - }, { - name: "valid pipeline with resource declarations and their valid usage", - p: &Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, - Spec: PipelineSpec{ - Resources: []PipelineDeclaredResource{{ - Name: "great-resource", Type: PipelineResourceTypeGit, - }, { - Name: "wonderful-resource", Type: PipelineResourceTypeImage, - }}, - Tasks: []PipelineTask{{ - Name: "non-final-task", - TaskRef: &TaskRef{Name: "bar-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-image", Resource: "wonderful-resource", - }}, - }, - }}, - Finally: []PipelineTask{{ - Name: "foo", - TaskRef: &TaskRef{Name: "foo-task"}, - Resources: &PipelineTaskResources{ - Inputs: []PipelineTaskInputResource{{ - Name: "some-workspace", Resource: "great-resource", - }}, - Outputs: []PipelineTaskOutputResource{{ - Name: "some-image", Resource: "wonderful-resource", - }}, - }, - }}, - }, - }, }, { name: "valid pipeline with final tasks referring to task results from a dag task", p: &Pipeline{ diff --git a/pkg/apis/pipeline/v1beta1/resource_types.go b/pkg/apis/pipeline/v1beta1/resource_types.go index 9f94addf9e8..d13c5fea2a9 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types.go +++ b/pkg/apis/pipeline/v1beta1/resource_types.go @@ -43,9 +43,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 - // PipelineResourceTypePullRequest indicates that this source is a SCM Pull Request. PipelineResourceTypePullRequest PipelineResourceType = resource.PipelineResourceTypePullRequest ) diff --git a/pkg/apis/resource/resource.go b/pkg/apis/resource/resource.go index 19bcc43c280..7811e95ac76 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/pullrequest" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" ) @@ -35,8 +34,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) case resourcev1alpha1.PipelineResourceTypePullRequest: 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 e306bbf1b61..3274c53a187 100644 --- a/pkg/apis/resource/v1alpha1/pipeline_resource_types.go +++ b/pkg/apis/resource/v1alpha1/pipeline_resource_types.go @@ -40,9 +40,6 @@ 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" - // PipelineResourceTypePullRequest indicates that this source is a SCM Pull Request. PipelineResourceTypePullRequest PipelineResourceType = "pullRequest" @@ -51,7 +48,7 @@ const ( ) // 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, PipelineResourceTypePullRequest} +var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypePullRequest} // +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 a40611bff1a..8e65e798a7d 100644 --- a/pkg/apis/resource/v1alpha1/storage/gcs_test.go +++ b/pkg/apis/resource/v1alpha1/storage/gcs_test.go @@ -32,13 +32,12 @@ 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", - PRImage: "override-with-pr:latest", - 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", + PRImage: "override-with-pr:latest", } func TestInvalidNewStorageResource(t *testing.T) { diff --git a/pkg/artifacts/artifact_storage_test.go b/pkg/artifacts/artifact_storage_test.go index 435bb1c7127..4e460507dc6 100644 --- a/pkg/artifacts/artifact_storage_test.go +++ b/pkg/artifacts/artifact_storage_test.go @@ -38,13 +38,12 @@ 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", - PRImage: "override-with-pr:latest", - 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", + PRImage: "override-with-pr:latest", } pipelinerun = &v1beta1.PipelineRun{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 30554cd00d3..e87edbc1a7b 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -73,13 +73,12 @@ 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", - PRImage: "override-with-pr:latest", - 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", + PRImage: "override-with-pr:latest", } 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 d816283fc37..b9b5d26bffb 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) { @@ -2516,32 +2496,6 @@ func TestValidateResourceBindings(t *testing.T) { } } -func TestValidateResourceBindings_Missing(t *testing.T) { - p := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, - Spec: v1beta1.PipelineSpec{ - Resources: []v1beta1.PipelineDeclaredResource{ - gitDeclaredResource, - { - Name: "image-resource", - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }, - }, - } - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun"}, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{Name: "pipeline"}, - Resources: []v1beta1.PipelineResourceBinding{gitSweetResourceBinding}, - }, - } - err := ValidateResourceBindings(&p.Spec, pr) - if err == nil { - t.Fatalf("Expected error indicating `image-resource` was missing but got no error") - } -} - func TestGetResourcesFromBindings_Extra(t *testing.T) { p := &v1beta1.Pipeline{ ObjectMeta: metav1.ObjectMeta{Name: "pipelines"}, diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index dcf13d89404..b5478ada2ba 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -38,13 +38,12 @@ 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", - PRImage: "override-with-pr:latest", - 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", + PRImage: "override-with-pr:latest", } simpleTaskSpec = &v1beta1.TaskSpec{ @@ -71,10 +70,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"])`, @@ -83,10 +78,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)", @@ -129,12 +120,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)", @@ -207,17 +192,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", - }, - }}, }, } @@ -367,10 +341,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])`, @@ -379,10 +349,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])", @@ -425,12 +391,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])", @@ -503,17 +463,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", - }, - }}, }, } @@ -714,8 +663,7 @@ var ( } outputs = map[string]v1beta1.PipelineResourceInterface{ - "imageToUse": imageResource, - "bucket": gcsResource, + "bucket": gcsResource, } gitResource, _ = resource.FromType("git-resource", &resourcev1alpha1.PipelineResource{ @@ -731,19 +679,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", @@ -903,26 +838,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" @@ -971,27 +904,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" @@ -1100,9 +1030,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", @@ -1112,10 +1040,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", @@ -1124,11 +1050,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/output_resource_test.go b/pkg/reconciler/taskrun/resources/output_resource_test.go index 27ddb5dcd8a..4b28144926c 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,192 +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", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-only-output-step", - Namespace: "marshmallow", - OwnerReferences: []metav1.OwnerReference{{ - Kind: "PipelineRun", - Name: "pipelinerun", - }}, - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - TargetPath: "/workspace", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace"}, - }}, - }, { - desc: "image output resource with no steps", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, - }, { - desc: "multiple image output resource with no steps", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-run-output-steps", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskRunSpec{ - Resources: &v1beta1.TaskRunResources{ - Outputs: []v1beta1.TaskResourceBinding{{ - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }, { - PipelineResourceBinding: v1beta1.PipelineResourceBinding{ - Name: "source-workspace-1", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "source-image", - }, - }, - }}, - }, - }, - }, - task: &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task1", - Namespace: "marshmallow", - }, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace", - Type: "image", - }}, { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "source-workspace-1", - Type: "image", - }}}, - }, - }, - }, - wantSteps: []v1beta1.Step{{ - Name: "create-dir-source-workspace-1-mz4c7", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace-1"}, - }, { - Name: "create-dir-source-workspace-9l9zj", - Image: "busybox", - Command: []string{"mkdir", "-p", "/workspace/output/source-workspace"}, - }}, }} { t.Run(c.name, func(t *testing.T) { names.TestingSeed() diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index bdeac1d8977..41d81ed4e3d 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 fd51e281762..4171da24d59 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -87,13 +87,12 @@ 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", - PRImage: "override-with-pr:latest", - 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", + PRImage: "override-with-pr:latest", } now = time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC) ignoreLastTransitionTime = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time") @@ -256,12 +255,6 @@ var ( Type: resourcev1alpha1.PipelineResourceTypeGit, }, }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "myimage", - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }}, }, Steps: []v1beta1.Step{ { @@ -317,16 +310,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,10 +698,6 @@ spec: - name: workspace resourceRef: name: git-resource - outputs: - - name: myimage - resourceRef: - name: image-resource taskRef: apiVersion: a1 name: test-task-with-substitution @@ -903,7 +882,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 @@ -934,71 +913,6 @@ spec: name: "sa-step", cmd: "/mycmd", }}), - }, { - name: "params", - taskRun: taskRunSubstitution, - wantEvents: []string{ - "Normal Started ", - "Normal Running Not all Steps", - }, - wantPod: expectedPod("test-taskrun-substitution-pod", "test-task-with-substitution", "test-taskrun-substitution", "foo", config.DefaultServiceAccountValue, false, []corev1.Volume{{ - Name: "volume-configmap", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "configbar", - }, - }, - }, - }}, []stepForExpectedPod{ - { - name: "create-dir-myimage-mssqb", - image: "busybox", - cmd: "mkdir", - args: []string{"-p", "/workspace/output/myimage"}, - }, - { - name: "git-source-workspace-mz4c7", - image: "override-with-git:latest", - cmd: "/ko-app/git-init", - args: []string{"-url", "https://foo.git", - "-path", "/workspace/workspace"}, - envVars: map[string]string{ - "TEKTON_RESOURCE_NAME": "workspace", - "HOME": "/tekton/home", - }, - workingDir: workspaceDir, - securityContext: gitResourceSecurityContext, - }, - { - name: "mycontainer", - image: "myimage", - cmd: "/mycmd", - args: []string{ - "--my-arg=foo", - "--my-arg-with-default=bar", - "--my-arg-with-default2=thedefault", - "--my-additional-arg=gcr.io/kristoff/sven", - "--my-taskname-arg=test-task-with-substitution", - "--my-taskrun-arg=test-taskrun-substitution", - }, - }, - { - name: "myothercontainer", - image: "myotherimage", - cmd: "/mycmd", - args: []string{"--my-other-arg=https://foo.git"}, - }, - { - name: "image-digest-exporter-9l9zj", - image: "override-with-imagedigest-exporter-image:latest", - cmd: "/ko-app/imagedigestexporter", - args: []string{ - "-images", - "[{\"name\":\"myimage\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"/workspace/output/myimage\"}]", - }, - }, - }), }, { name: "taskrun-with-taskspec", taskRun: taskRunWithTaskSpec, @@ -1217,7 +1131,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 7b0e224ec36..ff50a5c6b1b 100644 --- a/pkg/reconciler/taskrun/validate_resources_test.go +++ b/pkg/reconciler/taskrun/validate_resources_test.go @@ -61,22 +61,6 @@ func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { }, }, }, - Outputs: []v1beta1.TaskResource{ - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "resource-to-provide", - Type: resourcev1alpha1.PipelineResourceTypeImage, - Optional: false, - }, - }, - { - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "optional-resource-to-provide", - Type: resourcev1alpha1.PipelineResourceTypeImage, - Optional: true, - }, - }, - }, }, }, } @@ -104,20 +88,6 @@ func TestValidateResolvedTaskResources_ValidResources(t *testing.T) { }, }, }, - Outputs: map[string]*resourcev1alpha1.PipelineResource{ - "resource-to-provide": { - ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }, - "optional-resource-to-provide": { - ObjectMeta: metav1.ObjectMeta{Name: "example-image"}, - Spec: resourcev1alpha1.PipelineResourceSpec{ - Type: resourcev1alpha1.PipelineResourceTypeImage, - }, - }, - }, } if err := ValidateResolvedTaskResources(ctx, []v1beta1.Param{}, &v1beta1.Matrix{}, rtr); err != nil { t.Fatalf("Did not expect to see error when validating valid resolved TaskRun but saw %v", err) @@ -367,19 +337,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 +364,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{ @@ -434,27 +378,6 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { }, }, } - testrequiredinputandoutput := &v1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - Spec: v1beta1.TaskSpec{ - Resources: &v1beta1.TaskResources{ - Inputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredimageinput", - Type: resourcev1alpha1.PipelineResourceTypeImage, - Optional: false, - }, - }}, - Outputs: []v1beta1.TaskResource{{ - ResourceDeclaration: v1beta1.ResourceDeclaration{ - Name: "requiredimageoutput", - Type: resourcev1alpha1.PipelineResourceTypeImage, - Optional: false, - }, - }}, - }, - }, - } tcs := []struct { name string rtr *resources.ResolvedTaskResources @@ -470,28 +393,6 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { TaskSpec: &testoutput.Spec, Outputs: map[string]*resourcev1alpha1.PipelineResource{"wrong-resource-name": r}, }, - }, { - name: "input-resource-mismatch", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageinput.Spec, - Inputs: map[string]*resourcev1alpha1.PipelineResource{"testimageinput": r}, - }, - }, { - name: "input-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageinput.Spec, - }, - }, { - name: "output-resource-mismatch", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageoutput.Spec, - Outputs: map[string]*resourcev1alpha1.PipelineResource{"testimageoutput": r}, - }, - }, { - name: "output-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testimageoutput.Spec, - }, }, { name: "extra-input-resource", rtr: &resources.ResolvedTaskResources{ @@ -534,11 +435,6 @@ func TestValidateResolvedTaskResources_InvalidResources(t *testing.T) { rtr: &resources.ResolvedTaskResources{ TaskSpec: &testrequiredgitoutput.Spec, }, - }, { - name: "required-input-and-output-resource-missing", - rtr: &resources.ResolvedTaskResources{ - TaskSpec: &testrequiredinputandoutput.Spec, - }, }} for _, tc := range tcs { diff --git a/tekton/publish.yaml b/tekton/publish.yaml index d4730ce75c5..ecfb4b3707f 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 pullrequest-init workingdirinit resolvers sidecarlogresults" + default: "controller webhook entrypoint nop git-init pullrequest-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 46eead15f51..c944b78a86e 100644 --- a/test/conversion_test.go +++ b/test/conversion_test.go @@ -177,11 +177,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 = ` @@ -189,7 +184,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/hermetic_taskrun_test.go b/test/hermetic_taskrun_test.go index f6bb1eb056a..51202ab1f1b 100644 --- a/test/hermetic_taskrun_test.go +++ b/test/hermetic_taskrun_test.go @@ -59,7 +59,7 @@ func TestHermeticTaskRun(t *testing.T) { t.Run(test.desc, func(t *testing.T) { // first, run the task run with hermetic=false to prove that it succeeds regularTaskRunName := fmt.Sprintf("not-hermetic-%s", test.desc) - regularTaskRun := test.getTaskRun(t, regularTaskRunName, namespace, "") + regularTaskRun := getTaskRun(t, regularTaskRunName, namespace, "") t.Logf("Creating TaskRun %s, hermetic=false", regularTaskRunName) if _, err := c.V1beta1TaskRunClient.Create(ctx, regularTaskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun `%s`: %s", regularTaskRunName, err) @@ -71,7 +71,7 @@ func TestHermeticTaskRun(t *testing.T) { // now, run the task mode with hermetic mode // it should fail, since it shouldn't be able to access any network hermeticTaskRunName := fmt.Sprintf("hermetic-should-fail-%s", test.desc) - hermeticTaskRun := test.getTaskRun(t, hermeticTaskRunName, namespace, "hermetic") + hermeticTaskRun := getTaskRun(t, hermeticTaskRunName, namespace, "hermetic") t.Logf("Creating TaskRun %s, hermetic=true", hermeticTaskRunName) if _, err := c.V1beta1TaskRunClient.Create(ctx, hermeticTaskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun `%s`: %s", regularTaskRun.Name, err) @@ -107,6 +107,28 @@ spec: `, executionMode, name, namespace)) } +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)) +} + func unpriviligedTaskRun(t *testing.T, name, namespace, executionMode string) *v1beta1.TaskRun { t.Helper() return parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(` 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/yamls/v1beta1/pipelineruns/pipelinerun.yaml b/test/yamls/v1beta1/pipelineruns/pipelinerun.yaml index ba3841b4401..72443eea9ae 100644 --- a/test/yamls/v1beta1/pipelineruns/pipelinerun.yaml +++ b/test/yamls/v1beta1/pipelineruns/pipelinerun.yaml @@ -89,18 +89,6 @@ spec: # makes it explicit that it needs to run as root. securityContext: runAsUser: 0 - - name: write-digest - workingDir: $(workspaces.source.path) - # TODO(abayer): Using ko:// means we end up rebuilding the image, which can be annoying. Consider alternatives while ensuring - # we're always replacing the ko:// images with ones already built from our source... - image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter - # output of imagedigestexport [{"name":"image","digest":"sha256:eed29..660"}] - command: ["/ko-app/imagedigestexporter"] - securityContext: - runAsUser: 0 - args: - - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] - - -terminationMessagePath=$(params.CONTEXT)/image-digested - name: digest-to-results workingDir: $(workspaces.source.path) image: stedolan/jq diff --git a/third_party/google.golang.org/api/support/bundler/LICENSE b/third_party/google.golang.org/api/support/bundler/LICENSE deleted file mode 100644 index 263aa7a0c12..00000000000 --- a/third_party/google.golang.org/api/support/bundler/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2011 Google Inc. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.