-
Notifications
You must be signed in to change notification settings - Fork 118
Tests/run conformance tests #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
01b8869
Run k8s gateway api conformance tests
vepatel 1e24883
update go files
vepatel 3b488fc
Update instructions
vepatel 9b278a9
linter changes & excluted conf test from unit-test
vepatel c9c0f5e
Remove blind sleep and update readme
vepatel ed62ca3
Merge branch 'main' into tests/run-conformance-tests
vepatel be45743
add chmod cmd to Makefile
vepatel cdf1ea4
replace custom script with kubectl wait
vepatel 8a5f534
add HTTPRoute to supported features
vepatel 8a34683
Merge branch 'main' into tests/run-conformance-tests
vepatel 7f2a62d
link conformace test readme to testing doc.
vepatel 45a9c5f
Merge branch 'main' into tests/run-conformance-tests
vepatel 7612a3b
add gomega
vepatel f907364
PR feedback
vepatel 8a06290
PR feedback
vepatel a548512
Merge branch 'main' into tests/run-conformance-tests
vepatel 0eeae5a
linting
vepatel b58ec41
Update README
vepatel 75cc30a
typos
vepatel 75a043d
Merge branch 'main' into tests/run-conformance-tests
vepatel 0426b33
Update README and error assertions
vepatel 6baf8b6
Merge branch 'main' into tests/run-conformance-tests
vepatel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# syntax=docker/dockerfile:1.5 | ||
|
||
FROM golang:1.20 | ||
|
||
WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway/conformance-tests | ||
|
||
COPY --link go.mod go.sum /go/src/github.com/nginxinc/nginx-kubernetes-gateway/ | ||
RUN go mod download | ||
|
||
COPY --link conformance-tests /go/src/github.com/nginxinc/nginx-kubernetes-gateway/conformance-tests/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
GATEWAY_CLASS = nginx | ||
SUPPORTED_FEATURES = Gateway | ||
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind | ||
TAG = latest | ||
PREFIX = conformance-test-runner | ||
.DEFAULT_GOAL := help | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.PHONY: help | ||
help: Makefile ## Display this help | ||
@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}' | ||
|
||
.PHONY: build-test-image | ||
build-test-image: ## Build conformance test image | ||
docker build -t $(PREFIX):$(TAG) -f Dockerfile .. | ||
|
||
.PHONY: create-kind-cluster | ||
create-kind-cluster: ## Create a KinD cluster | ||
kind create cluster --image kindest/node:v1.27.1 | ||
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config | ||
|
||
.PHONY: install-nkg | ||
install-nkg: ## Install NKG with provisioner on configured KinD cluster | ||
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.0/standard-install.yaml | ||
./wait_for_webhook.sh | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kubectl apply -f ../deploy/manifests/namespace.yaml | ||
kubectl create configmap njs-modules --from-file=../internal/nginx/modules/src/httpmatches.js -n nginx-gateway | ||
kubectl apply -f ../deploy/manifests/nginx-conf.yaml | ||
kubectl apply -f ../deploy/manifests/rbac.yaml | ||
kubectl apply -f ../deploy/manifests/gatewayclass.yaml | ||
kubectl apply -f ../deploy/manifests/service/nodeport.yaml | ||
kubectl apply -f ../conformance/provisioner/provisioner.yaml | ||
|
||
.PHONY: update-test-kind-config | ||
update-test-kind-config: ## Update KinD config | ||
sed -ir "s|server:.*|server: https://kind-control-plane:6443|" $(KIND_KUBE_CONFIG_FOLDER)/config | ||
|
||
.PHONY: run-conformance-tests | ||
run-conformance-tests: update-test-kind-config ## Run conformance tests | ||
docker run --network=kind --rm -v $(KIND_KUBE_CONFIG_FOLDER):/root/.kube $(PREFIX):$(TAG) \ | ||
go test -v . -args --gateway-class=$(GATEWAY_CLASS) --supported-features=$(SUPPORTED_FEATURES) | ||
|
||
.PHONY: uninstall-nkg | ||
uninstall-nkg: ## Uninstall NKG on configured KinD cluster | ||
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.0/standard-install.yaml | ||
kubectl delete -f ../deploy/manifests/rbac.yaml | ||
kubectl delete -f ../deploy/manifests/namespace.yaml | ||
kubectl delete clusterrole nginx-gateway-provisioner | ||
kubectl delete clusterrolebinding nginx-gateway-provisioner | ||
|
||
.PHONY: delete-kind-cluster | ||
delete-kind-cluster: ## Delete kind cluster | ||
kind delete cluster |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Running [Gateway Conformance Tests](https://gateway-api.sigs.k8s.io/concepts/conformance/#3-conformance-tests) in Kind | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Prerequisites: | ||
|
||
* [Kind](https://kind.sigs.k8s.io/). | ||
* Docker. | ||
* Golang. | ||
|
||
**Note**: all commands in steps below are executed from the ```conformance-tests``` directory | ||
|
||
List available commands: | ||
|
||
```bash | ||
$ make | ||
|
||
build-test-image Build conformance test image | ||
create-kind-cluster Create a KinD cluster | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delete-kind-cluster Delete kind cluster | ||
help Display this help | ||
install-nkg Install NKG on configured KinD cluster | ||
run-conformance-tests Run conformance tests | ||
uninstall-nkg Uninstall NKG from configured KinD cluster | ||
update-test-kind-config Update KinD config | ||
``` | ||
### Step 1 - Create a Kind Cluster | ||
|
||
```bash | ||
$ make create-kind-cluster | ||
``` | ||
|
||
### Step 2 - Build conformance test image | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```bash | ||
$ make build-test-image | ||
``` | ||
|
||
### Step 3 - Install Nginx Kubernetes Gateway | ||
```bash | ||
$ make install-nkg | ||
``` | ||
|
||
### Step 4 - Run Gateway conformance tests | ||
```bash | ||
$ make run-conformance-tests | ||
``` | ||
|
||
### Step 5 - Uninstall Nginx Kubernetes Gateway | ||
```bash | ||
$ make uninstall-nkg | ||
``` | ||
|
||
### Step 6 - Delete KinD cluster | ||
```bash | ||
$ make delete-kind-cluster | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
"sigs.k8s.io/gateway-api/conformance/tests" | ||
"sigs.k8s.io/gateway-api/conformance/utils/flags" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func TestConformance(t *testing.T) { | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
t.Fatalf("Error loading Kubernetes config: %v", err) | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
client, err := client.New(cfg, client.Options{}) | ||
if err != nil { | ||
t.Fatalf("Error initializing Kubernetes client: %v", err) | ||
} | ||
_ = v1alpha2.AddToScheme(client.Scheme()) | ||
vepatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ = v1beta1.AddToScheme(client.Scheme()) | ||
|
||
t.Logf(`Running conformance tests with %s GatewayClass\n cleanup: %t\n`+ | ||
`debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]`, | ||
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, | ||
*flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures) | ||
|
||
cSuite := suite.New(suite.Options{ | ||
Client: client, | ||
GatewayClassName: *flags.GatewayClassName, | ||
Debug: *flags.ShowDebug, | ||
CleanupBaseResources: *flags.CleanupBaseResources, | ||
SupportedFeatures: nil, | ||
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures, | ||
}) | ||
cSuite.Setup(t) | ||
cSuite.Run(t, tests.ConformanceTests) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
export exit=1 | ||
export count=0 | ||
while (( exit == 1 )) && (( count < 10)); do | ||
sleep 1 | ||
count=$((count+1)) | ||
echo waiting $count seconds for webhook container | ||
kubectl get events -n gateway-system | grep "Started container webhook" | ||
exit=`echo $?` | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.