|
| 1 | +## End-to-end tests |
| 2 | + |
| 3 | +The end-to-end tests use the [Ginkgo framework](https://onsi.github.io/ginkgo/) and allow to test the operator against a real cluster in the following scenarios: |
| 4 | +- building and deploying the operator image off of the current code |
| 5 | +- using a specific image or a specific downstream build |
| 6 | + |
| 7 | +Deployment of the operator itself can be done by: |
| 8 | +- deploying with or without OLM, |
| 9 | +- or deploying the downstream bundle in both online and air-gapped scenarios |
| 10 | + |
| 11 | +To run the end-to-end tests, make sure you have an active connection to a cluster in your current [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) and run: |
| 12 | +```shell |
| 13 | +# Check your current context |
| 14 | +$ kubectl config current-context |
| 15 | +$ make test-e2e |
| 16 | +``` |
| 17 | + |
| 18 | +### Configuration |
| 19 | + |
| 20 | +The behavior is configurable using the following environment variables: |
| 21 | + |
| 22 | +| Name | Type | Description | Default value | Example | |
| 23 | +|------------------------------------------------------------------------------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|---------------------------------------------------------| |
| 24 | +| `BACKSTAGE_OPERATOR_TEST_MODE` | string | The test mode:<br>- if not set, it will call `make deploy`<br>- `olm`: it will call `make deploy-olm`<br>- `rhdh-latest` or `rhdh-next`: it will install the operator using the [`install-rhdh-catalog-source.sh`](../../.rhdh/scripts/install-rhdh-catalog-source.sh) script<br>- `rhdh-airgap`: it will install the operator using the [`prepare-restricted-environment.sh`](../../.rhdh/scripts/prepare-restricted-environment.sh) script. | | `rhdh-latest` | |
| 25 | +| `IMG` (or any variables from the Makefile that are used by `make deploy` or `make deploy-olm`) | string | The image to use. Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is not set or set to `olm` | `VERSION` defined in [`Makefile`](../../Makefile) | `quay.io/janus-idp/operator:0.0.1-latest` | |
| 26 | +| `BACKSTAGE_OPERATOR_TESTS_BUILD_IMAGES` | bool | If set to `true`, it will build the operator image with `make image-build`.<br>Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is not set or set to `olm`. | | `false` | |
| 27 | +| `BACKSTAGE_OPERATOR_TESTS_PUSH_IMAGES` | bool | If set to `true`, it will push the operator image with `make image-push`.<br>Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is not set or set to `olm`. | | `false` | |
| 28 | +| `BACKSTAGE_OPERATOR_TESTS_PLATFORM` | string | The platform type, to directly load the operator image if supported instead of pushing it.<br>Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is not set or set to `olm`.br>Supported values: [`kind`](#building-and-testing-local-changes-on-kind), [`k3d`](#building-and-testing-local-changes-on-k3d), [`minikube`](#building-and-testing-local-changes-on-minikube) | | `kind` | |
| 29 | +| `BACKSTAGE_OPERATOR_TESTS_KIND_CLUSTER` | string | Name of the local KinD cluster to use. Relevant only if `BACKSTAGE_OPERATOR_TESTS_PLATFORM` is `kind`. | `kind` | `kind-local-k8s-cluster` | |
| 30 | +| `BACKSTAGE_OPERATOR_TESTS_K3D_CLUSTER` | string | Name of the local k3d cluster to use. Relevant only if `BACKSTAGE_OPERATOR_TESTS_PLATFORM` is `k3d`. | `k3s-default` | `k3d-local-k8s-cluster` | |
| 31 | +| `BACKSTAGE_OPERATOR_TESTS_AIRGAP_INDEX_IMAGE` | string | Index image to use in the airgap scenario.<br>Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is `rhdh-airgap`. | `quay.io/rhdh/iib:latest-v4.14-x86_64` | `registry.redhat.io/redhat/redhat-operator-index:v4.14` | |
| 32 | +| `BACKSTAGE_OPERATOR_TESTS_AIRGAP_OPERATOR_VERSION` | string | Operator version to use in the airgap scenario.<br>Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is `rhdh-airgap`. | `v1.1.0` | `v1.1.0` | |
| 33 | +| `BACKSTAGE_OPERATOR_TESTS_AIRGAP_MIRROR_REGISTRY` | string | Existing mirror registry to use in the airgap scenario.<br>Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is `rhdh-airgap`<br>. | | `my-registry.example.com` | |
| 34 | + |
| 35 | +### Examples |
| 36 | + |
| 37 | +#### Testing the operator available for the VERSION (default) |
| 38 | + |
| 39 | +In this scenario, you want to run the E2E test suite against the operator image corresponding to the `VERSION` declared in the project [`Makefile`](../../Makefile), which should be publicly available at `quay.io/janus-idp/operator:<VERSION>`. |
| 40 | + |
| 41 | +This is the default behavior. |
| 42 | + |
| 43 | +This should work on any Kubernetes or OpenShift cluster: |
| 44 | + |
| 45 | +```shell |
| 46 | +$ make test-e2e |
| 47 | +``` |
| 48 | + |
| 49 | +#### Testing a specific image (e.g. PR image) |
| 50 | + |
| 51 | +In this scenario, you want to run the E2E test suite against an existing operator image. |
| 52 | + |
| 53 | +This should work on any Kubernetes or OpenShift cluster: |
| 54 | + |
| 55 | +```shell |
| 56 | +# if the tag is already published and available at the default location: quay.io/janus-idp/operator |
| 57 | +$ make test-e2e VERSION=0.2.0-3d1c1e0 |
| 58 | + |
| 59 | +# or you can override the full image repo name |
| 60 | +$ make test-e2e IMG=my.registry.example.com/operator:0.2.0-3d1c1e0 |
| 61 | +``` |
| 62 | + |
| 63 | +Note that `VERSION` and `IMG` override the respective variables declared in the project [`Makefile`](../../Makefile). |
| 64 | + |
| 65 | +#### Building and testing local changes on supported local clusters |
| 66 | + |
| 67 | +In this scenario, you are iterating locally, and want to run the E2E test suite against your local changes. You are already using a local cluster like [`kind`](https://kind.sigs.k8s.io/), [`k3d`](https://k3d.io/) or [`minikube`](https://minikube.sigs.k8s.io/docs/), which provide the ability to import images into the cluster nodes. |
| 68 | + |
| 69 | +To do so, you can: |
| 70 | +1. set `BACKSTAGE_OPERATOR_TESTS_BUILD_IMAGES` to `true`, which will result in building the operator image from the local changes, |
| 71 | +2. and set `BACKSTAGE_OPERATOR_TESTS_PLATFORM` to a supported local cluster, which will result in loading the image built directly in that cluster (without having to push to a separate registry). |
| 72 | + |
| 73 | +##### `kind` |
| 74 | + |
| 75 | +```shell |
| 76 | +$ kind create cluster |
| 77 | +$ make test-e2e \ |
| 78 | + BACKSTAGE_OPERATOR_TESTS_BUILD_IMAGES=true \ |
| 79 | + BACKSTAGE_OPERATOR_TESTS_PLATFORM=kind |
| 80 | +``` |
| 81 | + |
| 82 | +##### `k3d` |
| 83 | + |
| 84 | +```shell |
| 85 | +$ k3d cluster create |
| 86 | +$ make test-e2e \ |
| 87 | + BACKSTAGE_OPERATOR_TESTS_BUILD_IMAGES=true \ |
| 88 | + BACKSTAGE_OPERATOR_TESTS_PLATFORM=k3d |
| 89 | +``` |
| 90 | + |
| 91 | +##### `minikube` |
| 92 | + |
| 93 | +```shell |
| 94 | +$ minikube start |
| 95 | +$ make test-e2e \ |
| 96 | + BACKSTAGE_OPERATOR_TESTS_BUILD_IMAGES=true \ |
| 97 | + BACKSTAGE_OPERATOR_TESTS_PLATFORM=minikube |
| 98 | +``` |
| 99 | + |
| 100 | +#### Testing a specific version using OLM |
| 101 | + |
| 102 | +In this scenario, you want to leverage the [Operator Lifecycle Manager (OLM)](https://olm.operatorframework.io/) to deploy the Operator. |
| 103 | + |
| 104 | +This requires OLM to be installed in the cluster. |
| 105 | + |
| 106 | +```shell |
| 107 | +$ make test-e2e BACKSTAGE_OPERATOR_TEST_MODE=olm |
| 108 | +``` |
| 109 | + |
| 110 | +#### Testing a downstream build of Red Hat Developer Hub (RHDH) |
| 111 | + |
| 112 | +In this scenario, you want to run the E2E tests against a downstream build of RHDH. |
| 113 | + |
| 114 | +This works only against OpenShift clusters. So make sure you are logged in to the OpenShift cluster using the `oc` command. See [Logging in to the OpenShift CLI](https://docs.openshift.com/container-platform/4.14/cli_reference/openshift_cli/getting-started-cli.html#cli-logging-in_cli-developer-commands) for more details. |
| 115 | + |
| 116 | +You can check your current context by running `oc config current-context` or `kubectl config current-context`. |
| 117 | + |
| 118 | +If testing a CI build, please follow the instructions in [Installing CI builds of Red Hat Developer Hub](../../.rhdh/docs/installing-ci-builds.adoc) to add your Quay token to the cluster. |
| 119 | + |
| 120 | +```shell |
| 121 | +# latest |
| 122 | +$ make test-e2e BACKSTAGE_OPERATOR_TEST_MODE=rhdh-latest |
| 123 | + |
| 124 | +# or next |
| 125 | +$ make test-e2e BACKSTAGE_OPERATOR_TEST_MODE=rhdh-next |
| 126 | +``` |
| 127 | + |
| 128 | +#### Airgap testing of Red Hat Developer Hub (RHDH) |
| 129 | + |
| 130 | +In this scenario, you want to run the E2E tests against an OpenShift cluster running in a restricted network. For this, the command below will make sure to prepare it by copying all the necessary images to a mirror registry, then deploy the operator. |
| 131 | + |
| 132 | +Make sure you are logged in to the OpenShift cluster using the `oc` command. See [Logging in to the OpenShift CLI](https://docs.openshift.com/container-platform/4.14/cli_reference/openshift_cli/getting-started-cli.html#cli-logging-in_cli-developer-commands) for more details. |
| 133 | + |
| 134 | +You can check your current context by running `oc config current-context` or `kubectl config current-context`. |
| 135 | + |
| 136 | +Also make sure to read the prerequisites in [Installing Red Hat Developer Hub (RHDH) in restricted environments](../../.rhdh/docs/airgap.adoc). |
| 137 | + |
| 138 | +```shell |
| 139 | +# if you want to have a mirror registry to be created for you as part of the airgap environment setup |
| 140 | +$ make test-e2e BACKSTAGE_OPERATOR_TEST_MODE=rhdh-airgap |
| 141 | + |
| 142 | +# or if you already have a mirror registry available and reachable from within your cluster |
| 143 | +$ make test-e2e \ |
| 144 | + BACKSTAGE_OPERATOR_TEST_MODE=rhdh-airgap \ |
| 145 | + BACKSTAGE_OPERATOR_TESTS_AIRGAP_MIRROR_REGISTRY=my-registry.example.com |
| 146 | +``` |
0 commit comments