forked from HYDPublic/ops-kube-db-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess-db
executable file
·63 lines (54 loc) · 1.51 KB
/
access-db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
### access-db
###
# TODO: update `--db` flag to represent the actual db name once that is changed in the code
###
NAMESPACE=$1
NAME=$2
if [ -z "${NAMESPACE}" -o -z "${NAME}" ]
then
echo
echo please provide namespace and postgresdb name on the command line
echo ie. ./access-db namespace example-db
echo
exit 1
fi
if [ -z $(which jq) ]
then
echo
echo "missing jq - please install it and rerun"
echo "ie. brew install jq"
echo
exit 1
fi
DB_SECRET_NAME="$NAMESPACE-$NAME-appadmin"
DB_AUTH=`kubectl get -n $NAMESPACE secrets $DB_SECRET_NAME -o json`
DB_USER=`echo $DB_AUTH | jq -r '.data.DB_USER'|base64 --decode`
DB_PASSWORD=`echo $DB_AUTH | jq -r '.data.DB_PASSWORD'|base64 --decode`
DB_HOST=`echo $DB_AUTH | jq -r '.data.DB_HOST'|base64 --decode`
POD_NAME="pgweb-${USER//[.]/-}"
function cleanup {
kubectl -n $NAMESPACE delete pod $POD_NAME
}
trap cleanup EXIT
PGWEB_VERSION=0.9.10
kubectl run -n $NAMESPACE $POD_NAME \
--generator run-pod/v1 \
--pod-running-timeout=1h \
--image=sosedoff/pgweb:$PGWEB_VERSION -- \
pgweb --host $DB_HOST \
--user "$DB_USER" \
--db postgres \
--pass \"$DB_PASSWORD\"
# WAIT FOR POD TO BE READY
while true
do
sleep 1
STATUS=`kubectl -n $NAMESPACE get pod $POD_NAME -o template --template={{.status.phase}}`
echo "Waiting for pod to be ready: $STATUS ..."
if [[ $STATUS == *"Running"* ]]; then
break
fi
done
echo "Access on http://localhost:8081"
kubectl -n $NAMESPACE port-forward $POD_NAME 8081