-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.sh
executable file
·147 lines (125 loc) · 2.84 KB
/
load.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
NUM_NAMESPACES=15
# derived from https://gist.github.com/davejamesmiller/1965569
ask() {
# https://djm.me/ask
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)<Paste>
echo -n "$1 [$prompt]:"
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
if [ $? -ne 0 ]; then
fatal "ERROR: Could not ask for user input - please run via interactive shell"
fi
# Default? (e.g user presses enter)
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
* ) echo "invalid reply: $reply"; return 1 ;;
esac
}
show_usage() {
echo ""
echo "Setup Postgres on the cluster"
echo ""
echo "Options:"
echo " -n <number> Number of namespaces to create and deploy postgres on"
echo " "
echo "Commands:"
echo " create Install a Postgres statefulset on the Kubernetes cluster."
echo " clean Cleanup Postgres statefulset on the cluster."
exit
}
setupStorageClasses(){
echo "Create Storageclasses...."
groupsnaps/sc/storageClasses.sh create
}
deleteStorageClasses(){
echo "Cleanup Storageclasses....."
groupsnaps/sc/storageClasses.sh cleanup
}
deleteNamespaces(){
for ((namespace=0; namespace < $NUM_NAMESPACES; namespace++ ))
do
kubectl delete ns ns-$namespace
done;
}
createNamespaces(){
for ((namespace=0; namespace < $NUM_NAMESPACES; namespace++ ))
do
kubectl create namespace ns-$namespace
done;
}
installApps(){
createPostgres
createWordpress
}
createPostgres() {
echo "Deploying Postgres... in ns-$namespace"
groupsnaps/postgres/postgres.sh ns-$namespace
}
createWordpress(){
echo "Deploying Wordpress... in ns-$namespace"
groupsnaps/wordpress/wordpress.sh ns-$namespace
}
setup(){
setupStorageClasses
createNamespaces
deployApps
}
teardown(){
deleteStorageClasses
deleteNamespaces
}
deployApps(){
for ((namespace=0; namespace < $NUM_NAMESPACES; namespace++ ))
do
installApps
done;
}
OPTIONS=
while getopts "n:" opt; do
case $opt in
n ) NUM_NAMESPACES="$OPTARG";;
\? ) show_usage;;
esac
done
shift "$((OPTIND-1))"
if [ $# -lt 1 ]; then
echo "?specify create or cleanup command"
show_usage
fi
case "$1" in
create)
COMMAND=$1
;;
clean)
COMMAND=$1
;;
*)
echo "?Invalid command $1"
show_usage
;;
esac
case "$COMMAND" in
create)
setup
;;
clean)
teardown
;;
esac