forked from crosscloudci/cross-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.sh
executable file
·400 lines (345 loc) · 15.9 KB
/
provision.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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!/bin/bash
# Usage
#
# provision.sh <provider>-<command> <name> <config-backend>
#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_retry() {
[ -z "${2}" ] && return 1
echo -n ${1}
until printf "." && "${@:2}" &>/dev/null; do sleep 5.2; done; echo "✓"
}
set -e
RED='\033[0;31m'
NC='\033[0m' # No Color
# Setup Enviroment Using $NAME
export TF_VAR_name="$2"
export TF_VAR_data_dir=$(pwd)/data/"$4"
export TF_VAR_packet_api_key=${PACKET_AUTH_TOKEN}
export TF_VAR_google_project=${GOOGLE_PROJECT}
# Configure Artifacts
if [ ! -e $KUBELET_ARTIFACT ] ; then
export TF_VAR_kubelet_artifact=$KUBELET_ARTIFACT
fi
if [ ! -e $CNI_ARTIFACT ] ; then
export TF_VAR_cni_artifact=$CNI_ARTIFACT
fi
if [ ! -e $ETCD_IMAGE ] ; then
export TF_VAR_etcd_image=$ETCD_IMAGE
fi
if [ ! -e $ETCD_TAG ] ; then
export TF_VAR_etcd_tag=$ETCD_TAG
fi
if [ ! -e $KUBE_APISERVER_IMAGE ] ; then
export TF_VAR_kube_apiserver_image=$KUBE_APISERVER_IMAGE
fi
if [ ! -e $KUBE_APISERVER_TAG ] ; then
export TF_VAR_kube_apiserver_tag=$KUBE_APISERVER_TAG
fi
if [ ! -e $KUBE_CONTROLLER_MANAGER_IMAGE ] ; then
export TF_VAR_kube_controller_manager_image=$KUBE_CONTROLLER_MANAGER_IMAGE
fi
if [ ! -e $KUBE_CONTROLLER_MANAGER_TAG ] ; then
export TF_VAR_kube_controller_manager_tag=$KUBE_CONTROLLER_MANAGER_TAG
fi
if [ ! -e $KUBE_SCHEDULER_IMAGE ] ; then
export TF_VAR_kube_scheduler_image=$KUBE_SCHEDULER_IMAGE
fi
if [ ! -e $KUBE_SCHEDULER_TAG ] ; then
export TF_VAR_kube_scheduler_tag=$KUBE_SCHEDULER_TAG
fi
if [ ! -e $KUBE_PROXY_IMAGE ] ; then
export TF_VAR_kube_proxy_image=$KUBE_PROXY_IMAGE
fi
if [ ! -e $KUBE_PROXY_TAG ] ; then
export TF_VAR_kube_proxy_tag=$KUBE_PROXY_TAG
fi
# tfstate, sslcerts, and ssh keys are currently stored in TF_VAR_data_dir
mkdir -p $TF_VAR_data_dir
# Run CMD
if [ "$1" = "aws-deploy" ] ; then
cd ${DIR}/aws
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=aws-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply ${DIR}/aws
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/aws
time terraform apply ${DIR}/aws
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
export NODES="$(expr $TF_VAR_master_node_count + $TF_VAR_worker_node_count)"
KUBECTL_PATH=$(which kubectl) NUM_NODES="$NODES" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "❤ Installing Helm" helm init
_retry "Wait for Tiller Deployment to be available" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$1" = "aws-destroy" ] ; then
cd ${DIR}/aws
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=aws-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force ${DIR}/aws
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/aws
fi
elif [ "$1" = "azure-deploy" ] ; then
# There are some dependency issues around cert,sshkey,k8s_cloud_config, and dns
# since they use files on disk that are created on the fly
# should probably move these to data resources
cd ${DIR}/azure
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=azure-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
terraform apply -target azurerm_resource_group.cncf ${DIR}/azure && \
terraform apply -target module.network.azurerm_virtual_network.cncf ${DIR}/azure || true && \
terraform apply -target module.network.azurerm_subnet.cncf ${DIR}/azure || true && \
time terraform apply ${DIR}/azure
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
terraform apply -target azurerm_resource_group.cncf ${DIR}/azure && \
terraform apply -target module.network.azurerm_virtual_network.cncf ${DIR}/azure || true && \
terraform apply -target module.network.azurerm_subnet.cncf ${DIR}/azure || true && \
time terraform apply ${DIR}/azure
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
export NODES="$(expr $TF_VAR_master_node_count + $TF_VAR_worker_node_count)"
KUBECTL_PATH=$(which kubectl) NUM_NODES="$NODES" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "❤ Installing Helm" helm init
_retry "Wait for Tiller Deployment to be available" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$1" = "azure-destroy" ] ; then
cd ${DIR}/azure
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=azure-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force ${DIR}/azure || true
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/azure || true
fi
# Begin OpenStack
elif [[ "$1" = "openstack-deploy" || "$1" = "openstack-destroy" ]] ; then
cd ${DIR}/openstack
# initialize based on the config type
if [ "$3" = "s3" ] ; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=openstack-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
elif [ "$3" = "file" ] ; then
cp ../file-backend.tf .
terraform init -backend-config "path=/cncf/data/${TF_VAR_NAME}/terraform.tfstate"
fi
# deploy/destroy implementations
if [ "$1" = "openstack-deploy" ] ; then
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply ${DIR}/openstack
elif [ "$1" = "openstack-destroy" ] ; then
time terraform destroy -force ${DIR}/openstack || true
fi
# End OpenStack
elif [ "$1" = "packet-deploy" ] ; then
cd ${DIR}/packet
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=packet-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
# ensure kubeconfig & resolv.conf is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/packet
time terraform apply ${DIR}/packet
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/packet
time terraform apply ${DIR}/packet
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
export NODES="$(expr $TF_VAR_master_node_count + $TF_VAR_worker_node_count)"
KUBECTL_PATH=$(which kubectl) NUM_NODES="$NODES" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "❤ Installing Helm" helm init
_retry "Wait for Tiller Deployment to be available" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$1" = "packet-destroy" ] ; then
cd ${DIR}/packet
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=packet-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force ${DIR}/packet
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/packet
fi
elif [ "$1" = "gce-deploy" ] ; then
cd ${DIR}/gce
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=gce-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/gce
time terraform apply -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
time terraform apply ${DIR}/gce
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/gce
time terraform apply -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
time terraform apply ${DIR}/gce
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
export NODES="$(expr $TF_VAR_master_node_count + $TF_VAR_worker_node_count)"
KUBECTL_PATH=$(which kubectl) NUM_NODES="$NODES" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "❤ Installing Helm" helm init
_retry "Wait for Tiller Deployment to be available" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$1" = "gce-destroy" ] ; then
cd ${DIR}/gce
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=gce-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force ${DIR}/gce || true # Allow to Fail and clean up network on next step
time terraform destroy -force -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
time terraform destroy -force -target module.vpc.google_compute_network.cncf ${DIR}/gce
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/gce || true # Allow to Fail and clean up network on next step
time terraform destroy -force -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
time terraform destroy -force -target module.vpc.google_compute_network.cncf ${DIR}/gce
fi
elif [ "$1" = "gke-deploy" ] ; then
cd ${DIR}/gke
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=gke-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -target module.vpc ${DIR}/gke && \
time terraform apply ${DIR}/gke
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -target module.vpc ${DIR}/gke && \
time terraform apply ${DIR}/gke
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
_retry "❤ Installing Helm" helm init
_retry "Wait for Tiller Deployment to be available" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$1" = "gke-destroy" ] ; then
cd ${DIR}/gke
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=gke-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force -target module.cluster.google_container_cluster.cncf ${DIR}/gke || true
echo "sleep" && sleep 10 && \
time terraform destroy -force -target module.vpc.google_compute_network.cncf ${DIR}/gke || true
time terraform destroy -force ${DIR}/gke || true
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force -target module.cluster.google_container_cluster.cncf ${DIR}/gke || true
echo "sleep" && sleep 10 && \
time terraform destroy -force -target module.vpc.google_compute_network.cncf ${DIR}/gke || true
time terraform destroy -force ${DIR}/gke || true
fi
elif [ "$1" = "bluemix-deploy" ] ; then
cd ${DIR}/bluemix
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=bluemix-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint null_resource.kubeconfig || true
time terraform apply ${DIR}/bluemix
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint null_resource.kubeconfig || true
time terraform apply ${DIR}/bluemix
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
_retry "❤ Installing Helm" helm init
kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$1" = "bluemix-destroy" ] ; then
cd ${DIR}/gke
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=bluemix-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force ${DIR}/bluemix
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/bluemix
fi
fi