Skip to content

Commit b611160

Browse files
committed
Run conformance tests nightly on main branch (nginx#884)
In order to ensure we are staying ahead of Gateway API changes, we'll now run conformance tests off of the main branch on a nightly schedule. Devs can also run from the main branch locally by setting the GW_API_VERSION variable.
1 parent 354ea5a commit b611160

File tree

6 files changed

+202
-90
lines changed

6 files changed

+202
-90
lines changed

.github/workflows/ci.yml

-86
Original file line numberDiff line numberDiff line change
@@ -147,92 +147,6 @@ jobs:
147147
path: ${{ github.workspace }}/dist
148148
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
149149

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

.github/workflows/conformance.yml

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Conformance Testing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release-*
8+
pull_request:
9+
branches:
10+
- main
11+
- release-*
12+
types:
13+
- opened
14+
- reopened
15+
- synchronize
16+
schedule:
17+
- cron: '0 4 * * *'
18+
19+
concurrency:
20+
group: ${{ github.ref_name }}-conformance
21+
cancel-in-progress: true
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
conformance-tests:
28+
name: Gateway Conformance Tests
29+
runs-on: ubuntu-22.04
30+
steps:
31+
- name: Checkout Repository
32+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
33+
34+
- name: Setup Golang Environment
35+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
36+
with:
37+
go-version-file: go.mod
38+
39+
- name: Set GOPATH
40+
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
41+
42+
- name: Docker Buildx
43+
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
44+
45+
- name: Docker meta
46+
id: meta
47+
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
48+
with:
49+
images: |
50+
name=ghcr.io/nginxinc/nginx-kubernetes-gateway
51+
tags: |
52+
type=semver,pattern={{version}}
53+
type=edge
54+
type=ref,event=pr
55+
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
56+
57+
- name: Prepare NKG files
58+
run: |
59+
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
60+
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
61+
make update-nkg-manifest NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
62+
working-directory: ./conformance
63+
64+
- name: Build binary
65+
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
66+
with:
67+
version: latest
68+
args: build --snapshot --clean
69+
70+
- name: Build Docker Image
71+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
72+
with:
73+
file: build/Dockerfile
74+
tags: ${{ steps.meta.outputs.tags }}
75+
context: "."
76+
target: goreleaser
77+
load: true
78+
cache-from: type=gha
79+
cache-to: type=gha,mode=max
80+
pull: true
81+
82+
- name: Update Go Modules
83+
if: ${{ github.event_name == 'schedule' }}
84+
run: make update-go-modules
85+
working-directory: ./conformance
86+
87+
- name: Build Test Docker Image
88+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
89+
with:
90+
file: conformance/tests/Dockerfile
91+
tags: conformance-test-runner:${{ github.sha }}
92+
context: "."
93+
load: true
94+
cache-from: type=gha
95+
cache-to: type=gha,mode=max
96+
pull: true
97+
98+
- name: Deploy Kubernetes
99+
id: k8s
100+
run: |
101+
make create-kind-cluster KIND_KUBE_CONFIG=${{ github.workspace }}/kube-${{ github.run_id }}
102+
echo "KUBECONFIG=${{ github.workspace }}/kube-${{ github.run_id }}" >> "$GITHUB_ENV"
103+
working-directory: ./conformance
104+
105+
- name: Setup conformance tests
106+
run: |
107+
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
108+
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
109+
if [ ${{ github.event_name }} == "schedule" ]; then
110+
export GW_API_VERSION=main
111+
fi
112+
make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
113+
working-directory: ./conformance
114+
115+
- name: Run conformance tests
116+
run: make run-conformance-tests TAG=${{ github.sha }}
117+
working-directory: ./conformance

conformance/Makefile

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
NKG_TAG = edge
22
NKG_PREFIX = nginx-kubernetes-gateway
3+
GW_API_VERSION ?= 0.7.1
34
GATEWAY_CLASS = nginx
45
SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect,GatewayClassObservedGenerationBump
56
KIND_KUBE_CONFIG=$${HOME}/.kube/kind/config
@@ -13,6 +14,11 @@ NGINX_IMAGE=$(shell yq '.spec.template.spec.containers[1].image as $$nginx_ver |
1314
help: Makefile ## Display this help
1415
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m<target>\033[0m\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
1516

17+
.PHONY: update-go-modules
18+
update-go-modules: ## Update the gateway-api go modules to latest main version
19+
go get -u sigs.k8s.io/gateway-api@main
20+
go mod tidy
21+
1622
.PHONY: build-test-runner-image
1723
build-test-runner-image: ## Build conformance test runner image
1824
docker build -t $(PREFIX):$(TAG) -f tests/Dockerfile ..
@@ -42,7 +48,7 @@ load-images: preload-nginx-container ## Load NKG and NGINX containers on configu
4248

4349
.PHONY: prepare-nkg-dependencies
4450
prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster
45-
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
51+
./scripts/install-gateway.sh $(GW_API_VERSION)
4652
kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system
4753
kubectl apply -f ../deploy/manifests/namespace.yaml
4854
kubectl create configmap njs-modules --from-file=../internal/mode/static/nginx/modules/src/httpmatches.js -n nginx-gateway
@@ -83,7 +89,7 @@ cleanup-conformance-tests: ## Clean up conformance tests fixtures
8389

8490
.PHONY: uninstall-nkg
8591
uninstall-nkg: ## Uninstall NKG on configured kind cluster
86-
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
92+
./scripts/uninstall-gateway.sh $(GW_API_VERSION)
8793
kubectl delete -f ../deploy/manifests/rbac.yaml
8894
kubectl delete -f ../deploy/manifests/namespace.yaml
8995
kubectl delete clusterrole nginx-gateway-provisioner
@@ -93,6 +99,10 @@ uninstall-nkg: ## Uninstall NKG on configured kind cluster
9399
undo-image-update: ## Undo the NKG image name and tag in deployment manifest
94100
git checkout -- $(NKG_DEPLOYMENT_MANIFEST)
95101

102+
.PHONY: reset-go-modules
103+
reset-go-modules: ## Reset the go modules changes
104+
git checkout -- ../go.mod ../go.sum
105+
96106
.PHONY: delete-kind-cluster
97107
delete-kind-cluster: ## Delete kind cluster
98108
kind delete cluster

conformance/README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ install-nkg-local-no-build Install NKG from local build with provisioner on
2929
load-images Load NKG and NGINX containers on configured kind cluster
3030
preload-nginx-container Preload NGINX container on configured kind cluster
3131
prepare-nkg-dependencies Install NKG dependencies on configured kind cluster
32+
reset-go-modules Reset the go modules changes
3233
run-conformance-tests Run conformance tests
3334
undo-image-update Undo the NKG image name and tag in deployment manifest
3435
uninstall-nkg Uninstall NKG on configured kind cluster
36+
update-go-modules Update the gateway-api go modules to latest main version
3537
update-nkg-manifest Update the NKG deployment manifest image name and imagePullPolicy
3638
```
3739

@@ -43,6 +45,7 @@ update-nkg-manifest Update the NKG deployment manifest image name and
4345
| PREFIX | conformance-test-runner | The prefix for the conformance test image |
4446
| NKG_TAG | edge | The tag for the locally built NKG image |
4547
| NKG_PREFIX | nginx-kubernetes-gateway | The prefix for the locally built NKG image |
48+
| GW_API_VERSION | 0.7.1 | Tag for the Gateway API version to check out. Set to `main` to get the latest version |
4649
| KIND_KUBE_CONFIG | ~/.kube/kind/config | The location of the kubeconfig |
4750
| GATEWAY_CLASS | nginx | The gateway class that should be used for the tests |
4851
| 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. |
@@ -58,6 +61,15 @@ make create-kind-cluster
5861

5962
### Step 2 - Install Nginx Kubernetes Gateway to configured kind cluster
6063

64+
> Note: If you want to run the latest conformance tests from the Gateway API `main` branch, set the following
65+
> environment variable before deploying NKG:
66+
67+
```bash
68+
export GW_API_VERSION=main
69+
```
70+
71+
> Otherwise, the latest stable version will be used by default.
72+
6173
#### *Option 1* Build and install Nginx Kubernetes Gateway from local to configured kind cluster
6274

6375
```makefile
@@ -96,6 +108,24 @@ make install-nkg-edge
96108

97109
### Step 3 - Build conformance test runner image
98110

111+
> Note: If you want to run the latest conformance tests from the Gateway API `main` branch, run the following
112+
> make command to update the Go modules to `main`:
113+
114+
```makefile
115+
make update-go-modules
116+
```
117+
118+
> You can also point to a specific fork/branch by running:
119+
120+
```bash
121+
go mod edit -replace=sigs.k8s.io/gateway-api=<your-fork>@<your-branch>
122+
go mod download
123+
go mod verify
124+
go mod tidy
125+
```
126+
127+
> Otherwise, the latest stable version will be used by default.
128+
99129
```makefile
100130
make build-test-runner-image
101131
```
@@ -116,15 +146,22 @@ make cleanup-conformance-tests
116146
make uninstall-nkg
117147
```
118148

119-
### Step 6 - Revert changes to the NKG deployment manifest
149+
### Step 6 - Revert changes to Go modules
150+
**Optional** Not required if you aren't running the `main` Gateway API tests.
151+
152+
```makefile
153+
make reset-go-modules
154+
```
155+
156+
### Step 7 - Revert changes to the NKG deployment manifest
120157
**Optional** Not required if using `edge` image
121158
**Warning**: `make undo-image-update` will hard reset changes to the deploy/manifests/deployment.yaml file!
122159

123160
```makefile
124161
make undo-image-update
125162
```
126163

127-
### Step 7 - Delete kind cluster
164+
### Step 8 - Delete kind cluster
128165

129166
```makefile
130167
make delete-kind-cluster
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
if [ -z $1 ]; then
4+
echo "gateway API version argument not set; exiting"
5+
exit 1
6+
fi
7+
8+
if [ $1 == "main" ]; then
9+
temp_dir=$(mktemp -d)
10+
cd ${temp_dir}
11+
curl -s https://codeload.github.com/kubernetes-sigs/gateway-api/tar.gz/main | tar -xz --strip=2 gateway-api-main/config
12+
kubectl apply -f webhook
13+
kubectl apply -f crd/standard
14+
rm -rf ${temp_dir}
15+
else
16+
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v$1/standard-install.yaml
17+
fi
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
if [ -z $1 ]; then
4+
echo "gatway API version argument not set; exiting"
5+
exit 1
6+
fi
7+
8+
if [ $1 == "main" ]; then
9+
temp_dir=$(mktemp -d)
10+
cd ${temp_dir}
11+
curl -s https://codeload.github.com/kubernetes-sigs/gateway-api/tar.gz/main | tar -xz --strip=2 gateway-api-main/config
12+
kubectl delete -f webhook
13+
kubectl delete -f crd/standard
14+
rm -rf ${temp_dir}
15+
else
16+
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v$1/standard-install.yaml
17+
fi

0 commit comments

Comments
 (0)