Skip to content

Commit 6aaefb3

Browse files
authored
add ability to run gateway api tests locally (#713)
1 parent 7bd265c commit 6aaefb3

File tree

7 files changed

+219
-1
lines changed

7 files changed

+219
-1
lines changed

conformance/Makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
NKG_TAG = edge
2+
NKG_PREFIX = nginx-kubernetes-gateway
3+
GATEWAY_CLASS = nginx
4+
SUPPORTED_FEATURES = Gateway,HTTPRoute
5+
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
6+
TAG = latest
7+
PREFIX = conformance-test-runner
8+
.DEFAULT_GOAL := help
9+
10+
.PHONY: help
11+
help: Makefile ## Display this help
12+
@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}'
13+
14+
.PHONY: build-test-runner-image
15+
build-test-runner-image: ## Build conformance test runner image
16+
docker build -t $(PREFIX):$(TAG) -f tests/Dockerfile ..
17+
18+
.PHONY: create-kind-cluster
19+
create-kind-cluster: ## Create a kind cluster
20+
kind create cluster --image kindest/node:v1.27.1
21+
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
22+
23+
.PHONY: prepare-nkg
24+
prepare-nkg: ## Build and load NKG container on configured kind cluster
25+
cd .. && make PREFIX=$(NKG_PREFIX) TAG=$(NKG_TAG) container
26+
kind load docker-image $(NKG_PREFIX):$(NKG_TAG)
27+
28+
.PHONY: install-nkg
29+
install-nkg: ## Install NKG with provisioner on configured kind cluster
30+
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.0/standard-install.yaml
31+
kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system
32+
kubectl apply -f ../deploy/manifests/namespace.yaml
33+
kubectl create configmap njs-modules --from-file=../internal/nginx/modules/src/httpmatches.js -n nginx-gateway
34+
kubectl apply -f ../deploy/manifests/nginx-conf.yaml
35+
kubectl apply -f ../deploy/manifests/rbac.yaml
36+
kubectl apply -f ../deploy/manifests/gatewayclass.yaml
37+
kubectl apply -f ../deploy/manifests/service/nodeport.yaml
38+
kubectl apply -f provisioner/provisioner.yaml
39+
40+
.PHONY: update-test-kind-config
41+
update-test-kind-config: ## Update kind config
42+
sed -ir "s|server:.*|server: https://kind-control-plane:6443|" $(KIND_KUBE_CONFIG_FOLDER)/config
43+
44+
.PHONY: run-conformance-tests
45+
run-conformance-tests: update-test-kind-config ## Run conformance tests
46+
docker run --network=kind --rm -v $(KIND_KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) \
47+
go test -v . -tags conformance -args --gateway-class=$(GATEWAY_CLASS) --supported-features=$(SUPPORTED_FEATURES)
48+
49+
.PHONY: uninstall-nkg
50+
uninstall-nkg: ## Uninstall NKG on configured kind cluster
51+
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.0/standard-install.yaml
52+
kubectl delete -f ../deploy/manifests/rbac.yaml
53+
kubectl delete -f ../deploy/manifests/namespace.yaml
54+
kubectl delete clusterrole nginx-gateway-provisioner
55+
kubectl delete clusterrolebinding nginx-gateway-provisioner
56+
57+
.PHONY: delete-kind-cluster
58+
delete-kind-cluster: ## Delete kind cluster
59+
kind delete cluster

conformance/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Running [Gateway Conformance Tests](https://gateway-api.sigs.k8s.io/concepts/conformance/#3-conformance-tests) in kind
2+
3+
## Prerequisites:
4+
5+
* [kind](https://kind.sigs.k8s.io/).
6+
* Docker.
7+
* Golang.
8+
9+
**Note**: all commands in steps below are executed from the ```conformance``` directory
10+
11+
List available commands:
12+
13+
```bash
14+
$ make
15+
16+
build-test-image Build conformance test image
17+
create-kind-cluster Create a kind cluster
18+
delete-kind-cluster Delete kind cluster
19+
help Display this help
20+
install-nkg Install NKG on configured kind cluster
21+
run-conformance-tests Run conformance tests
22+
uninstall-nkg Uninstall NKG from configured kind cluster
23+
update-test-kind-config Update kind config
24+
```
25+
### Step 1 - Create a kind Cluster
26+
27+
```bash
28+
$ make create-kind-cluster
29+
```
30+
31+
### Step 2 - Update NKG deployment and provisioner manifests
32+
**Note**: this step is only required when user wants to run conformance tests using locally built image of Nginx Kubernetes Gateway
33+
* Set NKG_PREFIX=<repo_name> NKG_TAG=<image_tag> to preferred values.
34+
* Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block.
35+
* Navigate to `conformance/provisioner` and update values in `provisioner.yaml` as specified in below code-block.
36+
* Save the changes.
37+
```
38+
.
39+
..
40+
containers:
41+
- image: <repo_name>:<image_tag>
42+
imagePullPolicy: Never
43+
..
44+
.
45+
```
46+
47+
### Step 3 - Build and load Nginx Kubernetes Gateway container to configured kind cluster
48+
**Note**: this step is only required when user wants to run conformance tests using locally built image of Nginx Kubernetes Gateway
49+
50+
```bash
51+
$ make NKG_PREFIX=<repo_name> NKG_TAG=<image_tag> prepare-nkg
52+
53+
```
54+
### Step 4 - Build conformance test runner image
55+
```bash
56+
$ make build-test-runner-image
57+
```
58+
59+
### Step 5 - Install Nginx Kubernetes Gateway
60+
```bash
61+
$ make install-nkg
62+
```
63+
64+
### Step 6 - Run Gateway conformance tests
65+
```bash
66+
$ make run-conformance-tests
67+
```
68+
69+
### Step 7 - Uninstall Nginx Kubernetes Gateway
70+
```bash
71+
$ make uninstall-nkg
72+
```
73+
74+
### Step 8 - Delete kind cluster
75+
```bash
76+
$ make delete-kind-cluster
77+
```

conformance/tests/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# syntax=docker/dockerfile:1.5
2+
3+
FROM golang:1.20
4+
5+
WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway/conformance/tests/
6+
7+
COPY --link go.mod /go/src/github.com/nginxinc/nginx-kubernetes-gateway/
8+
COPY --link go.sum /go/src/github.com/nginxinc/nginx-kubernetes-gateway/
9+
RUN go mod download
10+
11+
COPY --link conformance/tests /go/src/github.com/nginxinc/nginx-kubernetes-gateway/conformance/tests/

conformance/tests/conformance_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//go:build conformance
2+
3+
/*
4+
Copyright 2022 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
package tests
19+
20+
import (
21+
"testing"
22+
23+
. "github.com/onsi/gomega"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
"sigs.k8s.io/controller-runtime/pkg/client/config"
26+
"sigs.k8s.io/gateway-api/apis/v1alpha2"
27+
"sigs.k8s.io/gateway-api/apis/v1beta1"
28+
"sigs.k8s.io/gateway-api/conformance/tests"
29+
"sigs.k8s.io/gateway-api/conformance/utils/flags"
30+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
31+
)
32+
33+
func TestConformance(t *testing.T) {
34+
g := NewGomegaWithT(t)
35+
cfg, err := config.GetConfig()
36+
g.Expect(err).To(BeNil())
37+
38+
client, err := client.New(cfg, client.Options{})
39+
g.Expect(err).To(BeNil())
40+
41+
g.Expect(v1alpha2.AddToScheme(client.Scheme())).To(Succeed())
42+
g.Expect(v1beta1.AddToScheme(client.Scheme())).To(Succeed())
43+
44+
t.Logf(`Running conformance tests with %s GatewayClass\n cleanup: %t\n`+
45+
`debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]`,
46+
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug,
47+
*flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures)
48+
49+
cSuite := suite.New(suite.Options{
50+
Client: client,
51+
GatewayClassName: *flags.GatewayClassName,
52+
Debug: *flags.ShowDebug,
53+
CleanupBaseResources: *flags.CleanupBaseResources,
54+
SupportedFeatures: nil,
55+
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures,
56+
})
57+
cSuite.Setup(t)
58+
cSuite.Run(t, tests.ConformanceTests)
59+
}

docs/developer/testing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ Follow the steps below for manual testing:
8383
- NGINX proxies traffic successfully (when applicable).
8484
- [Examples](/examples) work correctly. This will ensure that your changes have not introduced any regressions.
8585
86-
8786
> **Note**
8887
>
8988
> Don't limit yourself to happy path testing. Make an effort to cover various scenarios, including edge cases and potential error conditions. By testing a wide range of scenarios, you can uncover hidden issues and ensure the robustness of your changes.
9089

9190
Performing manual testing helps guarantee the stability, reliability, and effectiveness of your changes before
9291
submitting them for review and integration into the project.
92+
93+
94+
## Gateway API Conformance Testing
95+
96+
To run Gateway API conformance tests, please follow the instructions on [this](/conformance/README.md) page.

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ require (
4242
github.com/json-iterator/go v1.1.12 // indirect
4343
github.com/mailru/easyjson v0.7.7 // indirect
4444
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
45+
github.com/moby/spdystream v0.2.0 // indirect
4546
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4647
github.com/modern-go/reflect2 v1.0.2 // indirect
4748
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4849
github.com/pkg/errors v0.9.1 // indirect
50+
github.com/pmezard/go-difflib v1.0.0 // indirect
4951
github.com/prometheus/client_golang v1.15.1 // indirect
5052
github.com/prometheus/client_model v0.4.0 // indirect
5153
github.com/prometheus/common v0.42.0 // indirect
5254
github.com/prometheus/procfs v0.9.0 // indirect
5355
github.com/spf13/pflag v1.0.5 // indirect
56+
github.com/stretchr/testify v1.8.2 // indirect
5457
go.uber.org/atomic v1.9.0 // indirect
5558
go.uber.org/multierr v1.7.0 // indirect
5659
go.uber.org/zap v1.24.0 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
34
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
45
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
56
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -75,6 +76,7 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY
7576
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
7677
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
7778
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
79+
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
7880
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
7981
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
8082
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
@@ -101,6 +103,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk
101103
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
102104
github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1 h1:9XE5ykDiC8eNSqIPkxx0EsV3kMX1oe4kQWRZjIgytUA=
103105
github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1/go.mod h1:qbKwBR+qQODzH2WD/s53mdgp/xVcXMlJb59GRFOp6Z4=
106+
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
107+
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
104108
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
105109
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
106110
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -145,6 +149,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
145149
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
146150
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
147151
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
152+
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
148153
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
149154
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
150155
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

0 commit comments

Comments
 (0)