Prow will run ./e2e-tests.sh
with authentication mechanism using Kubernetes
Secrets and ./e2e-wi-tests.sh
with authentication mechanism using Workload
Identity.
E2E tests are tagged with // +build e2e
but tagging a Go file this way will
prevent the compiler from compiling the test code. To work around this, for the
test code we separate them into different files:
test/e2e
├── e2e_test.go
└── test_xxx.go
e2e_test.go
is the testing file entry point (tagged with e2e).test_xxx.go
are the test implementations (not tagged with e2e).
We leverage the test library in Eventing as much as possible for implementing the e2e tests. Logic specific to knative-gcp should be added under knative-gcp e2e test lib.
Run the following command:
SKIP_TESTS=true ./test/e2e-tests.sh --skip-teardowns
SKIP_TESTS
will skip the actual tests so only the cluster initialization is
run. --skip-teardowns
tells the script to not tear down the cluster. This
command runs the cluster initialization logic and leaves the cluster in a state
that's ready to run tests.
If you run into
Something went wrong: error creating deployer: --gcp-zone and --gcp-region cannot both be set
,
you may have set the ZONE
environment variable. Try unset ZONE
.
There are two ways to set up authentication mechanism.
- (GKE Specific) If you want to run E2E tests with Workload Identity as the authentication mechanism, please follow below instructions to configure the authentication mechanism with Workload Identity.
- If you want to run E2E tests with Kubernetes Secrets as the authentication mechanism, please follow below instructions to configure the authentication mechanism with Kubernetes Secrets.
-
A running Kubernetes cluster with knative-gcp installed and configured.
-
Create a Service Account for the Data Plane. Download a credential file and set
GOOGLE_APPLICATION_CREDENTIALS
env var. This is used by some tests(e.g.,TestSmokePullSubscription
) to authorize the Google SDK clients.cred_file=$(pwd)/cre-dataplane.json gcloud iam service-accounts keys create ${cred_file} --iam-account=cre-dataplane@$PROJECT_ID.iam.gserviceaccount.com export GOOGLE_APPLICATION_CREDENTIALS=${cred_file}
-
Broker with Pub/Sub Channel installed.
-
CloudSchedulerSource Prerequisites. Note that you only need to:
- Create with an App Engine application in your project.
-
CloudStorageSource Prerequisites. Note that you only need to:
- Enable the Cloud Storage API on your project.
- Give Google Cloud Storage permissions to publish to GCP Pub/Sub.
-
A docker repo containing the test images. Remember to specify the build tag
e2e
. -
(Optional) Note that if you plan on running metrics-related E2E tests using the StackDriver backend, you need to give your Service Account the
monitoring.metricWriter
role on your Google Cloud project:gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:${your_service_account}@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/monitoring.metricWriter
If you also plan on running tracing-related E2E tests using the StackDriver backend, your Service Account needs additional
cloudtrace.admin
role:gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:"${your_service_account}"@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/cloudtrace.admin
-
(Optional) Note that if plan on running tracing-related E2E tests using the Zipkin backend, you need to install zipkin-in-mem and patch the configmap
config-tracing
in theknative-eventing
namespace to use the Zipkin backend as the with patch-config-tracing-configmap-with-zipkin.yaml.kubectl patch configmap config-tracing -n knative-eventing --patch "\$(cat patch-config-tracing-configmap-with-zipkin.yaml)"
E2E_PROJECT_ID=<project name> \
go test --tags=e2e ./test/e2e/...
And count is supported too:
E2E_PROJECT_ID=<project name> \
go test --tags=e2e ./test/e2e/... --count=3
If you want to run a specific test:
E2E_PROJECT_ID=<project name> \
go test --tags=e2e ./test/e2e/... -run NameOfTest
For example, to run TestPullSubscription:
E2E_PROJECT_ID=<project name> \
go test --tags=e2e ./test/e2e/... -run TestPullSubscription
First, you'll have to modify clusterDefaults
in ConfigMap config-gcp-auth
.
You can directly edit the ConfigMap by:
kubectl edit configmap config-gcp-auth -n cloud-run-events
and replace the default-auth-config:
part with:
default-auth-config: |
clusterDefaults:
serviceAccountName: test-default-ksa
workloadIdentityMapping:
test-default-ksa: $PUBSUB_SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com
$PUBSUB_SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com
is the Pub/Sub
enabled Google Cloud Service Account.
Then, add -workloadIdentity=true
and -serviceAccountName=test-default-ksa
to
the go test
command.
For example,
E2E_PROJECT_ID=<project name> go test --tags=e2e ./test/e2e/... \
-workloadIdentity=true \
-serviceAccountName=test-default-ksa \
-run TestPullSubscription
-
Enable necessary APIs:
gcloud services enable compute.googleapis.com gcloud services enable container.googleapis.com
-
Install kubetest. (Note this is just a workaround because of kubernetes issue
-
Set the project you want to run E2E tests to be the default one with:
export PROJECT=<REPLACE_ME> gcloud config set core/project $PROJECT
If you want to run E2E tests with authentication mechanism using Kubernetes Secrets:
./test/e2e-tests.sh
If you want to run E2E tests with authentication mechanism using Workload Identity:
./test/e2e-wi-tests.sh
Note: this is only required when you run e2e tests locally with go test
commands. Running tests through e2e-tests.sh will publish the images
automatically.
The upload-test-images.sh
script can be used to
build and push the test images used by the e2e tests. It requires:
KO_DOCKER_REPO
to be set- You need to be
authenticated with your
KO_DOCKER_REPO
docker
to be installed
For images deployed in GCR, a docker tag is mandatory to avoid issues with using
latest
tag:
./test/upload-test-images.sh ./test/test_images e2e
sed -i 's@ko://knative.dev/eventing/test/test_images@ko://github.com/google/knative-gcp/vendor/knative.dev/eventing/test/test_images@g' vendor/knative.dev/eventing/test/test_images/*/*.yaml
./test/upload-test-images.sh ./vendor/knative.dev/eventing/test/test_images/ e2e
To run the script for all end to end test images:
./test/upload-test-images.sh ./test/test_images
sed -i 's@ko://knative.dev/eventing/test/test_images@ko://github.com/google/knative-gcp/vendor/knative.dev/eventing/test/test_images@g' vendor/knative.dev/eventing/test/test_images/*/*.yaml
./test/upload-test-images.sh ./vendor/knative.dev/eventing/test/test_images/
New test images should be placed in ./test/test_images
. For each image create
a new sub-folder and include a Go file that will be an entry point to the
application. This Go file should use the package main
and include the function
main()
. It is a good practice to include a README
file as well. When
uploading test images, ko
will build an image from this folder and upload to
the Docker repository configured as
KO_DOCKER_REPO
.
Each PR will trigger E2E tests. For failed tests, follow the
prow links on the PR page. Such links are in the format of
https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/google_knative-gcp/[PR ID]/[TEST NAME]/[TEST ID]
, e.g.
https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/google_knative-gcp/1153/pull-google-knative-gcp-integration-tests/1267481606424104960
.
If the prow page doesn't provide any useful information, check out the full logs dump.
- The control plane pods (in
cloud-run-events
namespace) logs dump are athttps://console.cloud.google.com/storage/browser/knative-prow/pr-logs/pull/google_knative-gcp/[PR ID]/[TEST NAME]/[TEST ID]/artifacts/controller-logs/
. - The data plane pods logs dump are at
https://console.cloud.google.com/storage/browser/knative-prow/pr-logs/pull/google_knative-gcp/[PR ID]/[TEST NAME]/[TEST ID]/artifacts/pod-logs/
.
Add CI=true
to the go test
command.
- The data plane pods logs dump are at
$GOPATH/src/github.com/google/knative-gcp/test/e2e/artifacts/pod-logs
.
For example:
CI=true E2E_PROJECT_ID=$PROJECT_ID \
go test --tags=e2e ./test/e2e/...