forked from mjura/automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaasp-devenv
executable file
·290 lines (237 loc) · 7.98 KB
/
caasp-devenv
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/sh
#
# READ THIS BEFORE ADDING ANYTHING HERE.
#
# This script should remain as simple as possible, with
# options only for the most commonly used options of the
# tools it orchestrates. If it's not something most
# developers would use at least once a week, then it doesn't
# belong here.
#
# This script should be as dumb as possible, it should
# contain the most commonly used options for each of the
# other tools, and no more. If you need to customize the
# options for a tool, use that tool directly instead!
set -euo pipefail
DIR="$( cd "$( dirname "$0" )" && pwd )"
# options
RUN_SETUP=
RUN_BUILD=
RUN_UPDATE_DEPLOYMENT=
RUN_BOOTSTRAP=
RUN_TESTINFRA=
RUN_DESTROY=
RUN_PLAN=
ACTION=
MASTERS=${CAASP_NUM_MASTERS:-1}
WORKERS=${CAASP_NUM_WORKERS:-2}
IMAGE=${CAASP_IMAGE:-channel://devel}
VANILLA=${CAASP_VANILLA:-}
DISABLE_MELTDOWN_SPECTRE=${CAASP_DISABLE_MELTDOWN_SPECTRE:-}
PROXY=${CAASP_HTTP_PROXY:-}
PARALLELISM=${CAASP_PARALLELISM:-1}
ENABLE_TILLER=${CAASP_ENABLE_TILLER:-false}
EXTRA_REPO=${CAASP_EXTRA_REPO:-}
# base distribution used for setting up dependencies, and the packages to install
DIST_BASE="opensuse.org/repositories/Virtualization:/containers"
DIST_PACKAGES="jq \
python-tox \
python-devel \
python-requests \
libsodium-devel \
python-openstackclient \
python-novaclient \
python-heatclient \
terraform \
terraform-provider-libvirt \
guestfs-tools \
qemu-kvm \
docker \
libvirt-daemon-qemu \
guestfs-tools \
ca-certificates-suse"
USAGE=$(cat <<USAGE
Usage:
* Setup your workstation
--setup Install Dev Env Dependencies
* Building a cluster
-b|--build Run the CaaSP KVM Build Step
-m|--masters <INT> Number of masters to build (Default: CAASP_NUM_MASTERS)
-w|--workers <INT> Number of workers to build (Default: CAASP_NUM_WORKERS)
-u|--update-deployment Update Terraform deployment (Default: false)
-d|--destroy Run the CaaSP KVM Destroy Step
-i|--image Image to use (Default: CAASP_IMAGE)
--vanilla Do not inject devenv code, use vanilla caasp (Default: false)
--disable-meltdown-spectre-fixes Disable meltdown and spectre fixes (Default: false)
--enable-tiller Enable Helm Tiller
* Bootstraping a cluster
Velum Username: [email protected]
Velum Password: password
-B|--bootstrap Bootstrap CaaSP cluster
* Testing a cluster
-T|--testinfra Run testinfra tests
* Common options
-p|--parallelism Set terraform parallelism (Default: CAASP_PARALLELISM)
-P|--proxy Set HTTP Proxy (Default: CAASP_HTTP_PROXY)
* Advanced Options
--plan Run the CaaSP KVM Plan Step
--extra-repo <STR> URL of a custom repository on the master(s)/worker(s) (Default: CAASP_EXTRA_REPO)
* Examples:
Build, Bootstrap and Test a cluster
$0 --build -m 1 -w 2 --bootstrap --testinfra
Bootstrap and Test a pre-made cluster
$0 --bootstrap --testinfra
Build a 1 master, 2 worker cluster using the latest kubic image
$0 --build -m 1 -w 2 --image channel://kubic
Add a worker node to a running cluster
$0 --update-deployment -m 1 -w 3
Build a cluster and add a custom repository on the master/worker(s)
$0 --build -m 1 -w 2 --extra-repo https://download.opensuse.org/repositories/devel:/CaaSP:/Head:/ControllerNode:/TestUpdates
USAGE
)
# Utility methods
log() { (>&2 echo ">>> [caasp-devenv] $@") ; }
warn() { log "WARNING: $@" ; }
error() { log "ERROR: $@" ; exit 1 ; }
check_file() { [ -f "$1" ] || error "File $1 doesn't exist!" ; }
usage() { echo "$USAGE" ; exit 0 ; }
# parse options
while [[ $# > 0 ]] ; do
case $1 in
--setup)
ACTION=1
RUN_SETUP=1
;;
-b|--build)
ACTION=1
RUN_BUILD=1
;;
-m|--masters)
MASTERS="$2"
shift
;;
-w|--workers)
WORKERS="$2"
shift
;;
-d|--destroy)
ACTION=1
RUN_DESTROY=1
;;
-u|--update-deployment)
ACTION=1
RUN_UPDATE_DEPLOYMENT=1
;;
-i|--image)
IMAGE="$2"
shift
;;
--vanilla)
VANILLA="true"
;;
--disable-meltdown-spectre-fixes)
DISABLE_MELTDOWN_SPECTRE="true"
;;
--enable-tiller)
ENABLE_TILLER=true
;;
-B|--bootstrap)
ACTION=1
RUN_BOOTSTRAP=1
;;
-T|--testinfra)
ACTION=1
RUN_TESTINFRA=1
;;
-p|--parallelism)
PARALLELISM="$2"
shift
;;
-P|--proxy)
PROXY="$2"
shift
;;
--plan)
ACTION=1
RUN_PLAN=1
;;
--extra-repo)
EXTRA_REPO="$2"
shift
;;
-h|--help)
usage
;;
esac
shift
done
##############################################################
CAASP_KVM_ARGS="-m $MASTERS -w $WORKERS --image $IMAGE"
[ -n "$PARALLELISM" ] && CAASP_KVM_ARGS="$CAASP_KVM_ARGS --parallelism=$PARALLELISM"
[ -n "$PROXY" ] && CAASP_KVM_ARGS="$CAASP_KVM_ARGS --proxy $PROXY"
[ -n "$VANILLA" ] && CAASP_KVM_ARGS="$CAASP_KVM_ARGS --vanilla"
[ -n "$DISABLE_MELTDOWN_SPECTRE" ] && CAASP_KVM_ARGS="$CAASP_KVM_ARGS --disable-meltdown-spectre-fixes"
[ -n "$EXTRA_REPO" ] && CAASP_KVM_ARGS="$CAASP_KVM_ARGS --extra-repo $EXTRA_REPO"
export ENVIRONMENT="$DIR/caasp-kvm/environment.json"
# Core methods
setup() {
log "Installing CaaSP Development Environment Requiemnts"
local dist=$(lsb-release -sd | tr -d '"' | tr " " "_")
if ! zypper lr -dU | grep --quiet "suse.de/ibs/SUSE:/CA" ; then
log "Adding SUSE:CA Zypper repo"
sudo zypper ar "http://download.suse.de/ibs/SUSE:/CA/${dist}/SUSE:CA.repo"
sudo zypper --gpg-auto-import-keys ref SUSE_CA
fi
if ! zypper lr -dU | grep --quiet "$DIST_BASE" ; then
log "Adding Virtualization:containers Zypper repo"
sudo zypper ar "http://download.$DIST_BASE/${dist}/Virtualization:containers.repo"
sudo zypper --gpg-auto-import-keys ref Virtualization_containers
fi
# || : is necessary, as Zypper exits non-zero for "no changes".
sudo zypper in --no-confirm $DIST_PACKAGES || :
# Enable and start services, if disabled
sudo systemctl enable --now docker
sudo systemctl enable --now libvirtd
# Ensure the current user has access to docker and libvirt
sudo usermod -aG docker,libvirt $USER
(cd "$DIR/velum-bootstrap" && ./velum-interactions --setup)
warn "You should now logout and back in again, in order for group membership changes to be reflected"
}
plan() {
log "Planning CaaSP KVM Environment"
(cd "$DIR/caasp-kvm" && ./caasp-kvm --plan $CAASP_KVM_ARGS )
}
build() {
log "Starting CaaSP KVM Environment"
(cd "$DIR/caasp-kvm" && ./caasp-kvm --build $CAASP_KVM_ARGS )
}
update_deployment() {
log "Updating CaaSP KVM Environment"
(cd "$DIR/caasp-kvm" && ./caasp-kvm --update-deployment $CAASP_KVM_ARGS )
}
bootstrap() {
log "Bootstrap CaaSP Environment"
local extra_flags=""
if [ "$ENABLE_TILLER" == "true" ]; then
extra_flags="$extra_flags --enable-tiller"
fi
[ -f "$ENVIRONMENT" ] || error "no environment file found at $ENVIRONMENT"
(cd "$DIR/velum-bootstrap" && ./velum-interactions --configure --bootstrap $extra_flags)
}
testinfra() {
log "Testing CaaSP Environment using testinfra"
[ -f "$ENVIRONMENT" ] || error "no environment file found at $ENVIRONMENT"
(cd "$DIR/testinfra" && env ENVIRONMENT_JSON="$ENVIRONMENT" tox)
}
destroy() {
log "Destroy CaaSP KVM Environment"
(cd "$DIR/caasp-kvm" && ./caasp-kvm --destroy $CAASP_KVM_ARGS)
}
[ -n "$ACTION" ] || usage
[ -n "$RUN_SETUP" ] && setup
[ -n "$RUN_PLAN" ] && plan
[ -n "$RUN_BUILD" -a -z "$RUN_UPDATE_DEPLOYMENT" ] && build
[ -n "$RUN_UPDATE_DEPLOYMENT" ] && update_deployment
[ -n "$RUN_BOOTSTRAP" ] && bootstrap
[ -n "$RUN_TESTINFRA" ] && testinfra
[ -n "$RUN_DESTROY" ] && destroy