|
| 1 | +# E2E Testing the Operator SDK |
| 2 | +The operator-sdk is automatically tested using both unit tests and e2e tests anytime |
| 3 | +a pull request is made. The e2e tests ensure that the operator-sdk acts as intended by |
| 4 | +simulating how a typical user might use the SDK. The automated tests test each PR and run in |
| 5 | +Travis CI, and Travis CI has a couple of features to simplify the e2e tests that we run. |
| 6 | +However, it is possible to run the e2e tests locally as well. |
| 7 | + |
| 8 | +## Running the E2E Tests Locally |
| 9 | +To run the tests locally, the tests either need access to a remote kubernetes cluster or a |
| 10 | +local minikube instance running on the machine. |
| 11 | + |
| 12 | +### Remote Kubernetes Instance |
| 13 | +To run the tests on a remote cluster, the tests need access to a remote kubernetes cluster |
| 14 | +running kubernetes 1.10 as well as a docker image repo to push the operator image to, |
| 15 | +such as quay.io. To run the test, use this command: |
| 16 | +``` |
| 17 | +$ go test ./test/e2e/... -kubeconfig "path-to-config" -image "<repository>:<tag>" |
| 18 | +``` |
| 19 | + |
| 20 | +This will run the tests on the cluster specified by the provided kubeconfig and the |
| 21 | +memcached-operator image that is built will be pushed to `<repository>:<tag>`. |
| 22 | + |
| 23 | +### Local Minikube Instance |
| 24 | +To run the e2e tests on a local minikube cluster, the minikube instance must be |
| 25 | +started and the host's docker client must be linked to the minikube instance's docker daemon, |
| 26 | +which allows the host to add images to the minikube's local image registry directly. |
| 27 | +To do this, run these commands: |
| 28 | +``` |
| 29 | +$ minikube start --kubernetes-version v1.10.0 |
| 30 | +$ eval $(minikube docker-env) |
| 31 | +``` |
| 32 | + |
| 33 | +Once that is complete, the test can be run with this command: |
| 34 | +``` |
| 35 | +$ go test ./test/e2e/... |
| 36 | +``` |
| 37 | + |
| 38 | +The test will run using the kube config in $HOME/.kube/config (which is where the minikube |
| 39 | +kubeconfig is placed by default) and the operator image will be built and stored on the |
| 40 | +minikube instance's local image registry. |
| 41 | + |
| 42 | +## Cleanup of the E2E Tests |
| 43 | +The e2e tests create a new project using the operator-sdk to run in the provided |
| 44 | +cluster. The tests are designed to cleanup everything that gets created, but some errors |
| 45 | +can cause these cleanups to fail. For example, if a segfault occurs or a user kills the |
| 46 | +testing process, the cleanup functions will not run. To manually clean up a test: |
| 47 | +1. Delete the created project in $GOPATH/src/github.com/example-inc/memcached-operator |
| 48 | +2. Delete the namespaces that the tests run in, which also deletes any resources created |
| 49 | +within the namespaces. The namespaces start with `memcached-memcached-group`. |
| 50 | +3. Delete the CRD (`kubectl delete -f deploy/crd.yaml`). |
0 commit comments