Skip to content

Commit 4294a8b

Browse files
committed
Support running tests in kind
1 parent cd14e80 commit 4294a8b

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

tests/Makefile

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,29 @@ NODE_IP =
88
TAG = latest
99
PREFIX = test-runner
1010
KUBE_CONFIG_FOLDER = $${HOME}/.kube
11+
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
1112
SHOW_IC_LOGS = no
1213
PYTEST_ARGS =
1314

15+
.PHONY: build
1416
build:
1517
docker build -t $(PREFIX):$(TAG) -f docker/Dockerfile ..
1618

19+
.PHONY: run-tests
1720
run-tests:
18-
docker run --rm -v $(KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) --context=$(CONTEXT) --image=$(BUILD_IMAGE) --image-pull-policy=$(PULL_POLICY) --deployment-type=$(DEPLOYMENT_TYPE) --ic-type=$(IC_TYPE) --service=$(SERVICE) --node-ip=$(NODE_IP) --show-ic-logs=$(SHOW_IC_LOGS) $(PYTEST_ARGS)
21+
docker run --rm -v $(KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) --context=$(CONTEXT) --image=$(BUILD_IMAGE) --image-pull-policy=$(PULL_POLICY) --deployment-type=$(DEPLOYMENT_TYPE) --ic-type=$(IC_TYPE) --service=$(SERVICE) --node-ip=$(NODE_IP) --show-ic-logs=$(SHOW_IC_LOGS) $(PYTEST_ARGS)
22+
23+
.PHONY: run-tests-in-kind
24+
run-tests-in-kind:
25+
$(eval KIND_CLUSTER_IP=$(shell docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' kind-control-plane))
26+
sed -i "" "s|server:.*|server: https://$(KIND_CLUSTER_IP):6443|" $(KIND_KUBE_CONFIG_FOLDER)/config
27+
docker run --network=kind --rm -v $(KIND_KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) --context=kind-kind --image=$(BUILD_IMAGE) --image-pull-policy=$(PULL_POLICY) --deployment-type=$(DEPLOYMENT_TYPE) --ic-type=$(IC_TYPE) --service=nodeport --node-ip=$(KIND_CLUSTER_IP) --show-ic-logs=$(SHOW_IC_LOGS) $(PYTEST_ARGS)
28+
29+
.PHONY: create-kind-cluster
30+
create-kind-cluster:
31+
kind create cluster
32+
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
33+
34+
.PHONY: delete-kind-cluster
35+
delete-kind-cluster:
36+
kind delete cluster

tests/README.md

+30-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The project includes automated tests for testing the Ingress Controller in a Kubernetes cluster. The tests are written in Python3 and use the pytest framework.
44

5-
Below you will find the instructions on how to run the tests against a Minikube cluster. However, you are not limited to Minikube and can use other types of Kubernetes clusters. See the [Configuring the Tests](#configuring-the-tests) section to find out about various configuration options.
5+
Below you will find the instructions on how to run the tests against a Minikube and kind clusters. However, you are not limited to those options and can use other types of Kubernetes clusters. See the [Configuring the Tests](#configuring-the-tests) section to find out about various configuration options.
66

77
## Running Tests in Minikube
88

@@ -36,22 +36,47 @@ Run the tests:
3636
```
3737
The tests will use the Ingress Controller for NGINX with the default *nginx/nginx-ingress:edge* image. See the section below to learn how to configure the tests including the image and the type of NGINX -- NGINX or NGINX Plus.
3838

39+
## Running Tests in Kind
40+
41+
### Prerequisites:
42+
43+
* [Kind](https://kind.sigs.k8s.io/).
44+
* Docker.
45+
46+
#### Step 1 - Create a Kind Cluster
47+
48+
```bash
49+
$ make create-kind-cluster
50+
```
51+
52+
#### Step 2 - Run the Tests
53+
54+
**Note**: if you have the Ingress Controller deployed in the cluster, please uninstall it first, making sure to remove its namespace and RBAC resources.
55+
56+
Run the tests in Docker:
57+
```bash
58+
$ cd tests
59+
$ make build
60+
$ make run-tests-in-kind
61+
```
62+
The tests will use the Ingress Controller for NGINX with the default *nginx/nginx-ingress:edge* image. See the section below to learn how to configure the tests including the image and the type of NGINX -- NGINX or NGINX Plus.
63+
3964
## Configuring the Tests
4065

4166
The table below shows various configuration options for the tests. If you use Python3 to run the tests, use the command-line arguments. If you use Docker, use the [Makefile](Makefile) variables.
4267

4368

4469
| Command-line Argument | Makefile Variable | Description | Default |
4570
| :----------------------- | :------------ | :------------ | :----------------------- |
46-
| `--context` | `CONTEXT` | The context to use in the kubeconfig file. | `""` |
71+
| `--context` | `CONTEXT`, not supported by `run-tests-in-kind` target. | The context to use in the kubeconfig file. | `""` |
4772
| `--image` | `BUILD_IMAGE` | The Ingress Controller image. | `nginx/nginx-ingress:edge` |
4873
| `--image-pull-policy` | `PULL_POLICY` | The pull policy of the Ingress Controller image. | `IfNotPresent` |
4974
| `--deployment-type` | `DEPLOYMENT_TYPE` | The type of the IC deployment: deployment or daemon-set. | `deployment` |
5075
| `--ic-type` | `IC_TYPE` | The type of the Ingress Controller: nginx-ingress or nginx-ingress-plus. | `nginx-ingress` |
51-
| `--service` | `SERVICE` | The type of the Ingress Controller service: nodeport or loadbalancer. | `nodeport` |
52-
| `--node-ip` | `NODE_IP` | The public IP of a cluster node. Not required if you use the loadbalancer service (see --service argument). | `""` |
76+
| `--service` | `SERVICE`, not supported by `run-tests-in-kind` target. | The type of the Ingress Controller service: nodeport or loadbalancer. | `nodeport` |
77+
| `--node-ip` | `NODE_IP`, not supported by `run-tests-in-kind` target. | The public IP of a cluster node. Not required if you use the loadbalancer service (see --service argument). | `""` |
5378
| `--kubeconfig` | `N/A` | An absolute path to a kubeconfig file. | `~/.kube/config` or the value of the `KUBECONFIG` env variable |
54-
| `N/A` | `KUBE_CONFIG_FOLDER` | A path to a folder with a kubeconfig file. | `~/.kube/` |
79+
| `N/A` | `KUBE_CONFIG_FOLDER`, not supported by `run-tests-in-kind` target. | A path to a folder with a kubeconfig file. | `~/.kube/` |
5580
| `--show-ic-logs` | `SHOW_IC_LOGS` | A flag to control accumulating IC logs in stdout. | `no` |
5681
| `N/A` | `PYTEST_ARGS` | Any additional pytest command-line arguments (i.e `-m "smoke"`) | `""` |
5782

0 commit comments

Comments
 (0)