8000 Initial e2e structure · kubernetes-sigs/ingress2gateway@87f9e29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87f9e29

Browse files
committed
Initial e2e structure
1 parent fa8f945 commit 87f9e29

File tree

10 files changed

+240
-2
lines changed

10 files changed

+240
-2
lines changed

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# Enable Go modules.
1919
export GO111MODULE=on
2020

21+
# INGRESS2GATEWAY defines the ingress2gateway location
22+
# It will be used by some makefile targets to avoid rebuilding it
23+
INGRESS2GATEWAY ?= $(shell pwd)/ingress2gateway
24+
2125
# I2GWPKG is the package path for i2gw. This allows us to propogate the git info
2226
# to the binary via LDFLAGS.
2327
I2GWPKG := $(shell go list .)/pkg/i2gw
@@ -57,10 +61,21 @@ test: vet;$(info $(M)...Begin to run tests.) @ ## Run tests.
5761

5862
# Build the binary
5963
.PHONY: build
60-
build: vet;$(info $(M)...Build the binary.) @ ## Build the binary.
61-
go build $(LDFLAGS) -o ingress2gateway .
64+
build: vet clean $(INGRESS2GATEWAY);$(info $(M)...Build the binary.) @ ## Build the binary.
65+
66+
.PHONY: clean
67+
clean:
68+
rm -rf $(INGRESS2GATEWAY)
69+
70+
$(INGRESS2GATEWAY):
71+
go build $(LDFLAGS) -o $(INGRESS2GATEWAY) .
6272

6373
# Run static analysis.
6474
.PHONY: verify
6575
verify:
6676
hack/verify-all.sh -v
77+
78+
# Run e2e tests
79+
.PHONY: e2e
80+
e2e: $(INGRESS2GATEWAY)
81+
I2G=$(INGRESS2GATEWAY) hack/verify-e2e.sh

e2e/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Ingress2Gateway e2e tests
2+
3+
This folder contains the e2e tests for ingress2gateway. Implementors willing to
4+
add new features or migrate MUST add tests to the subfolder of the provider, to
5+
guarantee that the desired migration is working as expected.
6+
7+
The tests are written using [BATS](https://bats-core.readthedocs.io/en/stable/index.html)
8+
to guarantee that the desired user behavior happens as they were really operating
9+
a cluster and avoiding to write Go programs that may not reflect the desired
10+
behavior of the test.
11+
12+
To execute the tests, you should run from the root directory of the project the
13+
command `make e2e`.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: backend
5+
spec:
6+
selector:
7+
app: backend
8+
ports:
9+
- name: http-port
10+
protocol: TCP
11+
port: 8080
12+
targetPort: 3000
13+
---
14+
apiVersion: apps/v1
15+
kind: Deployment
16+
metadata:
17+
name: backend
18+
labels:
19+
app: backend
20+
spec:
21+
selector:
22+
matchLabels:
23+
app: backend
24+
template:
25+
metadata:
26+
labels:
27+
app: backend
28+
spec:
29+
containers:
30+
- name: backend
31+
image: gcr.io/k8s-staging-gateway-api/echo-basic:v20240412-v1.0.0-394-g40c666fd
32+
env:
33+
- name: POD_NAME
34+
valueFrom:
35+
fieldRef:
36+
fieldPath: metadata.name
37+
- name: NAMESPACE
38+
valueFrom:
39+
fieldRef:
40+
fieldPath: metadata.namespace
41+
resources:
42+
requests:
43+
cpu: 10m
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: eg
5+
spec:
6+
gatewayClassName: eg
7+
listeners:
8+
- name: http
9+
protocol: HTTP
10+
port: 80
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: GatewayClass
3+
metadata:
4+
name: eg
5+
spec:
6+
controllerName: gateway.envoyproxy.io/gatewayclass-controller

e2e/manifests/simple/simple.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: simple
5+
spec:
6+
rules:
7+
- host: some.test
8+
http:
9+
paths:
10+
- backend:
11+
service:
12+
name: backend
13+
port:
14+
number: 3000
15+
path: /
16+
pathType: Exact

e2e/tests/e2e_simple.bats

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bats
2+
3+
#### This test suite contains just the simple ingress test, and should not have any Provider specifics
4+
5+
load functions.bash
6+
7+
@test "Simple Ingress manifest test" {
8+
i2g simple/simple.yaml
9+
do_request
10+
}

e2e/tests/functions.bash

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
function log() {
8+
echo "# LOG: $1" >&3
9+
}
10+
11+
function do_request() {
12+
HOST=${1:-localhost}
13+
log "Doing an initial request to Gateway on ${HOST}:${GATEWAY_FORWARDED_PORT}"
14+
curl --fail -kv --max-time 5 --resolve ${HOST}:${GATEWAY_FORWARDED_PORT}:127.0.0.1 "http://${HOST}:${GATEWAY_FORWARDED_PORT}"
15+
}
16+
17+
function i2g() {
18+
MANIFEST="${1:-}"
19+
if [ -z "${MANIFEST}" ]; then
20+
echo "The source manifest is mandatory"
21+
exit 1
22+
fi
23+
log "Running i2g on e2e/manifests/${MANIFEST}"
24+
${I2G} print --input-file e2e/manifests/"${MANIFEST}"
25+
}

e2e/tests/setup_suite.bash

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
export GATEWAY_FORWARDED_PORT="${GATEWAY_PORT:-8888}"
8+
9+
source e2e/tests/functions.bash
10+
11+
# TODO: We may want to accept other providers, for now to keep it simple we will go with Envoy Gateway
12+
function setup_suite {
13+
log "Installing envoy gateway"
14+
15+
kubectl apply --server-side -f https://github.com/envoyproxy/gateway/releases/download/v1.5.0/install.yaml
16+
kubectl wait --timeout=5m -n envoy-gateway-system deployment/envoy-gateway --for=condition=Available
17+
18+
# Install envoy gateway class
19+
log "Creating GatewayClass"
20+
kubectl apply -f e2e/manifests/infrastructure/gatewayclass.yaml
21+
kubectl wait gatewayclass/eg --for=condition=Accepted=True
22+
# TODO: Add HTTPS listener
23+
log "Creating Gateway"
24+
kubectl apply -f e2e/manifests/infrastructure/gateway.yaml
25+
sleep 3 # Give some time for controller to reconcile gateway and start a deployment
26+
export GATEWAY_NAME=$(kubectl get deploy -n envoy-gateway-system --selector=gateway.envoyproxy.io/owning-gateway-namespace=default,gateway.envoyproxy.io/owning-gateway-name=eg -o name |cut -f 2 -d /)
27+
kubectl wait --timeout=2m deploy -n envoy-gateway-system ${GATEWAY_NAME} --for=condition=Available
28+
log "Starting port-forwarding to gateway"
29+
kubectl -n envoy-gateway-system port-forward service/${GATEWAY_NAME} ${GATEWAY_FORWARDED_PORT}:80 &
30+
export KUBECTL_FORWARDER_PID=$!
31+
32+
log "Setting the sample application"
33+
kubectl apply -f e2e/manifests/infrastructure/backend.yaml
34+
kubectl wait --timeout=2m deploy backend --for=condition=Available
35+
log "Test is ready to roll"
36+
}
37+
38+
# We don't remove envoy gateway during teardown to avoid the reinstallation that has high cost
39+
function teardown_suite {
40+
kill ${KUBECTL_FORWARDER_PID}
41+
log "Killed port-forwarding"
42+
log "Removing the sample application"
43+
kubectl delete -f e2e/manifests/infrastructure/backend.yaml
44+
log "Cleaning gateway and gatewayclass resources"
45+
kubectl delete -f e2e/manifests/infrastructure/gateway.yaml
46+
kubectl delete -f e2e 38BA /manifests/infrastructure/gatewayclass.yaml
47+
}

hack/verify-e2e.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2014 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
# TODO: make this configurable
22+
export PROVIDER="ingress-nginx"
23+
export I2G="${I2G:-$(pwd)/ingress2gateway}"
24+
export TESTS_DIR="${TESTS_DIR:-$(pwd)/e2e/tests}"
25+
26+
27+
function pre_check() {
28+
if ! ${I2G} &>/dev/null; then
29+
echo "Error executing ingress2gateway, please be sure the variable I2G is pointing to the right location"
30+
exit 1
31+
fi
32+
if ! command -v bats &> /dev/null; then
33+
echo "BATS needs to be installed. Please check https://bats-core.readthedocs.io/en/stable/installation.html"
34+
exit 1
35+
fi
36+
37+
if ! command -v curl &> /dev/null; then
38+
echo "cURL needs to be installed to execute the tests"
39+
exit 1
40+
fi
41 38BA +
42+
if ! kubectl version; then
43+
echo "Error executing kubectl. Please be sure you have a Kubernetes cluster running before executing the test"
44+
exit 1
45+
fi
46+
}
47+
48+
function run_tests() {
49+
bats "${TESTS_DIR}"
50+
}
51+
52+
pre_check
53+
run_tests

0 commit comments

Comments
 (0)
0