Skip to content

Commit

Permalink
Address some PR comments; fix some linting issues; improve dynamic-ness
Browse files Browse the repository at this point in the history
  • Loading branch information
jramsdale committed Aug 22, 2018
1 parent a312c54 commit c8e67b9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 38 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
account.json
__pycache__/
terraform.tfvars
.terraform/
terraform/terraform.tfstate
terraform/terraform.tfstate.backup
terraform.tfvars
.terraform.tfstate*
terraform.tfstate*
28 changes: 0 additions & 28 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,13 @@
# "- -"
# "---------------------------------------------------------"

APP_NAME="tracing-demo"
CLUSTER_NAME="tracing-demo-space"
GKE_VERSION=$(gcloud container get-server-config \
--format="value(validMasterVersions[0])")

# gcloud and kubectl are required for this POC
command -v gcloud >/dev/null 2>&1 || { \
echo >&2 "I require gcloud but it's not installed. Aborting."; exit 1; }

command -v kubectl >/dev/null 2>&1 || { \
echo >&2 "I require kubectl but it's not installed. Aborting."; exit 1; }

usage() { echo "Usage: $0 [-c <cluster name>]" 1>&2; exit 1; }

# parse -c flag for the CLUSTER_NAME using getopts
while getopts ":c:" opt; do
case ${opt} in
c)
CLUSTER_NAME=$OPTARG
;;
\?)
echo "Invalid flag on command line: $OPTARG" 1>&2
;;
*)
usage
;;
esac
done
shift $((OPTIND -1))

# If user did not pass in -c flag then fail
if [ -z "${CLUSTER_NAME}" ]; then
usage
fi

# Get the default zone and use it or die
ZONE=$(gcloud config get-value compute/zone)
if [ -z "${ZONE}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "$ROOT"/scripts/common.sh

# Tear down Terraform-managed resources and remove generated tfvars
(cd "$ROOT"/terraform; terraform destroy -input=false -auto-approve)
cd "$ROOT"/terraform || exit; terraform destroy -input=false -auto-approve
rm -f "$ROOT"/terraform/terraform.tfvars
17 changes: 11 additions & 6 deletions scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ ROOT=$(dirname "${BASH_SOURCE[0]}")/..
# shellcheck disable=SC1090
source "$ROOT"/scripts/common.sh

APP_NAME=$(kubectl get deployments \
-ojsonpath='{.items[0].metadata.labels.app}')
APP_MESSAGE="deployment \"$APP_NAME\" successfully rolled out"

cd "$ROOT"/terraform || exit; CLUSTER_NAME=$(terraform output cluster_name) \
ZONE=$(terraform output primary_zone)

# Get credentials for the k8s cluster
gcloud container clusters get-credentials "$CLUSTER_NAME" --zone "$ZONE"
gcloud container clusters get-credentials "$CLUSTER_NAME" --zone="$ZONE"

# Wait for the rollout of demo app to finish
while true
do
ROLLOUT=$(kubectl rollout status --namespace default --watch=false deployment/"$APP_NAME") \
&> /dev/null
ROLLOUT=$(kubectl rollout status --namespace default \
--watch=false deployment/"$APP_NAME") &> /dev/null
if [[ $ROLLOUT = *"$APP_MESSAGE"* ]]; then
break
fi
sleep 2
done
echo "step 1 of the validation passed."
echo "Step 1 of the validation passed. App is deployed."

# Grab the external IP and port of the service to confirm that demo app
# deployed correctly.
Expand All @@ -60,7 +65,7 @@ do

if [[ $EXT_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
break
elif [[ $EXT_PORT =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
elif [[ $EXT_PORT =~ ^0*(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$ ]]; then
break
else
continue
Expand All @@ -70,4 +75,4 @@ done
echo "App is available at: http://$EXT_IP:$EXT_PORT"
[ "$(curl -s -o /dev/null -w '%{http_code}' "$EXT_IP:$EXT_PORT"/)" \
-eq 200 ] || exit 1
echo "step 2 of the validation passed."
echo "Step 2 of the validation passed. App handles requests."
8 changes: 8 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ resource "google_pubsub_subscription" "tracing-demo-subscription" {
name = "tracing-demo-cli"
topic = "${google_pubsub_topic.tracing-demo-topic.name}"
}

output "cluster_name" {
value = "${google_container_cluster.primary.name}"
}

output "primary_zone" {
value = "${google_container_cluster.primary.zone}"
}

0 comments on commit c8e67b9

Please sign in to comment.