Commit 9373af23 authored by Geoff Simmons's avatar Geoff Simmons

Add example/test for Service type LoadBalancer.

Also set up the tests so that the external IP and port for both the
NodePort and LoadBalancer tests. For this it is necessary to pass
in the external cluster IP, and/or set up an external IP for the
LoadBalancer Service.

If neither of these are available, just use port-forwarding as for
the other tests. That doesn't actually test the Service types, since
connections are forwarded to the clusterIP. But the tests can be
run in automation when the external networking is not available.
parent fbbefd2b
../hello/cafe.vtc
\ No newline at end of file
# looks like -*- vcl -*-
varnishtest "cafe example (hello world for Ingress)"
client c1 -connect "${ip} ${port}" {
txreq -url /coffee/foo/bar -hdr "Host: cafe.example.com"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /coffee/foo/bar$"
expect resp.body ~ "(?m)^Server name: coffee-[a-z0-9]+-[a-z0-9]+$"
txreq -url /tea/baz/quux -hdr "Host: cafe.example.com"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /tea/baz/quux$"
expect resp.body ~ "(?m)^Server name: tea-[a-z0-9]+-[a-z0-9]+$"
txreq -url /coffee/foo/bar
rxresp
expect resp.status == 404
txreq -url /milk -hdr "Host: cafe.example.com"
rxresp
expect resp.status == 404
} -run
apiVersion: v1
kind: Service
metadata:
name: svctypes-example
labels:
app: varnish-ingress
viking.uplex.de/svc: public
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8888
protocol: TCP
name: http
- port: 443
targetPort: 4443
protocol: TCP
name: tls
selector:
app: varnish-ingress
......@@ -3,13 +3,34 @@
MYDIR=$(dirname ${BASH_SOURCE[0]})
source ${MYDIR}/../../test/utils.sh
IP=${IP:-127.0.0.1}
LOCALPORT=${LOCALPORT:-8888}
wait_until_ready app=varnish-ingress
wait_until_configured app=varnish-ingress
kubectl port-forward svc/svctypes-example ${LOCALPORT}:80 >/dev/null &
trap 'kill $(jobs -p)' EXIT
wait_for_port ${LOCALPORT}
NODEPORT=$(kubectl get svc svctypes-example -o jsonpath='{.spec.ports[0].nodePort}')
EXTERNALIP=$(kubectl get svc svctypes-example -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
HTTPPORT=$(kubectl get svc svctypes-example -o jsonpath='{.spec.ports[0].port}')
varnishtest ${TESTOPTS} -Dlocalport=${LOCALPORT} cafe.vtc
if [[ -n ${CLUSTERIP} ]] && [[ -n ${NODEPORT} ]]; then
# If CLUSTERIP is set, we can test the NodePort example using the
# node IP and nodePort.
# For minikube: CLUSTERIP=$(minikube ip)
IP=${CLUSTERIP}
PORT=${NODEPORT}
elif [[ -n ${EXTERNALIP} ]] && [[ -n ${HTTPPORT} ]]; then
# If an external IP was found, we can test the LoadBalancer
# example using the external IP and HTTP port.
IP=${EXTERNALIP}
PORT=${HTTPPORT}
else
# Otherwise use port forwarding. This just forwards connections to
# the ClusterIP (so it doesn't really test the Service types).
PORT=${LOCALPORT}
kubectl port-forward svc/svctypes-example ${PORT}:80 >/dev/null &
trap 'kill $(jobs -p)' EXIT
wait_for_port ${PORT}
fi
varnishtest ${TESTOPTS} -Dport=${PORT} -Dip=${IP} cafe.vtc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment