Skip to content

Commit 89f150c

Browse files
authored
BYO K8s (#158)
* PYO K8s * Enhanced Destroy * Update main-setup.sh
1 parent ccdac65 commit 89f150c

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

grabdish/utils/main-destroy.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ set -e
1414
sed -i.bak '/grabdish/d' ~/.bashrc
1515

1616

17+
# No destroy necessary for Live Labs
18+
if test "$(state_get RUN_TYPE)" == "3"; then
19+
echo "No teardown required for Live Labs"
20+
exit
21+
fi
22+
23+
1724
# Run the os-destroy.sh in the background
1825
if ps -ef | grep "$GRABDISH_HOME/utils/os-destroy.sh" | grep -v grep; then
1926
echo "$GRABDISH_HOME/utils/os-destroy.sh is already running"
@@ -51,4 +58,11 @@ export TF_VAR_ociRegionIdentifier="$(state_get REGION)"
5158
export TF_VAR_runName="$(state_get RUN_NAME)"
5259
export TF_VAR_orderDbName="$(state_get ORDER_DB_NAME)"
5360
export TF_VAR_inventoryDbName="$(state_get INVENTORY_DB_NAME)"
61+
terraform init
5462
terraform destroy -auto-approve
63+
64+
65+
# If BYO K8s then delete the msdataworkshop namespace in k8s
66+
if state_done BYO_K8S; then
67+
kubectl delete ns msdataworkshop
68+
fi

grabdish/utils/main-setup.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@ while ! state_done RUN_TYPE; do
2828
state_set USER_OCID 'NA'
2929
state_set USER_NAME "LL$(state_get RESERVATION_ID)-USER"
3030
state_set_done PROVISIONING
31+
state_set_done K8S_PROVISIONING
3132
state_set RUN_NAME "grabdish$(state_get RESERVATION_ID)"
3233
state_set ORDER_DB_NAME "ORDER$(state_get RESERVATION_ID)"
3334
state_set INVENTORY_DB_NAME "INVENTORY$(state_get RESERVATION_ID)"
3435
state_set_done OKE_LIMIT_CHECK
3536
state_set_done ATP_LIMIT_CHECK
3637
else
3738
state_set RUN_TYPE "1"
39+
# BYO K8s
40+
if test ${BYO_K8S:-UNSET} != 'UNSET'; then
41+
state_set_done BYO_K8S
42+
state_set_done K8S_PROVISIONING
43+
state_set OKE_OCID 'NA'
44+
state_set_done KUBECTL
45+
state_set_done OKE_LIMIT_CHECK
46+
fi
3847
fi
3948
done
4049

@@ -111,7 +120,7 @@ while ! state_done COMPARTMENT_OCID; do
111120
COMPARTMENT_OCID=`oci iam compartment create --compartment-id "$(state_get TENANCY_OCID)" --name "$(state_get RUN_NAME)" --description "GrabDish Workshop" --query 'data.id' --raw-output`
112121
export OCI_CLI_PROFILE=$(state_get REGION)
113122
else
114-
read -p "Please enter your OCI compartments's OCID: " COMPARTMENT_OCID
123+
read -p "Please enter your OCI compartment's OCID: " COMPARTMENT_OCID
115124
fi
116125
while ! test `oci iam compartment get --compartment-id "$COMPARTMENT_OCID" --query 'data."lifecycle-state"' --raw-output 2>/dev/null`"" == 'ACTIVE'; do
117126
echo "Waiting for the compartment to become ACTIVE"
@@ -411,14 +420,7 @@ while ! state_done INVENTORY_DB_PASSWORD_SET; do
411420
done
412421

413422

414-
# Wait for OKE Setup
415-
while ! state_done OKE_SETUP; do
416-
# echo "`date`: Waiting for OKE_SETUP"
417-
sleep 2
418-
done
419-
420-
421-
# Collect UI password and create secret
423+
# Create UI password secret
422424
while ! state_done UI_PASSWORD; do
423425
while true; do
424426
if kubectl create -n msdataworkshop -f -; then

grabdish/utils/oke-setup.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ done
1515

1616

1717
# Wait for provisioning
18-
while ! state_done PROVISIONING; do
19-
echo "`date`: Waiting for terraform provisioning"
18+
while ! state_done K8S_PROVISIONING; do
19+
echo "`date`: Waiting for k8s provisioning"
2020
sleep 10
2121
done
2222

@@ -48,7 +48,7 @@ done
4848

4949

5050
# Wait for OKE nodes to become redy
51-
while true; do
51+
while ! state_done BYO_K8S; do
5252
READY_NODES=`kubectl get nodes | grep Ready | wc -l` || echo 'Ignoring any Error'
5353
if test "$READY_NODES" -ge 3; then
5454
echo "3 OKE nodes are ready"
@@ -70,13 +70,6 @@ while ! state_done OKE_NAMESPACE; do
7070
done
7171

7272

73-
# Wait for Order User (avoid concurrent kubectl)
74-
while ! state_done ORDER_USER; do
75-
echo "`date`: Waiting for ORDER_USER"
76-
sleep 2
77-
done
78-
79-
8073
# Create SSL Secret
8174
while ! state_done SSL_SECRET; do
8275
if kubectl create secret tls ssl-certificate-secret --key $GRABDISH_HOME/tls/tls.key --cert $GRABDISH_HOME/tls/tls.crt -n msdataworkshop; then

grabdish/utils/terraform.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ if ! state_done PROVISIONING; then
1616
export TF_VAR_runName="$(state_get RUN_NAME)"
1717
export TF_VAR_orderDbName="$(state_get ORDER_DB_NAME)"
1818
export TF_VAR_inventoryDbName="$(state_get INVENTORY_DB_NAME)"
19-
if ! terraform init; then
19+
20+
if state_done K8S_PROVISIONING; then
21+
rm -f containerengine.tf core.tf
22+
fi
23+
24+
if ! terraform init; then
2025
echo 'ERROR: terraform init failed!'
2126
exit
2227
fi
28+
2329
if ! terraform apply -auto-approve; then
2430
echo 'ERROR: terraform apply failed!'
2531
exit
2632
fi
33+
2734
cd $GRABDISH_HOME
35+
state_set_done K8S_PROVISIONING
2836
state_set_done PROVISIONING
2937
fi
3038

0 commit comments

Comments
 (0)