Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
# Enable Go modules.
export GO111MODULE=on

# INGRESS2GATEWAY defines the ingress2gateway location
# It will be used by some makefile targets to avoid rebuilding it
INGRESS2GATEWAY ?= $(shell pwd)/ingress2gateway

# I2GWPKG is the package path for i2gw. This allows us to propogate the git info
# to the binary via LDFLAGS.
I2GWPKG := $(shell go list .)/pkg/i2gw
Expand Down Expand Up @@ -57,10 +61,21 @@ test: vet;$(info $(M)...Begin to run tests.) @ ## Run tests.

# Build the binary
.PHONY: build
build: vet;$(info $(M)...Build the binary.) @ ## Build the binary.
go build $(LDFLAGS) -o ingress2gateway .
build: vet clean $(INGRESS2GATEWAY);$(info $(M)...Build the binary.) @ ## Build the binary.

.PHONY: clean
clean:
rm -rf $(INGRESS2GATEWAY)

$(INGRESS2GATEWAY):
go build $(LDFLAGS) -o $(INGRESS2GATEWAY) .

# Run static analysis.
.PHONY: verify
verify:
hack/verify-all.sh -v

# Run e2e tests
.PHONY: e2e
e2e: $(INGRESS2GATEWAY)
I2G=$(INGRESS2GATEWAY) hack/verify-e2e.sh
Copy link
Member

@LiorLieberman LiorLieberman Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we do I2GW?

13 changes: 13 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Ingress2Gateway e2e tests

This folder contains the e2e tests for ingress2gateway. Implementors willing to
add new features or migrate MUST add tests to the subfolder of the provider, to
guarantee that the desired migration is working as expected.

The tests are written using [BATS](https://bats-core.readthedocs.io/en/stable/index.html)
to guarantee that the desired user behavior happens as they were really operating
a cluster and avoiding to write Go programs that may not reflect the desired
behavior of the test.

To execute the tests, you should run from the root directory of the project the
command `make e2e`.
43 changes: 43 additions & 0 deletions e2e/manifests/infrastructure/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: v1
kind: Service
metadata:
name: backend
spec:
selector:
app: backend
ports:
- name: http-port
protocol: TCP
port: 8080
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
labels:
app: backend
spec:
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: gcr.io/k8s-staging-gateway-api/echo-basic:v20240412-v1.0.0-394-g40c666fd
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources:
requests:
cpu: 10m
10 changes: 10 additions & 0 deletions e2e/manifests/infrastructure/gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: eg
spec:
gatewayClassName: eg
listeners:
- name: http
protocol: HTTP
port: 80
6 changes: 6 additions & 0 deletions e2e/manifests/infrastructure/gatewayclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: eg
spec:
controllerName: gateway.envoyproxy.io/gatewayclass-controller
16 changes: 16 additions & 0 deletions e2e/manifests/simple/simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: simple
spec:
rules:
- host: some.test
http:
paths:
- backend:
service:
name: backend
port:
number: 3000
path: /
pathType: Exact
10 changes: 10 additions & 0 deletions e2e/tests/e2e_simple.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bats

#### This test suite contains just the simple ingress test, and should not have any Provider specifics

load functions.bash

@test "Simple Ingress manifest test" {
i2g simple/simple.yaml
do_request
}
25 changes: 25 additions & 0 deletions e2e/tests/functions.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

function log() {
echo "# LOG: $1" >&3
}

function do_request() {
HOST=${1:-localhost}
log "Doing an initial request to Gateway on ${HOST}:${GATEWAY_FORWARDED_PORT}"
curl --fail -kv --max-time 5 --resolve ${HOST}:${GATEWAY_FORWARDED_PORT}:127.0.0.1 "http://${HOST}:${GATEWAY_FORWARDED_PORT}"
}

function i2g() {
MANIFEST="${1:-}"
if [ -z "${MANIFEST}" ]; then
echo "The source manifest is mandatory"
exit 1
fi
log "Running i2g on e2e/manifests/${MANIFEST}"
${I2G} print --input-file e2e/manifests/"${MANIFEST}"
}
47 changes: 47 additions & 0 deletions e2e/tests/setup_suite.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

export GATEWAY_FORWARDED_PORT="${GATEWAY_PORT:-8888}"

source e2e/tests/functions.bash

# TODO: We may want to accept other providers, for now to keep it simple we will go with Envoy Gateway
function setup_suite {
log "Installing envoy gateway"

kubectl apply --server-side -f https://github.com/envoyproxy/gateway/releases/download/v1.5.0/install.yaml
kubectl wait --timeout=5m -n envoy-gateway-system deployment/envoy-gateway --for=condition=Available

# Install envoy gateway class
log "Creating GatewayClass"
kubectl apply -f e2e/manifests/infrastructure/gatewayclass.yaml
kubectl wait gatewayclass/eg --for=condition=Accepted=True
# TODO: Add HTTPS listener
log "Creating Gateway"
kubectl apply -f e2e/manifests/infrastructure/gateway.yaml
sleep 3 # Give some time for controller to reconcile gateway and start a deployment
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 /)
kubectl wait --timeout=2m deploy -n envoy-gateway-system ${GATEWAY_NAME} --for=condition=Available
log "Starting port-forwarding to gateway"
kubectl -n envoy-gateway-system port-forward service/${GATEWAY_NAME} ${GATEWAY_FORWARDED_PORT}:80 &
export KUBECTL_FORWARDER_PID=$!

log "Setting the sample application"
kubectl apply -f e2e/manifests/infrastructure/backend.yaml
kubectl wait --timeout=2m deploy backend --for=condition=Available
log "Test is ready to roll"
}

# We don't remove envoy gateway during teardown to avoid the reinstallation that has high cost
function teardown_suite {
kill ${KUBECTL_FORWARDER_PID}
log "Killed port-forwarding"
log "Removing the sample application"
kubectl delete -f e2e/manifests/infrastructure/backend.yaml
log "Cleaning gateway and gatewayclass resources"
kubectl delete -f e2e/manifests/infrastructure/gateway.yaml
kubectl delete -f e2e/manifests/infrastructure/gatewayclass.yaml
}
53 changes: 53 additions & 0 deletions hack/verify-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Copyright 2014 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dammit copy/pasta

#
# 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.

set -o errexit
set -o nounset
set -o pipefail

# TODO: make this configurable
export PROVIDER="ingress-nginx"
export I2G="${I2G:-$(pwd)/ingress2gateway}"
export TESTS_DIR="${TESTS_DIR:-$(pwd)/e2e/tests}"


function pre_check() {
if ! ${I2G} &>/dev/null; then
echo "Error executing ingress2gateway, please be sure the variable I2G is pointing to the right location"
exit 1
fi
if ! command -v bats &> /dev/null; then
echo "BATS needs to be installed. Please check https://bats-core.readthedocs.io/en/stable/installation.html"
exit 1
fi

if ! command -v curl &> /dev/null; then
echo "cURL needs to be installed to execute the tests"
exit 1
fi

if ! kubectl version; then
echo "Error executing kubectl. Please be sure you have a Kubernetes cluster running before executing the test"
exit 1
fi
}

function run_tests() {
bats "${TESTS_DIR}"
}

pre_check
run_tests