Commit 6e8f849e authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

add skript to test and debug VILLASweb in our K8S cluster

parent 5627e80b
#!/bin/bash
kubectl -n services port-forward svc/postgres-postgresql 5432:5432 & PF1=$!
kubectl -n services port-forward svc/broker 5672:5672 & PF2=$!
set -e
NS=villas-demo
NS=${NS:-villas}
MK="minikube"
KCTL="kubectl -n${NS}"
HELM="helm -n${NS}"
# CHART="villas"
CHART="~/workspace/rwth/acs/public/catalogue/charts/villas"
POSTGRES_USER=$(kubectl -n ${NS} get secret postgres-credentials -o json | jq -r .data.username | base64 -d)
POSTGRES_PASS=$(kubectl -n ${NS} get secret postgres-credentials -o json | jq -r .data.password | base64 -d)
RABBITMQ_USER=$(kubectl -n ${NS} get secret postgres-credentials -o json | jq -r .data.username | base64 -d)
RABBITMQ_PASS=$(kubectl -n ${NS} get secret postgres-credentials -o json | jq -r .data.password | base64 -d)
CONFIG=$(mktemp)
NAME="villas"
go test ./routes/healthz -p 1 --args \
-mode test \
-db-host localhost -db-name villas \
-db-user ${POSTGRES_USER} -db-pass ${POSTGRES_PASS} \
-amqp-host localhost \
-amqp-user ${RABBITMQ_USER} -amqp-pass ${RABBITMQ_PASS}
function cleanup() {
kill $PF1 $PF2 $PF3
wait $PF1 $PF2 $PF3
kill $PF1 $PF2
wait $PF1 $PF2
rm ${CONFIG}
echo "Goodbye"
}
trap cleanup EXIT
if [ -n "${USE_MINIKUBE}" ]; then
MK_START_OPTS="--addons=ingress"
if [ $(uname -s) == Darwin ]; then
# https://github.com/kubernetes/minikube/issues/7332
MK_START_OPTS+="--vm=true"
fi
${MK} start ${MK_START_OPTS}
kubectl -n kube-system expose deployment ingress-nginx-controller --type=LoadBalancer || true
IP=$(minikube ip)
PORT=$(kubectl -n kube-system get service ingress-nginx-controller --output='jsonpath={.spec.ports[0].nodePort}')
# Add pseudo hostname to /etc/hosts
echo "Please provide your root password for modifiying /etc/hosts"
sudo sed -in "/^${IP}.*/d" /etc/hosts
echo "${IP} minikube" | sudo tee -a /etc/hosts
HELM_OPTS="--set web.backend.enabled=false \
--set web.backend.external.ip=${IP} \
--set web.backend.external.port=4000 \
--set web.admin.password=admin \
--set ingress.host=minikube"
# Check if chart has already been deployed before
if helm get values villas > /dev/null; then
RABBITMQ_ERLANG_COOKIE=$(kubectl get secret --namespace default villas-broker -o jsonpath="{.data.rabbitmq-erlang-cookie}" | base64 --decode)
RABBITMQ_PASSWORD=$(kubectl get secret --namespace default villas-broker -o jsonpath="{.data.rabbitmq-password}" | base64 --decode)
HELM_OPTS+=" --set broker.auth.password=${RABBITMQ_PASSWORD} --set broker.auth.erlangCookie=${RABBITMQ_ERLANG_COOKIE}"
fi
${HELM} upgrade \
${HELM_OPTS} \
--install \
--create-namespace \
--wait \
--repo https://packages.fein-aachen.org/helm/charts \
${NAME} ${CHART}
fi
# Get backend config from cluster
${KCTL} get cm ${NAME}-web -o 'jsonpath={.data.config\.yaml}' > ${CONFIG}
# Enable access of backend to db, broker and s3
export DB_HOST=localhost
export DB_PASS=$(${KCTL} get secret ${NAME}-database -o 'jsonpath={.data.postgresql-password}' | base64 -d)
export AMQP_HOST=localhost
export AMQP_PASS=$(${KCTL} get secret ${NAME}-broker -o 'jsonpath={.data.rabbitmq-password}' | base64 -d)
export AWS_ACCESS_KEY_ID=$(${KCTL} get secret ${NAME}-s3 -o 'jsonpath={.data.accesskey}' | base64 -d)
export AWS_SECRET_ACCESS_KEY=$(${KCTL} get secret ${NAME}-s3 -o 'jsonpath={.data.secretkey}' | base64 -d)
# Setup port forwards for backend
if [ -n "${USE_EXTERNAL_POSTGRESQL}" ]; then
kubectl -n postgresql port-forward svc/postgresql 5432:5432 & PF1=$!
else
${KCTL} port-forward svc/${NAME}-database 5432:5432 & PF1=$!
fi
${KCTL} port-forward svc/${NAME}-broker 5672:5672 & PF2=$!
sleep 2
if [ -n "${USE_MINIKUBE}" ]; then
# python -mwebbrowser http://minikube:${PORT}
echo
echo "==========================================="
echo "Access VILLASweb at http://minikube:${PORT}"
echo "==========================================="
echo
fi
go run start.go -config ${CONFIG}
Supports Markdown
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