Skip to content

Commit 9d9a269

Browse files
committed
Run conformance tests in pod on cluster
1 parent e04cc27 commit 9d9a269

File tree

4 files changed

+119
-39
lines changed

4 files changed

+119
-39
lines changed

conformance/Makefile

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
NKG_TAG = edge
22
NKG_PREFIX = nginx-kubernetes-gateway
3-
GATEWAY_CLASS = nginx
4-
SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect
5-
EXEMPT_FEATURES = ReferenceGrant
63
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
74
TAG = latest
85
PREFIX = conformance-test-runner
6+
NGINX_IMAGE=$(shell yq '.spec.template.spec.containers[1].image as $$nginx_ver | $$nginx_ver' ../deploy/manifests/deployment.yaml)
97
.DEFAULT_GOAL := help
108

119
.PHONY: help
@@ -14,17 +12,20 @@ help: Makefile ## Display this help
1412

1513
.PHONY: build-test-runner-image
1614
build-test-runner-image: ## Build conformance test runner image
17-
docker build -t $(PREFIX):$(TAG) -f tests/Dockerfile ..
15+
docker build -t $(PREFIX):$(TAG) -f tests/Dockerfile ..
1816

1917
.PHONY: create-kind-cluster
2018
create-kind-cluster: ## Create a kind cluster
21-
kind create cluster --image kindest/node:v1.27.1
19+
kind create cluster --image kindest/node:v1.27.1
2220
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
2321

2422
.PHONY: prepare-nkg
25-
prepare-nkg: ## Build and load NKG container on configured kind cluster
23+
prepare-nkg: ## Build and load NKG and NGINX containers on configured kind cluster
2624
cd .. && make PREFIX=$(NKG_PREFIX) TAG=$(NKG_TAG) container
2725
kind load docker-image $(NKG_PREFIX):$(NKG_TAG)
26+
docker pull $(NGINX_IMAGE)
27+
kind load docker-image $(NGINX_IMAGE)
28+
yq -i 'with(.spec.template.spec.containers[0]; .image = "$(NKG_PREFIX):$(NKG_TAG)" | .imagePullPolicy = "Never")' ../deploy/manifests/deployment.yaml
2829

2930
.PHONY: install-nkg
3031
install-nkg: ## Install NKG with provisioner on configured kind cluster
@@ -36,16 +37,17 @@ install-nkg: ## Install NKG with provisioner on configured kind cluster
3637
kubectl apply -f ../deploy/manifests/rbac.yaml
3738
kubectl apply -f ../deploy/manifests/gatewayclass.yaml
3839
kubectl apply -f ../deploy/manifests/service/nodeport.yaml
39-
kubectl apply -f provisioner/provisioner.yaml
40-
41-
.PHONY: update-test-kind-config
42-
update-test-kind-config: ## Update kind config
43-
sed -ir "s|server:.*|server: https://kind-control-plane:6443|" $(KIND_KUBE_CONFIG_FOLDER)/config
40+
yq '(select(di != 3))' provisioner/provisioner.yaml | kubectl apply -f -
41+
yq '(select(.spec.template.spec.containers[].image) | .spec.template.spec.containers[].image="$(NKG_PREFIX):$(NKG_TAG)" | .spec.template.spec.containers[].imagePullPolicy = "Never")' provisioner/provisioner.yaml | kubectl apply -f -
4442

4543
.PHONY: run-conformance-tests
46-
run-conformance-tests: update-test-kind-config ## Run conformance tests
47-
docker run --network=kind --rm -v $(KIND_KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) \
48-
go test -timeout 25m -v . -tags conformance -args --gateway-class=$(GATEWAY_CLASS) --debug --supported-features=$(SUPPORTED_FEATURES) --exempt-features=$(EXEMPT_FEATURES)
44+
run-conformance-tests: ## Run conformance tests
45+
kind load docker-image $(PREFIX):$(TAG)
46+
yq '(select(di != 3))' tests/conformance_spec.yaml | kubectl apply -f -
47+
yq '(select(.spec.containers[].image) | .spec.containers[].image="$(PREFIX):$(TAG)")' tests/conformance_spec.yaml | kubectl apply -f -
48+
sleep 5
49+
kubectl logs conformance --follow
50+
kubectl delete -f tests/conformance_spec.yaml
4951

5052
.PHONY: uninstall-nkg
5153
uninstall-nkg: ## Uninstall NKG on configured kind cluster
@@ -54,7 +56,11 @@ uninstall-nkg: ## Uninstall NKG on configured kind cluster
5456
kubectl delete -f ../deploy/manifests/namespace.yaml
5557
kubectl delete clusterrole nginx-gateway-provisioner
5658
kubectl delete clusterrolebinding nginx-gateway-provisioner
57-
59+
60+
.PHONY: undo-image-update
61+
undo-image-update: ## Undo the NKG image name and tag in deployment manifest
62+
git checkout -- ../deploy/manifests/deployment.yaml
63+
5864
.PHONY: delete-kind-cluster
5965
delete-kind-cluster: ## Delete kind cluster
6066
kind delete cluster

conformance/README.md

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [kind](https://kind.sigs.k8s.io/).
66
* Docker.
77
* Golang.
8+
* [yq](https://github.com/mikefarah/yq/#macos--linux-via-homebrew)
89

910
**Note**: all commands in steps below are executed from the ```conformance``` directory
1011

@@ -29,49 +30,38 @@ update-test-kind-config Update kind config
2930
$ make create-kind-cluster
3031
```
3132

32-
### Step 2 - Update NKG deployment and provisioner manifests
33-
**Note**: this step is only required when user wants to run conformance tests using locally built image of Nginx Kubernetes Gateway
34-
* Set NKG_PREFIX=<repo_name> NKG_TAG=<image_tag> to preferred values.
35-
* Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block.
36-
* Navigate to `conformance/provisioner` and update values in `provisioner.yaml` as specified in below code-block.
37-
* Save the changes.
38-
```
39-
.
40-
..
41-
containers:
42-
- image: <repo_name>:<image_tag>
43-
imagePullPolicy: Never
44-
..
45-
.
46-
```
47-
48-
### Step 3 - Build and load Nginx Kubernetes Gateway container to configured kind cluster
49-
**Note**: this step is only required when user wants to run conformance tests using locally built image of Nginx Kubernetes Gateway
33+
### Step 2 - Build Nginx Kubernetes Gateway container and load it and the NGINX container to configured kind cluster
5034

5135
```bash
5236
$ make NKG_PREFIX=<repo_name> NKG_TAG=<image_tag> prepare-nkg
5337

5438
```
55-
### Step 4 - Build conformance test runner image
39+
### Step 3 - Build conformance test runner image
5640
```bash
5741
$ make build-test-runner-image
5842
```
5943

60-
### Step 5 - Install Nginx Kubernetes Gateway
44+
### Step 4 - Install Nginx Kubernetes Gateway
6145
```bash
62-
$ make install-nkg
46+
$ make NKG_PREFIX=<repo_name> NKG_TAG=<image_tag> install-nkg
6347
```
6448

65-
### Step 6 - Run Gateway conformance tests
49+
### Step 5 - Run Gateway conformance tests
6650
```bash
67-
$ make run-conformance-tests
51+
$ make NKG_PREFIX=<repo_name> NKG_TAG=<image_tag> run-conformance-tests
6852
```
6953

70-
### Step 7 - Uninstall Nginx Kubernetes Gateway
54+
### Step 6 - Uninstall Nginx Kubernetes Gateway
7155
```bash
7256
$ make uninstall-nkg
7357
```
7458

59+
### Step 7 - Revert changes to the NKG deployment manifest
60+
**Warning**: `make undo-image-update` will hard reset changes to the deploy/manifests/deployment.yaml file!
61+
```bash
62+
$ make undo-image-update
63+
```
64+
7565
### Step 8 - Delete kind cluster
7666
```bash
7767
$ make delete-kind-cluster

conformance/tests/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ COPY --link go.sum /go/src/github.com/nginxinc/nginx-kubernetes-gateway/
99
RUN go mod download
1010

1111
COPY --link conformance/tests /go/src/github.com/nginxinc/nginx-kubernetes-gateway/conformance/tests/
12+
13+
CMD go test -timeout 25m -v . -tags conformance -args --gateway-class=${GATEWAY_CLASS} --debug --supported-features=${SUPPORTED_FEATURES} --exempt-features=${EXEMPT_FEATURES}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: conformance
5+
---
6+
kind: ClusterRole
7+
apiVersion: rbac.authorization.k8s.io/v1
8+
metadata:
9+
name: conformance
10+
rules:
11+
- apiGroups:
12+
- ""
13+
resources:
14+
- namespaces
15+
- pods
16+
- secrets
17+
- services
18+
verbs:
19+
- create
20+
- delete
21+
- get
22+
- list
23+
- update
24+
- apiGroups:
25+
- apps
26+
resources:
27+
- deployments
28+
verbs:
29+
- create
30+
- delete
31+
- get
32+
- list
33+
- apiGroups:
34+
- gateway.networking.k8s.io
35+
resources:
36+
- gatewayclasses
37+
verbs:
38+
- get
39+
- list
40+
- apiGroups:
41+
- gateway.networking.k8s.io
42+
resources:
43+
- gateways
44+
- httproutes
45+
verbs:
46+
- create
47+
- delete
48+
- get
49+
- list
50+
- patch
51+
---
52+
kind: ClusterRoleBinding
53+
apiVersion: rbac.authorization.k8s.io/v1
54+
metadata:
55+
name: nginx-conformance
56+
subjects:
57+
- kind: ServiceAccount
58+
name: conformance
59+
namespace: default
60+
roleRef:
61+
kind: ClusterRole
62+
name: conformance
63+
apiGroup: rbac.authorization.k8s.io
64+
---
65+
apiVersion: v1
66+
kind: Pod
67+
metadata:
68+
name: conformance
69+
spec:
70+
containers:
71+
- name: conformance
72+
image: conformance-test-runner:latest
73+
imagePullPolicy: Never
74+
env:
75+
- name: GATEWAY_CLASS
76+
value: nginx
77+
- name: SUPPORTED_FEATURES
78+
value: HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect
79+
- name: EXEMPT_FEATURES
80+
value: ReferenceGrant
81+
serviceAccountName: conformance
82+
restartPolicy: Never

0 commit comments

Comments
 (0)