Commit b89b0d53 authored by Geoff Simmons's avatar Geoff Simmons

Run the Pod template tests with helm, driven by a Makefile.

parent 8f6e194f
# Copyright (c) 2020 UPLEX Nils Goroll Systemoptimierung
# All rights reserved
#
# Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# GNU make is required.
mkpath := $(abspath $(lastword $(MAKEFILE_LIST)))
mkdir := $(dir $(mkpath))
CHARTDIR=$(mkdir)/../../charts
# For the klarlack image: make VARNISH=klarlack ...
ifndef VARNISH
VARNISH=varnish
endif
CI_REPO_PFX=registry.gitlab.com/uplex/varnish/k8s-ingress/varnish-ingress
# For tests using the local docker registry: make TEST=local ...
# For tests using images from the CI pipeline: make TEST=ci ...
ifeq ($(TEST),local)
CONTROLLER_IMAGE=varnish-ingress/controller
CONTROLLER_TAG=latest
VARNISH_IMAGE=varnish-ingress/$(VARNISH)
VARNISH_TAG=latest
HAPROXY_IMAGE=varnish-ingress/haproxy
HAPROXY_TAG=latest
else ifeq ($(TEST),ci)
CONTROLLER_IMAGE=$(CI_REPO_PFX)/controller
CONTROLLER_TAG=master
VARNISH_IMAGE=$(CI_REPO_PFX)/$(VARNISH)
VARNISH_TAG=master
HAPROXY_IMAGE=$(CI_REPO_PFX)/haproxy
HAPROXY_TAG=master
endif
# If not specified, pull the latest "official" images from dockerhub.
LATEST=0.0.2
ifndef CONTROLLER_IMAGE
CONTROLLER_IMAGE=uplex/viking-controller
endif
ifndef CONTROLLER_TAG
CONTROLLER_TAG=$(LATEST)
endif
ifndef VARNISH_IMAGE
VARNISH_IMAGE=uplex/viking-$(VARNISH)
endif
ifndef VARNISH_TAG
VARNISH_TAG=$(LATEST)
endif
ifndef HAPROXY_IMAGE
HAPROXY_IMAGE=uplex/viking-haproxy
endif
ifndef HAPROXY_TAG
HAPROXY_TAG=$(LATEST)
endif
all: deploy
deploy-cli-args-helm:
@helm install viking-service-cli-args $(CHARTDIR)/viking-service \
--values values-cli-args-varnish.yaml \
--set vikingService.varnish.image.repository=$(VARNISH_IMAGE) \
--set vikingService.varnish.image.tag=$(VARNISH_TAG) \
--set vikingService.haproxy.image.repository=$(HAPROXY_IMAGE) \
--set vikingService.haproxy.image.tag=$(HAPROXY_TAG)
@helm install viking-ingress-cli-args $(CHARTDIR)/viking-test-app \
--values values.yaml
deploy-proxy-helm:
@helm install viking-service-proxy $(CHARTDIR)/viking-service \
--values values-proxy-varnish.yaml \
--set vikingService.varnish.image.repository=$(VARNISH_IMAGE) \
--set vikingService.varnish.image.tag=$(VARNISH_TAG) \
--set vikingService.haproxy.image.repository=$(HAPROXY_IMAGE) \
--set vikingService.haproxy.image.tag=$(HAPROXY_TAG)
@helm install viking-ingress-proxy $(CHARTDIR)/viking-test-app \
--values values.yaml
deploy-env-helm:
@helm install viking-service-env $(CHARTDIR)/viking-service \
--values values-env-varnish.yaml \
--set vikingService.varnish.image.repository=$(VARNISH_IMAGE) \
--set vikingService.varnish.image.tag=$(VARNISH_TAG) \
--set vikingService.haproxy.image.repository=$(HAPROXY_IMAGE) \
--set vikingService.haproxy.image.tag=$(HAPROXY_TAG)
@helm install viking-ingress-env $(CHARTDIR)/viking-test-app \
--values values.yaml
deploy-cli-args-kubectl:
@kubectl apply -f ../hello/cafe.yaml
@kubectl apply -f cafe-ingress.yaml
@kubectl apply -f cli-args.yaml
deploy-proxy-kubectl:
@kubectl apply -f ../hello/cafe.yaml
@kubectl apply -f cafe-ingress.yaml
@kubectl apply -f proxy.yaml
deploy-env-kubectl:
@kubectl apply -f ../hello/cafe.yaml
@kubectl apply -f cafe-ingress.yaml
@kubectl apply -f env.yaml
# TESTOPTS are passed to varnishtest, e.g.: make TESTOPTS=-v verify
verify-cli-args:
$(mkdir)/verify_cli-args.sh
verify-proxy:
$(mkdir)/verify_proxy.sh
verify-env:
$(mkdir)/verify_env.sh
undeploy-cli-args-kubectl:
@kubectl delete -f cli-args.yaml
@kubectl delete -f cafe-ingress.yaml
@kubectl delete -f ../hello/cafe.yaml
$(mkdir)/wait_delete.sh app=varnish-ingress,example=cli-args
undeploy-proxy-kubectl:
@kubectl delete -f proxy.yaml
@kubectl delete -f cafe-ingress.yaml
@kubectl delete -f ../hello/cafe.yaml
$(mkdir)/wait_delete.sh app=varnish-ingress,example=proxy
undeploy-env-kubectl:
@kubectl delete -f env.yaml
@kubectl delete -f cafe-ingress.yaml
@kubectl delete -f ../hello/cafe.yaml
$(mkdir)/wait_delete.sh app=varnish-ingress,example=env
undeploy-cli-args-helm:
@helm uninstall viking-ingress-cli-args
@helm uninstall viking-service-cli-args
$(mkdir)/wait_delete.sh app=varnish-ingress,example=cli-args
undeploy-proxy-helm:
@helm uninstall viking-ingress-proxy
@helm uninstall viking-service-proxy
$(mkdir)/wait_delete.sh app=varnish-ingress,example=proxy
undeploy-env-helm:
@helm uninstall viking-ingress-env
@helm uninstall viking-service-env
$(mkdir)/wait_delete.sh app=varnish-ingress,example=env
deploy-cli-args:
deploy-proxy:
deploy-env:
undeploy-cli-args:
undeploy-proxy:
undeploy-env:
ifeq ($(DEPLOY),kubectl)
deploy-cli-args: deploy-cli-args-kubectl
deploy-proxy: deploy-proxy-kubectl
deploy-env: deploy-env-kubectl
undeploy-cli-args: undeploy-cli-args-kubectl
undeploy-proxy: undeploy-proxy-kubectl
undeploy-env: undeploy-env-kubectl
else
deploy-cli-args: deploy-cli-args-helm
deploy-proxy: deploy-proxy-helm
deploy-env: deploy-env-helm
undeploy-cli-args: undeploy-cli-args-helm
undeploy-proxy: undeploy-proxy-helm
undeploy-env: undeploy-env-helm
endif
deploy:
verify:
undeploy:
ifeq ($(EXAMPLE),cli-args)
deploy: deploy-cli-args
verify: verify-cli-args
undeploy: undeploy-cli-args
else ifeq ($(EXAMPLE),proxy)
deploy: deploy-proxy
verify: verify-proxy
undeploy: undeploy-proxy
else ifeq ($(EXAMPLE),env)
deploy: deploy-env
verify: verify-env
undeploy: undeploy-env
else
$(error EXAMPLE must be set to cli-args, proxy, or env)
endif
.PHONY: all $(MAKECMDGOALS)
apiVersion: v1
kind: Service
metadata:
name: pod-template-examples-svc
name: pod-template-examples
labels:
app: varnish-ingress
spec:
......
apiVersion: v1
kind: Service
metadata:
name: pod-template-examples-svc
name: pod-template-examples
labels:
app: varnish-ingress
spec:
......
apiVersion: v1
kind: Service
metadata:
name: pod-template-examples-svc
name: pod-template-examples
labels:
app: varnish-ingress
spec:
......
nameOverride: pod-template-examples
fullnameOverride: pod-template-examples
vikingService:
varnish:
extraArgs:
- -s
- malloc,256m
- -t
- "900"
- -p
- workspace_client=256k
## Name of the ingress class to route through this controller
##
ingressClass: varnish
replicaCount: 1
# labels to add to the pod container metadata
podLabels:
app: varnish-ingress
example: cli-args
nameOverride: pod-template-examples
fullnameOverride: pod-template-examples
vikingService:
varnish:
extraEnvs:
- name: PROTO
value: PROXY
- name: HTTP_PORT
value: "81"
- name: READY_PORT
value: "8000"
- name: ADMIN_PORT
value: "7000"
- name: CONFIG_PORT
value: "9000"
- name: SECRET_PATH
value: /var/secret
- name: SECRET_FILE
value: adm.secret
admSecret:
path: /var/secret
file: adm.secret
service:
ports:
http: 81
httpTarget: 81
varnishadm: 7000
ready: 8000
config: 9000
haproxy:
extraEnvs:
- name: VARNISH_READY_PORT
value: "8000"
## Name of the ingress class to route through this controller
##
ingressClass: varnish
replicaCount: 1
# labels to add to the pod container metadata
podLabels:
app: varnish-ingress
example: env
nameOverride: pod-template-examples
fullnameOverride: pod-template-examples
vikingService:
varnish:
extraEnvs:
- name: PROTO
value: PROXY
## Name of the ingress class to route through this controller
##
ingressClass: varnish
replicaCount: 1
# labels to add to the pod container metadata
podLabels:
app: varnish-ingress
example: proxy
apps:
coffee:
image: nginxdemos/hello:plain-text
replicas: 2
tea:
image: nginxdemos/hello:plain-text
replicas: 3
ingress:
name: cafe-ingress
rules:
- host: cafe.example.com
paths:
- path: /tea
app: tea
- path: /coffee
app: coffee
vikingAdmSvc: pod-template-examples-admin
......@@ -5,13 +5,11 @@ source ${MYDIR}/../../test/utils.sh
LOCALPORT=${LOCALPORT:-8888}
# wait_until_deleted app=varnish-ingress,example!=cli-args
set -e
wait_until_ready example=cli-args
wait_until_configured example=cli-args
kubectl port-forward svc/pod-template-examples-svc ${LOCALPORT}:80 >/dev/null &
kubectl port-forward svc/pod-template-examples ${LOCALPORT}:80 >/dev/null &
trap 'kill $(jobs -p)' EXIT
wait_for_port ${LOCALPORT}
......
......@@ -10,7 +10,7 @@ wait_until_ready example=env
# Config check is at non-default port 9000.
wait_until_configured example=env default 120 9000
kubectl port-forward svc/pod-template-examples-svc ${LOCALPORT}:81 >/dev/null &
kubectl port-forward svc/pod-template-examples ${LOCALPORT}:81 >/dev/null &
trap 'kill $(jobs -p)' EXIT
wait_for_port ${LOCALPORT}
......
#! /bin/bash -x
function dump_controller_log {
echo "error status $?"
local pod=( $(kubectl get pods -n kube-system -l app=varnish-ingress-controller --no-headers -o custom-columns=":metadata.name") )
kubectl logs -n kube-system ${pod}
}
MYDIR=$(dirname ${BASH_SOURCE[0]})
source ${MYDIR}/../../test/utils.sh
LOCALPORT=${LOCALPORT:-8888}
set -e
# trap dump_controller_log ERR
wait_until_ready example=proxy
wait_until_configured example=proxy
kubectl port-forward svc/pod-template-examples-svc ${LOCALPORT}:80 >/dev/null &
kubectl port-forward svc/pod-template-examples ${LOCALPORT}:80 >/dev/null &
trap 'kill $(jobs -p)' EXIT
wait_for_port ${LOCALPORT}
......
#! /bin/bash -ex
if [ -z "$1" ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 label [namespace] [timeout]"
exit 1
fi
MYDIR=$(dirname ${BASH_SOURCE[0]})
source ${MYDIR}/../../test/utils.sh
wait_until_deleted "$@"
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