forked from irfanhabib/caasp-tf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
296 lines (242 loc) · 9.42 KB
/
Makefile
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
291
292
293
294
295
296
#
# Author(s): Alvaro Saurin <[email protected]>
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
#
# Makefile FOR DEVELOPERS
# if you are not a developer, just do "terraform apply"
#
# Usage:
# * install "sshpass", "wget"...
# * customize some of these vars (for example, putting them in a Makefile.local)
# * do "make dev-apply" (or some othe target)
#
# Note: you can overwrite these vars from command line with something like:
# make dev-apply CHECKOUTS_DIR=~/dev
# prefix for all the resources'
PREFIX = caasp
# pool used for images in libvirt
LIBVIRT_POOL_NAME = personal
LIBVIRT_POOL_DIR = ~/.libvirt/images
# some dis
CHECKOUTS_DIR = ~/Development/SUSE
SALT_DIR = $(CHECKOUTS_DIR)/k8s-salt
SALT_VM_DIR = /usr/share/salt/kubernetes
E2E_TESTS_RUNNER = $(CHECKOUTS_DIR)/automation/k8s-e2e-tests/e2e-tests
#####################################################################
# the directory with resources that will be copied to the VMs
RESOURCES_DIR = resources
VARS_STAGING_A = profiles/devel/images-staging-a.tfvars
VARS_STAGING_B = profiles/devel/images-staging-b.tfvars
# VMs we use
VMS_NODES = node_0 node_1
VMS_ALL = admin $(VMS_NODES)
VMS_NUM_MINIONS = 2
CAASPCTL = /tmp/caasp/caaspctl
RUN_CAASPCTL = bash $(CAASPCTL)
# environment variables we always pass to Terraform
TERRAFORM_VARS = TF_VAR_prefix=$(PREFIX) \
TF_VAR_img_pool=$(LIBVIRT_POOL_NAME) \
TF_VAR_salt_dir=$(SALT_DIR)
# common options for ssh, rsync, etc
SSH = sshpass -p "linux" ssh
SCP = sshpass -p "linux" scp
SSH_OPTS = -oStrictHostKeyChecking=no \
-oUserKnownHostsFile=/dev/null
EXCLUDE_ARGS = --exclude='*.tfstate*' \
--exclude='.git*' \
--exclude='Makefile' \
--exclude='README.md' \
--exclude='*.sublime-*' \
--exclude='.idea' \
--exclude='*.tgz'
RSYNC_OPTS = $(EXCLUDE_ARGS) -e '$(SSH) $(SSH_OPTS)' --delete
# stuff for building distributions
DIST_CONT = *.profile k8s-setup terraform
DIST_TAR = kubernetes-terraform.tgz
TAR_ARGS = $(EXCLUDE_ARGS) -zcvf
# a kubeconfig we will download from the master
KUBECONFIG = kubeconfig
# files to remove after a "destroy"
CLEANUP_FILES = terraform.tfstate* \
admin.{tar,crt,key} ca.crt \
$(KUBECONFIG) \
$(LIBVIRT_POOL_DIR)/$(PREFIX)_*
# the dashboard and node IPs (might need a "terraform refresh" after a while)
ADMIN_IP = `support/mk/get-admin-ip.sh`
NODES_IPS = `support/mk/get-node-ip.sh`
# you can customimze vars in a local Makefile
-include Makefile.local
####################################################################
# CAASP
####################################################################
all:
@echo "Makefile FOR DEVELOPERS"
@echo "For regular users please do: terraform apply"
dev-apply-with-args:
@echo ">>> Applying Terraform..."
@env $(TERRAFORM_VARS) terraform apply $(ARGS)
@sleep 10 && make dev-snapshot
dev-apply:
make dev-apply-with-args
dev-apply-staging-a:
make dev-apply-with-args ARGS="-var-file=$(VARS_STAGING_A) $(ARGS)"
dev-apply-staging-b:
make dev-apply-with-args ARGS="-var-file=$(VARS_STAGING_B) $(ARGS)"
dev-destroy:
-@for h in $(VMS_ALL) ; do \
echo ">>> Destroying snapshots for $(PREFIX)_$$h" ; \
while sudo virsh snapshot-delete $(PREFIX)_$$h --current &>/dev/null ; do echo ; done ; \
done
-terraform destroy -force
-rm -f $(CLEANUP_FILES)
-@notify-send "k8s: cluster destruction finished" &>/dev/null
dev-copy:
@echo ">>> Copying the VM's resources to /tmp/caasp"
@rsync -avz $(RSYNC_OPTS) $(RESOURCES_DIR)/common/ root@$(ADMIN_IP):/tmp/caasp/
@rsync -avz $(RSYNC_OPTS) $(RESOURCES_DIR)/admin/ root@$(ADMIN_IP):/tmp/caasp/admin/
@echo ">>> Making fs RW-able"
@make dev-ssh CMD='$(RUN_CAASPCTL) rw on'
@echo ">>> Copying the Salt scripts/pillar"
@rsync -avz $(RSYNC_OPTS) $(SALT_DIR)/ root@$(ADMIN_IP):$(SALT_VM_DIR)/
@echo ">>> Synchronizing Salt stuff"
@make dev-ssh CMD='$(RUN_CAASPCTL) salt sync'
dev-orch: dev-copy
@make dev-ssh CMD='$(RUN_CAASPCTL) orchestrate'
@rm -f $(KUBECONFIG)
-@notify-send "k8s: cluster orchestration finished" &>/dev/null
dev-reorch: dev-rollback _wait-20s dev-orch
dev: dev-apply dev-orch
dev-restart-master: dev-copy
@make dev-ssh CMD='$(RUN_CAASPCTL) salt restart-master'
dev-restart-api: dev-copy
@make dev-ssh CMD='$(RUN_CAASPCTL) salt restart-api'
# some times we might need to refresh data
# and readjust some stuff (ie, when IPs change)
dev-refresh:
support/mk/refresh-vms.sh
dev-kubeconfig: $(KUBECONFIG)
$(KUBECONFIG):
@echo ">>> Generating a kubeconfig"
@make dev-ssh CMD='$(RUN_CAASPCTL) kubeconfig gen'
@echo ">>> Getting the kubeconfig"
@$(SCP) -q $(SSH_OPTS) root@$(ADMIN_IP):.kube/config $(KUBECONFIG)
@echo ">>> done."
# run the e2e tests
dev-e2e: $(KUBECONFIG)
@echo ">>> Running the kubernetes e2e tests"
$(E2E_TESTS_RUNNER) --kubeconfig $(KUBECONFIG) $(E2E_ARGS)
-@notify-send "k8s: e2e tests finished" &>/dev/null
####################################################################
# profiles
dev-profile-apply: dev-profile-clean
@echo ">>> Applying development profile"
@for i in profiles/devel/profile-devel*.tf ; do ln -sf $$i ; done
dev-profile-clean:
@echo ">>> Cleaning profile files"
@for i in *.tf ; do \
if [ -L $$i ] ; then \
l=`readlink $$i` ; \
[[ $$l == profiles/* ]] && rm -f $$i ; \
fi ; \
done
####################################################################
# updates & reboots
dev-nodes-dist-update:
@make dev-ssh-nodes CMD='$(RUN_CAASPCTL) zypper update'
-@notify-send "k8s: cluster updates downloaded... would need a reboot" &>/dev/null
dev-nodes-reboot:
@make dev-ssh-nodes CMD='$(RUN_CAASPCTL) reboot'
-@notify-send "k8s: nodes rebooted" &>/dev/null
####################################################################
# some ssh convencience targets
dev-ssh: dev-ssh-admin
dev-ssh-admin:
@$(SSH) -q $(SSH_OPTS) root@$(ADMIN_IP) '$(CMD)'
dev-ssh-nodes:
@for node in $(NODES_IPS) ; do \
$(SSH) -q $(SSH_OPTS) root@$$node '$(CMD)' ; \
done
dev-ssh-node-0:
@$(SSH) $(SSH_OPTS) root@`support/mk/get-node-ip.sh 0` '$(CMD)'
dev-ssh-node-1:
@$(SSH) $(SSH_OPTS) root@`support/mk/get-node-ip.sh 1` '$(CMD)'
dev-ssh-salt-master:
@make dev-ssh CMD='$(RUN_CAASPCTL) salt $(CMD)'
####################################################################
# some logging utilities
dev-logs-salt-master:
@echo ">>> Dumping logs from the Salt master"
@make dev-ssh CMD='$(RUN_CAASPCTL) salt logs'
dev-logs-events:
@echo ">>> Dumping Salt events at the master"
@make dev-ssh CMD='$(RUN_CAASPCTL) salt events'
####################################################################
# VMs management
dev-snapshot:
@echo ">>> Creating snapshots..."
@for h in $(VMS_ALL) ; do \
sudo virsh snapshot-create --atomic $(PREFIX)_$$h ; \
done
-@notify-send "k8s: cluster creation finished" &>/dev/null
dev-suspend:
@echo ">>> Suspending VMs before rolling back"
-@for h in $(VMS_ALL) ; do \
sudo virsh suspend $(PREFIX)_$$h ; \
done
-@notify-send "k8s: all VMs suspended" &>/dev/null
dev-resume:
@echo ">>> Resuming VMs before rolling back"
-@for h in $(VMS_ALL) ; do \
sudo virsh resume $(PREFIX)_$$h ; \
done
-@notify-send "k8s: all VMs suspended" &>/dev/null
# NOTE: we need to "echo 1 > /proc/sys/vm/overcommit_memory"
# or qemu-kvm will kill our machine...
dev-rollback: dev-suspend
@for h in $(VMS_ALL) ; do \
echo ">>> Rolling back $(PREFIX)_$$h" ; \
sudo virsh snapshot-revert --current --running $(PREFIX)_$$h ; \
done
@echo ">>> Refreshing Terraform data"
-@make dev-refresh
-@notify-send "k8s: all VMs rolled back" &>/dev/null
####################################################################
# packages installation
_install-rpms-on:
@echo "Copying RPMs to $(NODE)"
@$(SSH) -q $(SSH_OPTS) root@$(NODE) 'rm -rf /tmp/rpms && mkdir -p /tmp/rpms'
@$(SCP) -q $(SSH_OPTS) rpms/* root@$(NODE):/tmp/rpms/
@$(SSH) -q $(SSH_OPTS) root@$(NODE) 'ls -lisah /tmp/rpms/*'
@echo "Importing keys"
@$(SSH) -q $(SSH_OPTS) root@$(NODE) 'caaspctl rw 1'
@$(SSH) -q $(SSH_OPTS) root@$(NODE) 'rpm --import /tmp/rpms/*.key /tmp/rpms/*.pub || /bin/true'
@echo "Installing packages"
@$(SSH) -q $(SSH_OPTS) root@$(NODE) 'caaspctl zypper in -y /tmp/rpms/*.rpm'
@echo "Rebooting $(NODE)"
@-$(SSH) -q $(SSH_OPTS) root@$(NODE) 'reboot'
-@notify-send "k8s: packages installed in $(NODE)" &>/dev/null
dev-install-rpms-nodes:
@for node in $(NODES_IPS) ; do \
make _install-rpms-on NODE=$$node ; \
done
####################################################################
# aux
.PHONY: _wait-20s
_wait-20s:
@echo ">>> Waiting some time..."
@sleep 20
####################################################################
# distribution
dist:
@echo "Creating distribution package"
tar $(TAR_ARGS) $(DIST_TAR) $(DIST_CONT)