Skip to content

Commit 104d511

Browse files
authored
Run conformance tests in the CI pipeline (#792)
* Add conformance tests to the CI pipeline
1 parent 1f8a416 commit 104d511

File tree

5 files changed

+137
-15
lines changed

5 files changed

+137
-15
lines changed

.github/workflows/ci.yml

+87-1
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,96 @@ jobs:
144144
path: ${{ github.workspace }}/dist
145145
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
146146

147+
conformance-tests:
148+
name: Gateway Conformance Tests
149+
runs-on: ubuntu-22.04
150+
needs: vars
151+
steps:
152+
- name: Checkout Repository
153+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
154+
155+
- name: Setup Golang Environment
156+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
157+
with:
158+
go-version-file: go.mod
159+
160+
- name: Docker Buildx
161+
uses: docker/setup-buildx-action@ecf95283f03858871ff00b787d79c419715afc34 # v2.7.0
162+
163+
- name: Docker meta
164+
id: meta
165+
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
166+
with:
167+
images: |
168+
name=ghcr.io/nginxinc/nginx-kubernetes-gateway
169+
tags: |
170+
type=semver,pattern={{version}}
171+
type=edge
172+
type=ref,event=pr
173+
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
174+
175+
- name: Prepare NKG files
176+
run: |
177+
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
178+
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
179+
make update-nkg-manifest NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
180+
working-directory: ./conformance
181+
182+
- name: Build binary
183+
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
184+
with:
185+
version: latest
186+
args: ${{ startsWith(github.ref, 'refs/tags/') && 'release' || 'build --snapshot' }} --clean
187+
env:
188+
GOPATH: ${{ needs.vars.outputs.go_path }}
189+
190+
- name: Build Docker Image
191+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
192+
with:
193+
file: build/Dockerfile
194+
tags: ${{ steps.meta.outputs.tags }}
195+
context: "."
196+
target: goreleaser
197+
load: true
198+
cache-from: type=gha
199+
cache-to: type=gha,mode=max
200+
pull: true
201+
202+
- name: Build Test Docker Image
203+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
204+
with:
205+
file: conformance/tests/Dockerfile
206+
tags: conformance-test-runner:${{ github.sha }}
207+
context: "."
208+
load: true
209+
cache-from: type=gha
210+
cache-to: type=gha,mode=max
211+
pull: true
212+
213+
- name: Deploy Kubernetes
214+
id: k8s
215+
run: |
216+
make create-kind-cluster KIND_KUBE_CONFIG=kube-${{ github.run_id }}
217+
echo "KUBECONFIG=kube-${{ github.run_id }}" >> "$GITHUB_ENV"
218+
working-directory: ./conformance
219+
220+
- name: Setup conformance tests
221+
run: |
222+
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
223+
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
224+
make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
225+
working-directory: ./conformance
226+
227+
- name: Run conformance tests
228+
run: |
229+
make run-conformance-tests TAG=${{ github.sha }}
230+
working-directory: ./conformance
231+
continue-on-error: true
232+
147233
build:
148234
name: Build Image
149235
runs-on: ubuntu-22.04
150-
needs: [vars, binary]
236+
needs: [vars, binary, conformance-tests]
151237
steps:
152238
- name: Checkout Repository
153239
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ deps: ## Add missing and remove unused modules, verify deps and download them to
4646

4747
.PHONY: create-kind-cluster
4848
create-kind-cluster: ## Create a kind cluster
49-
kind create cluster --image kindest/node:v1.27.1
49+
$(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node' <conformance/tests/Dockerfile | awk -F'[ ]' '{print $$2}'))
50+
kind create cluster --image $(KIND_IMAGE)
5051
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
5152

5253
.PHONY: delete-kind-cluster

conformance/Makefile

+20-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ NKG_TAG = edge
22
NKG_PREFIX = nginx-kubernetes-gateway
33
GATEWAY_CLASS = nginx
44
SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect
5-
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
5+
KIND_KUBE_CONFIG=$${HOME}/.kube/kind/config
66
TAG = latest
77
PREFIX = conformance-test-runner
88
NKG_DEPLOYMENT_MANIFEST=../deploy/manifests/deployment.yaml
@@ -19,18 +19,25 @@ build-test-runner-image: ## Build conformance test runner image
1919

2020
.PHONY: create-kind-cluster
2121
create-kind-cluster: ## Create a kind cluster
22-
kind create cluster --image kindest/node:v1.27.1
23-
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
22+
$(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node' <tests/Dockerfile | awk -F'[ ]' '{print $$2}'))
23+
kind create cluster --image $(KIND_IMAGE)
24+
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG)
2425

2526
.PHONY: preload-nginx-container
2627
preload-nginx-container: ## Preload NGINX container on configured kind cluster
2728
docker pull $(NGINX_IMAGE)
2829
kind load docker-image $(NGINX_IMAGE)
2930

30-
.PHONY: build-and-load-images
31-
build-and-load-images: preload-nginx-container ## Build NKG container and load it and NGINX container on configured kind cluster
31+
.PHONY: update-nkg-manifest
32+
update-nkg-manifest: ## Update the NKG deployment manifest image name and imagePullPolicy
3233
yq -i 'with(.spec.template.spec.containers[0]; .image = "$(NKG_PREFIX):$(NKG_TAG)" | .imagePullPolicy = "Never")' $(NKG_DEPLOYMENT_MANIFEST)
34+
35+
.PHONY: build-nkg-image
36+
build-nkg-image: update-nkg-manifest ## Build NKG container and load it and NGINX container on configured kind cluster
3337
cd .. && make PREFIX=$(NKG_PREFIX) TAG=$(NKG_TAG) container
38+
39+
.PHONY: load-images
40+
load-images: preload-nginx-container ## Load NKG and NGINX containers on configured kind cluster
3441
kind load docker-image $(NKG_PREFIX):$(NKG_TAG)
3542

3643
.PHONY: prepare-nkg-dependencies
@@ -44,11 +51,17 @@ prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster
4451
kubectl apply -f ../deploy/manifests/gatewayclass.yaml
4552
kubectl apply -f ../deploy/manifests/service/nodeport.yaml
4653

47-
.PHONY: install-nkg-local-build
48-
install-nkg-local-build: build-and-load-images prepare-nkg-dependencies ## Install NKG from local build with provisioner on configured kind cluster
54+
.PHONY: deploy-updated-provisioner
55+
deploy-updated-provisioner: ## Update provisioner manifest and deploy to the configured kind cluster
4956
yq '(select(di != 3))' provisioner/provisioner.yaml | kubectl apply -f -
5057
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 -
5158

59+
.PHONY: install-nkg-local-build
60+
install-nkg-local-build: build-nkg-image load-images prepare-nkg-dependencies deploy-updated-provisioner ## Install NKG from local build with provisioner on configured kind cluster
61+
62+
.PHONY: install-nkg-local-build
63+
install-nkg-local-no-build: load-images prepare-nkg-dependencies deploy-updated-provisioner ## Install NKG from local build with provisioner on configured kind cluster but do not build the NKG image
64+
5265
.PHONY: install-nkg-edge
5366
install-nkg-edge: preload-nginx-container prepare-nkg-dependencies ## Install NKG with provisioner from edge on configured kind cluster
5467
kubectl apply -f provisioner/provisioner.yaml

conformance/README.md

+26-6
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ List available commands:
1414
```bash
1515
$ make
1616

17-
build-and-load-images Build NKG container and load it and NGINX container on configured kind cluster
17+
build-nkg-image Build NKG container and load it and NGINX container on configured kind cluster
1818
build-test-runner-image Build conformance test runner image
1919
cleanup-conformance-tests Clean up conformance tests fixtures
2020
create-kind-cluster Create a kind cluster
2121
delete-kind-cluster Delete kind cluster
22+
deploy-updated-provisioner Update provisioner manifest and deploy to the configured kind cluster
2223
help Display this help
2324
install-nkg-edge Install NKG with provisioner from edge on configured kind cluster
2425
install-nkg-local-build Install NKG from local build with provisioner on configured kind cluster
26+
install-nkg-local-no-build Install NKG from local build with provisioner on configured kind cluster but do not build the NKG image
27+
load-images Load NKG and NGINX containers on configured kind cluster
2528
preload-nginx-container Preload NGINX container on configured kind cluster
2629
prepare-nkg-dependencies Install NKG dependencies on configured kind cluster
2730
run-conformance-tests Run conformance tests
2831
undo-image-update Undo the NKG image name and tag in deployment manifest
2932
uninstall-nkg Uninstall NKG on configured kind cluster
33+
update-nkg-manifest Update the NKG deployment manifest image name and imagePullPolicy
3034
```
3135

3236
**Note:** The following variables are configurable when running the below `make` commands:
@@ -37,7 +41,7 @@ uninstall-nkg Uninstall NKG on configured kind cluster
3741
| PREFIX | conformance-test-runner | The prefix for the conformance test image |
3842
| NKG_TAG | edge | The tag for the locally built NKG image |
3943
| NKG_PREFIX | nginx-kubernetes-gateway | The prefix for the locally built NKG image |
40-
| KIND_KUBE_CONFIG_FOLDER | ~/.kube/kind | The location of the kubeconfig folder |
44+
| KIND_KUBE_CONFIG | ~/.kube/kind/config | The location of the kubeconfig |
4145
| GATEWAY_CLASS | nginx | The gateway class that should be used for the tests |
4246
| SUPPORTED_FEATURES | HTTPRoute,HTTPRouteQueryParamMatching, HTTPRouteMethodMatching,HTTPRoutePortRedirect, HTTPRouteSchemeRedirect | The supported features that should be tested by the conformance tests. Ensure the list is comma separated with no spaces. |
4347
| EXEMPT_FEATURES | ReferenceGrant | The features that should not be tested by the conformance tests |
@@ -55,10 +59,26 @@ $ make create-kind-cluster
5559
```bash
5660
$ make install-nkg-local-build
5761
```
58-
59-
#### *Option 2* Install Nginx Kubernetes Gateway from edge to configured kind cluster
60-
Instead of the above command, you can skip the build NKG image step and prepare the environment to instead
61-
use the `edge` image
62+
#### *Option 2* Install Nginx Kubernetes Gateway from local already built image to configured kind cluster
63+
```bash
64+
$ make install-nkg-local-no-build
65+
```
66+
**Note:** You can optionally skip the actual *build* step. However, if choosing
67+
this option, the following step *must* be completed manually *before* the build step:
68+
* Set NKG_PREFIX=<nkg_repo_name> NKG_TAG=<nkg_image_tag> to preferred values.
69+
* Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block.
70+
* Save the changes.
71+
```
72+
.
73+
..
74+
containers:
75+
- image: <nkg_repo_name>:<nkg_image_tag>
76+
imagePullPolicy: Never
77+
..
78+
.
79+
```
80+
#### *Option 3* Install Nginx Kubernetes Gateway from edge to configured kind cluster
81+
You can also skip the build NKG image step and prepare the environment to instead use the `edge` image
6282

6383
```bash
6484
$ make install-nkg-edge

conformance/tests/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# syntax=docker/dockerfile:1.5
2+
# this is here so we can grab the latest version of kind and have dependabot keep it up to date
3+
FROM kindest/node:v1.27.3
24

35
FROM golang:1.20
46

0 commit comments

Comments
 (0)