-
Notifications
You must be signed in to change notification settings - Fork 59
/
provision.sh
executable file
·623 lines (527 loc) · 27.2 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
#!/bin/bash
# Usage
#
# provision.sh shell
# provision.sh <provider>-<command> <name> <config-backend>
#
# If the first argument is "shell" then exec into a shell and abandon
# the rest of the script.
if [ "$1" = "shell" ]; then exec /bin/bash; fi
# If the first argument is "kubectl" then execute kubectl with any
# of the remaining arguments.
if [ "${1}" = "kubectl" ]; then shift; exec /usr/local/bin/kubectl "${@}"; fi
# Initialize the configuration properties based on the command-line
# arguments OR on the corresponding environment variables.
CLOUD_CMD=$CLOUD-$COMMAND
if [ ! "$1" = "" ]; then CLOUD_CMD=$1; fi
if [ ! "$2" = "" ]; then NAME=$2; fi
if [ ! "$3" = "" ]; then BACKEND=$3; fi
if [ ! "$4" = "" ]; then DATA_FOLDER=$4; fi
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="$NAME"
export TF_VAR_data_dir=$(pwd)/data/"$DATA_FOLDER"
export TF_VAR_packet_api_key=${PACKET_AUTH_TOKEN}
export TF_VAR_master_node_count="${TF_VAR_master_node_count:-1}"
export TF_VAR_worker_node_count="${TF_VAR_worker_node_count:-1}"
# 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_ARTIFACT ] ; then
export TF_VAR_etcd_artifact=$ETCD_ARTIFACT
fi
if [ ! -e $KUBE_APISERVER_ARTIFACT ] ; then
export TF_VAR_kube_apiserver_artifact=$KUBE_APISERVER_ARTIFACT
fi
if [ ! -e $KUBE_CONTROLLER_MANAGER_ARTIFACT ] ; then
export TF_VAR_kube_controller_manager_artifact=$KUBE_CONTROLLER_MANAGER_ARTIFACT
fi
if [ ! -e $KUBE_SCHEDULER_ARTIFACT ] ; then
export TF_VAR_kube_scheduler_artifact=$KUBE_SCHEDULER_ARTIFACT
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 [ "$CLOUD_CMD" = "aws-deploy" ] ; then
cd ${DIR}/aws
if [ "$BACKEND" = "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 -auto-approve ${DIR}/aws
elif [ "$BACKEND" = "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 -auto-approve ${DIR}/aws
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
kubectl create -f /cncf/rbac/ || true
kubectl create -f /cncf/addons/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$CLOUD_CMD" = "aws-destroy" ] ; then
cd ${DIR}/aws
if [ "$BACKEND" = "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 [ "$BACKEND" = "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 [ "$CLOUD_CMD" = "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 [ "$BACKEND" = "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 -auto-approve ${DIR}/azure && \
terraform apply -target module.network.azurerm_virtual_network.cncf -auto-approve ${DIR}/azure || true && \
terraform apply -target module.network.azurerm_subnet.cncf -auto-approve ${DIR}/azure || true && \
time terraform apply -auto-approve ${DIR}/azure
elif [ "$BACKEND" = "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 -auto-approve ${DIR}/azure && \
terraform apply -target module.network.azurerm_virtual_network.cncf -auto-approve ${DIR}/azure || true && \
terraform apply -target module.network.azurerm_subnet.cncf -auto-approve ${DIR}/azure || true && \
time terraform apply -auto-approve ${DIR}/azure
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
kubectl create -f /cncf/rbac/ || true
kubectl create -f /cncf/addons/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$CLOUD_CMD" = "azure-destroy" ] ; then
cd ${DIR}/azure
if [ "$BACKEND" = "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 [ "$BACKEND" = "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 [[ "$CLOUD_CMD" = "openstack-deploy" || \
"$CLOUD_CMD" = "openstack-destroy" ]] ; then
cd ${DIR}/openstack
# initialize based on the config type
if [ "$BACKEND" = "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 [ "$BACKEND" = "file" ] ; then
cp ../file-backend.tf .
terraform init -backend-config "path=/cncf/data/${TF_VAR_NAME}/terraform.tfstate"
fi
# deploy/destroy implementations
if [ "$CLOUD_CMD" = "openstack-deploy" ] ; then
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -auto-approve ${DIR}/openstack
elif [ "$CLOUD_CMD" = "openstack-destroy" ] ; then
time terraform destroy -force ${DIR}/openstack || true
# Exit after destroying resources as further commands cause hang
exit
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
kubectl create -f /cncf/rbac/ || true
kubectl create -f /cncf/addons/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
# End OpenStack
elif [ "$CLOUD_CMD" = "packet-deploy" ] ; then
cd ${DIR}/packet
if [ "$BACKEND" = "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 -auto-approve ${DIR}/packet
elif [ "$BACKEND" = "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 -auto-approve ${DIR}/packet
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
kubectl create -f /cncf/rbac/ || true
if [ "$ARCH" = "arm64" ]; then
kubectl create -f /cncf/addons-arm/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --tiller-image=jessestuart/tiller --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
else
kubectl create -f /cncf/addons/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
fi
elif [ "$CLOUD_CMD" = "packet-destroy" ] ; then
cd ${DIR}/packet
if [ "$BACKEND" = "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 [ "$BACKEND" = "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 [ "$CLOUD_CMD" = "gce-deploy" ] ; then
cd ${DIR}/gce
if [ "$BACKEND" = "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 -auto-approve ${DIR}/gce
time terraform apply -auto-approve ${DIR}/gce
elif [ "$BACKEND" = "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 -auto-approve ${DIR}/gce
time terraform apply -auto-approve ${DIR}/gce
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
kubectl create -f /cncf/rbac/ || true
kubectl create -f /cncf/addons/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$CLOUD_CMD" = "gce-destroy" ] ; then
cd ${DIR}/gce
if [ "$BACKEND" = "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 [ "$BACKEND" = "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 [ "$CLOUD_CMD" = "gke-deploy" ] ; then
cd ${DIR}/gke
if [ "$BACKEND" = "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 apply -target module.vpc -auto-approve ${DIR}/gke && \
time terraform apply -auto-approve ${DIR}/gke
elif [ "$BACKEND" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform apply -target module.vpc -auto-approve ${DIR}/gke && \
time terraform apply -auto-approve ${DIR}/gke
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo $GOOGLE_CREDENTIALS > ${TF_VAR_data_dir}/keyfile.json
gcloud auth activate-service-account $GOOGLE_AUTH_EMAIL --key-file ${TF_VAR_data_dir}/keyfile.json --project $GOOGLE_PROJECT
gcloud container clusters get-credentials $TF_VAR_name --zone $GOOGLE_ZONE --project $GOOGLE_PROJECT
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
echo "kube-dns is already deployed, skipping"
kubectl create -f /cncf/rbac/helm-rbac.yml || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$CLOUD_CMD" = "gke-destroy" ] ; then
cd ${DIR}/gke
if [ "$BACKEND" = "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 [ "$BACKEND" = "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 [ "$CLOUD_CMD" = "ibmcloud-deploy" ] ; then
cd ${DIR}/ibm
if [ "$BACKEND" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=ibm-${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 -auto-approve ${DIR}/ibm
elif [ "$BACKEND" = "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 -auto-approve ${DIR}/ibm
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
echo "kube-dns is already deployed, skipping"
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
kubectl create -f /cncf/rbac/helm-rbac.yml || true
_retry "❤ Installing Helm" helm init
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
elif [ "$CLOUD_CMD" = "ibmcloud-destroy" ] ; then
cd ${DIR}/ibm
if [ "$BACKEND" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=ibm-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
time terraform destroy -force ${DIR}/ibm
elif [ "$BACKEND" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/ibm
fi
# Begin vSphere
elif [[ "$CLOUD_CMD" = "vsphere-deploy" || \
"$CLOUD_CMD" = "vsphere-destroy" || \
"$CLOUD_CMD" = "vsphere-validate" ]] ; then
cd ${DIR}/vsphere
if [ -n "$VSPHERE_SERVER" ]; then
export TF_VAR_vsphere_server=$VSPHERE_SERVER
fi
if [ -n "$VSPHERE_USER" ]; then
export TF_VAR_vsphere_user=$VSPHERE_USER
fi
if [ -n "$VSPHERE_PASSWORD" ]; then
export TF_VAR_vsphere_password=$VSPHERE_PASSWORD
fi
if [ -n "$VSPHERE_AWS_ACCESS_KEY_ID" ]; then
export TF_VAR_vsphere_aws_access_key_id=$VSPHERE_AWS_ACCESS_KEY_ID
fi
if [ -n "$VSPHERE_AWS_SECRET_ACCESS_KEY" ]; then
export TF_VAR_vsphere_aws_secret_access_key=$VSPHERE_AWS_SECRET_ACCESS_KEY
fi
if [ -n "$VSPHERE_AWS_REGION" ]; then
export TF_VAR_vsphere_aws_region=$VSPHERE_AWS_REGION
fi
# If VSPHERE_DESTROY_FORCE is set (true, dryrun) then use the
# destroy script to tear down the environment. This option does
# not require the Terraform state.
if [ "${CLOUD_CMD}" = "vsphere-destroy" ] && \
[ -n "${VSPHERE_DESTROY_FORCE}" ]; then
if [ "${BACKEND}" = "file" ]; then
export VSPHERE_TFSTATE_PATH="/cncf/data/${NAME}"
fi
time ./destroy-force.sh "${NAME}"
exit "${?}"
fi
# initialize based on the config type
if [ "$BACKEND" = "s3" ] ; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=vsphere-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
elif [ "$BACKEND" = "file" ] ; then
cp ../file-backend.tf .
terraform init -backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
fi
# deploy/destroy implementations
if [ "$CLOUD_CMD" = "vsphere-deploy" ] ; then
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -auto-approve ${DIR}/vsphere
elif [ "$CLOUD_CMD" = "vsphere-destroy" ] ; then
VSPHERE_DESTROY_SKIP=${VSPHERE_DESTROY_SKIP:-${DESTROY_SKIP}}
if [ "${VSPHERE_DESTROY_SKIP}" = "true" ]; then
echo "vsphere environment destruction disabled"
else
time terraform destroy -force ${DIR}/vsphere || true
fi
# Exit after destroying resources as further commands cause hang
exit
elif [ "$CLOUD_CMD" = "vsphere-validate" ] ; then
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
exit 0
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
kubectl create -f /cncf/rbac/ || true
kubectl create -f /cncf/addons/ || true
KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
# End vSphere
# Begin OCI
elif [[ "$CLOUD_CMD" = "oci-deploy" || \
"$CLOUD_CMD" = "oci-destroy" ]] ; then
cd ${DIR}/oci
if [ -n "$OCI_TENANCY_OCID" ]; then
export TF_VAR_oci_tenancy_ocid=$OCI_TENANCY_OCID
fi
if [ -n "$OCI_USER_OCID" ]; then
export TF_VAR_oci_user_ocid=$OCI_USER_OCID
fi
if [ -n "$OCI_FINGERPRINT" ]; then
export TF_VAR_oci_fingerprint=$OCI_FINGERPRINT
fi
if [ -n "$OCI_COREOS_OCID" ]; then
export TF_VAR_coreos_image_ocid=$OCI_COREOS_OCID
fi
# initialize based on the config type
if [ "$BACKEND" = "s3" ] ; then
cp ../s3-backend.tf .
terraform init \
-backend-config "bucket=${AWS_BUCKET}" \
-backend-config "key=oci-${TF_VAR_name}" \
-backend-config "region=${AWS_DEFAULT_REGION}"
elif [ "$BACKEND" = "file" ] ; then
cp ../file-backend.tf .
terraform init -backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
fi
# deploy/destroy implementations
if [ "$CLOUD_CMD" = "oci-deploy" ] ; then
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -auto-approve ${DIR}/oci
elif [ "$CLOUD_CMD" = "oci-destroy" ] ; then
time terraform destroy -force ${DIR}/oci || true
# Exit after destroying resources as further commands cause hang
exit
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
_retry "❤ Trying to connect to cluster with kubectl" kubectl get cs
_retry "❤ Ensure that the kube-system namespaces exists" kubectl get namespace kube-system
_retry "❤ Ensure that ClusterRoles are available" kubectl get ClusterRole.v1.rbac.authorization.k8s.io
_retry "❤ Ensure that ClusterRoleBindings are available" kubectl get ClusterRoleBinding.v1.rbac.authorization.k8s.io
# Need to run sed on the secrets files to add the OCI API key so that it doesn't appear in the TF output.
sed -e 's/^/ /g' /cncf/keys/oci_api_key.pem > /cncf/keys/oci_api_key_indented.pem
sed -i -e '/@@oci_api_private_key@@/r /cncf/keys/oci_api_key_indented.pem' -e '/@@oci_api_private_key@@/d' /cncf/data/addons/create/*.yaml
rm -f /cncf/keys/oci_api_key_indented.pem
kubectl create -f /cncf/rbac/ || true
kubectl --namespace kube-system create secret generic oci-cloud-controller-manager --from-file=cloud-provider.yaml=/cncf/data/addons/create/oci-ccm-secret.yaml || true
kubectl --namespace kube-system create secret generic oci-flexvolume-driver --from-file=config.yaml=/cncf/data/addons/create/oci-fvd-secret.yaml || true
kubectl --namespace kube-system create secret generic oci-volume-provisioner --from-file=config.yaml=/cncf/data/addons/create/oci-vp-secret.yaml || true
kubectl apply -f /cncf/data/addons/apply
KUBECTL_PATH=$(which kubectl) NUM_NODES=$(expr $TF_VAR_worker_node_count + $TF_VAR_master_node_count) KUBERNETES_PROVIDER=local ${DIR}/validate-cluster/cluster/validate-cluster.sh || true
_retry "Installing Helm" helm init --service-account tiller
sleep 10
_retry "Wait for Helm to Finish Install" kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
# End Oracle
fi # END PROVIDERS - DO NOT REPLACE