From 9ee828276c840ff94fdb654c719f93430880a1f7 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Wed, 9 Oct 2019 11:58:53 +0100 Subject: [PATCH] Use kubectl create instead of apply When running YAML E2E tests, use kubectl create instead of apply, so that example can use generateName, which is a best practice for run objects (TaskRun/PipelineRun). Using "create" also exposed name conflicts for several resources all named the same. Luckily the content of those secret was the same, so we had no race condition in the past, but it's best to avoid side effects between tests as much as possible and keep resource names uniques across examples. With this change we start running taskrun tests again, and it turns out the gitlab test is broken because of a broken gitlab URL. Introduce a subfolder for examples that are valid but that we don't want to run in CI because they need some access to a resource which is not available. Fixes #1397 --- examples/pipelineruns/output-pipelinerun.yaml | 4 ++-- examples/pipelineruns/pipelinerun.yaml | 10 +++++----- examples/taskruns/build-push-kaniko.yaml | 10 +++++----- examples/taskruns/configmap.yaml | 6 +++--- examples/taskruns/{ => no-ci}/gitlab.yaml | 0 examples/taskruns/secret-env.yaml | 4 ++-- examples/taskruns/secret-volume-params.yaml | 5 +++-- examples/taskruns/secret-volume.yaml | 4 ++-- examples/taskruns/steptemplate-env-merge.yaml | 3 +++ examples/taskruns/task-multiple-output-image.yaml | 8 ++++---- examples/taskruns/task-output-image.yaml | 12 ++++++------ examples/taskruns/task-volume-args.yaml | 5 +++-- test/e2e-common.sh | 4 ++-- 13 files changed, 40 insertions(+), 35 deletions(-) rename examples/taskruns/{ => no-ci}/gitlab.yaml (100%) diff --git a/examples/pipelineruns/output-pipelinerun.yaml b/examples/pipelineruns/output-pipelinerun.yaml index 67eb4b86e1f..84446760c18 100644 --- a/examples/pipelineruns/output-pipelinerun.yaml +++ b/examples/pipelineruns/output-pipelinerun.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-git + name: skaffold-git-output-pipelinerun spec: type: git params: @@ -102,4 +102,4 @@ spec: resources: - name: source-repo resourceRef: - name: skaffold-git + name: skaffold-git-output-pipelinerun diff --git a/examples/pipelineruns/pipelinerun.yaml b/examples/pipelineruns/pipelinerun.yaml index ee16639e37c..e00261dd292 100644 --- a/examples/pipelineruns/pipelinerun.yaml +++ b/examples/pipelineruns/pipelinerun.yaml @@ -16,7 +16,7 @@ spec: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: default-cluster-admin + generateName: default-cluster-admin- subjects: - kind: ServiceAccount name: default @@ -29,7 +29,7 @@ roleRef: apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-image-leeroy-web + name: skaffold-image-leeroy-web-pipelinerun spec: type: image params: @@ -39,7 +39,7 @@ spec: apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-git + name: skaffold-git-pipelinerun spec: type: git params: @@ -250,10 +250,10 @@ spec: resources: - name: source-repo resourceRef: - name: skaffold-git + name: skaffold-git-pipelinerun - name: web-image resourceRef: - name: skaffold-image-leeroy-web + name: skaffold-image-leeroy-web-pipelinerun - name: app-image resourceRef: name: skaffold-image-leeroy-app diff --git a/examples/taskruns/build-push-kaniko.yaml b/examples/taskruns/build-push-kaniko.yaml index 532d5f108a4..08b30bb7034 100644 --- a/examples/taskruns/build-push-kaniko.yaml +++ b/examples/taskruns/build-push-kaniko.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-image-leeroy-web + name: skaffold-image-leeroy-web-build-push-kaniko spec: type: image params: @@ -14,7 +14,7 @@ spec: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: default-cluster-admin + generateName: default-cluster-admin- subjects: - kind: ServiceAccount name: default @@ -27,7 +27,7 @@ roleRef: apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-git + name: skaffold-git-build-push-kaniko spec: type: git params: @@ -82,7 +82,7 @@ spec: resources: - name: workspace resourceRef: - name: skaffold-git + name: skaffold-git-build-push-kaniko params: - name: pathToDockerFile value: Dockerfile @@ -92,4 +92,4 @@ spec: resources: - name: builtImage resourceRef: - name: skaffold-image-leeroy-web + name: skaffold-image-leeroy-web-build-push-kaniko diff --git a/examples/taskruns/configmap.yaml b/examples/taskruns/configmap.yaml index 1c6038ee533..067d336a5cf 100644 --- a/examples/taskruns/configmap.yaml +++ b/examples/taskruns/configmap.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: config-for-testing + name: config-for-testing-configmaps data: test.data: tasks are my jam --- @@ -22,7 +22,7 @@ spec: - name: TEST_DATA valueFrom: configMapKeyRef: - name: config-for-testing + name: config-for-testing-configmaps key: test.data volumeMounts: - name: config-volume @@ -30,4 +30,4 @@ spec: volumes: - name: config-volume configMap: - name: config-for-testing + name: config-for-testing-configmaps diff --git a/examples/taskruns/gitlab.yaml b/examples/taskruns/no-ci/gitlab.yaml similarity index 100% rename from examples/taskruns/gitlab.yaml rename to examples/taskruns/no-ci/gitlab.yaml diff --git a/examples/taskruns/secret-env.yaml b/examples/taskruns/secret-env.yaml index 7f1d326842e..0b8c2ba74d5 100644 --- a/examples/taskruns/secret-env.yaml +++ b/examples/taskruns/secret-env.yaml @@ -1,7 +1,7 @@ kind: Secret apiVersion: v1 metadata: - name: secret-password + name: secret-env-password stringData: ninja: SECRET_PASSWORD --- @@ -22,5 +22,5 @@ spec: - name: SECRET_PASSWORD valueFrom: secretKeyRef: - name: secret-password + name: secret-env-password key: ninja diff --git a/examples/taskruns/secret-volume-params.yaml b/examples/taskruns/secret-volume-params.yaml index ba8744901d0..77d505a83b1 100644 --- a/examples/taskruns/secret-volume-params.yaml +++ b/examples/taskruns/secret-volume-params.yaml @@ -1,7 +1,7 @@ kind: Secret apiVersion: v1 metadata: - name: secret-password + name: secret-vol-param-password stringData: ninja: SECRET_PASSWORD --- @@ -15,6 +15,7 @@ spec: params: - name: SCNAME description: Name of secret + type: string steps: - image: ubuntu command: @@ -33,4 +34,4 @@ spec: inputs: params: - name: SCNAME - value: secret-password + value: secret-vol-param-password diff --git a/examples/taskruns/secret-volume.yaml b/examples/taskruns/secret-volume.yaml index 1074e5e34b6..fcff74a2947 100644 --- a/examples/taskruns/secret-volume.yaml +++ b/examples/taskruns/secret-volume.yaml @@ -1,7 +1,7 @@ kind: Secret apiVersion: v1 metadata: - name: secret-password + name: secret-vol-password stringData: ninja: SECRET_PASSWORD --- @@ -25,4 +25,4 @@ spec: volumes: - name: secret-volume secret: - secretName: secret-password + secretName: secret-vol-password diff --git a/examples/taskruns/steptemplate-env-merge.yaml b/examples/taskruns/steptemplate-env-merge.yaml index 77b1069f21e..89b76b85bb7 100644 --- a/examples/taskruns/steptemplate-env-merge.yaml +++ b/examples/taskruns/steptemplate-env-merge.yaml @@ -19,11 +19,14 @@ spec: params: - name: FOO description: FOO variable + type: string - name: BAR description: BAR variable + type: string - name: FOOBAR description: FOOBAR variable default: foobar + type: string steps: # Test the environment variables are set in the task - name: foo diff --git a/examples/taskruns/task-multiple-output-image.yaml b/examples/taskruns/task-multiple-output-image.yaml index dc467b7804d..47ed8ab3cd8 100644 --- a/examples/taskruns/task-multiple-output-image.yaml +++ b/examples/taskruns/task-multiple-output-image.yaml @@ -24,7 +24,7 @@ spec: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: default-cluster-admin + generateName: default-cluster-admin- subjects: - kind: ServiceAccount name: default @@ -37,7 +37,7 @@ roleRef: apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-git + name: skaffold-git-multiple-output-image spec: type: git params: @@ -46,7 +46,7 @@ spec: - name: url value: https://github.com/GoogleContainerTools/skaffold --- -# This task is currently hardcoding a index.json file instead of +# 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/v1alpha1 @@ -117,7 +117,7 @@ spec: resources: - name: sourcerepo resourceRef: - name: skaffold-git + name: skaffold-git-multiple-output-image outputs: resources: - name: builtImage1 diff --git a/examples/taskruns/task-output-image.yaml b/examples/taskruns/task-output-image.yaml index c9c6e839c37..5bbca82424d 100644 --- a/examples/taskruns/task-output-image.yaml +++ b/examples/taskruns/task-output-image.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-image-leeroy-web + name: skaffold-image-leeroy-web-output-image spec: type: image params: @@ -14,7 +14,7 @@ spec: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: default-cluster-admin + generateName: default-cluster-admin- subjects: - kind: ServiceAccount name: default @@ -27,7 +27,7 @@ roleRef: apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: - name: skaffold-git + name: skaffold-git-output-image spec: type: git params: @@ -36,7 +36,7 @@ spec: - name: url value: https://github.com/GoogleContainerTools/skaffold --- -# This task is currently hardcoding a index.json file instead of +# 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/v1alpha1 @@ -95,9 +95,9 @@ spec: resources: - name: sourcerepo resourceRef: - name: skaffold-git + name: skaffold-git-output-image outputs: resources: - name: builtImage resourceRef: - name: skaffold-image-leeroy-web + name: skaffold-image-leeroy-web-output-image diff --git a/examples/taskruns/task-volume-args.yaml b/examples/taskruns/task-volume-args.yaml index 84feed2f2d2..3b90241312c 100644 --- a/examples/taskruns/task-volume-args.yaml +++ b/examples/taskruns/task-volume-args.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: config-for-testing + name: config-for-testing-volume-args data: test.data: tasks are my jam --- @@ -15,6 +15,7 @@ spec: params: - name: CFGNAME description: Name of config map + type: string steps: - name: read image: ubuntu @@ -30,4 +31,4 @@ spec: inputs: params: - name: CFGNAME - value: config-for-testing + value: config-for-testing-volume-args diff --git a/test/e2e-common.sh b/test/e2e-common.sh index a0da61587aa..856c265c3a3 100755 --- a/test/e2e-common.sh +++ b/test/e2e-common.sh @@ -94,8 +94,8 @@ function create_resources() { echo ">> Creating resources ${resource}" # Applying the resources, either *taskruns or * *pipelineruns - for file in $(find ${REPO_ROOT_DIR}/examples/${resource}s/ -name *.yaml | sort); do - perl -p -e 's/gcr.io\/christiewilson-catfactory/$ENV{KO_DOCKER_REPO}/g' ${file} | ko apply -f - || return 1 + for file in $(find ${REPO_ROOT_DIR}/examples/${resource}s/ -name *.yaml -not -path "${REPO_ROOT_DIR}/examples/${resource}s/no-ci/*" | sort); do + perl -p -e 's/gcr.io\/christiewilson-catfactory/$ENV{KO_DOCKER_REPO}/g' ${file} | ko create -f - || return 1 done }