Skip to content

Commit a88c0c5

Browse files
authored
Merge pull request #4 from tjengland/hosted-zone-sanity-check
Add hosted zone sanity check in init script
2 parents 9305c5d + 3490858 commit a88c0c5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ FROM kubefirst/kubefirst-builder:0.1-ubuntu
33
ADD scripts/nebulous /scripts/nebulous
44
ADD terraform /terraform
55

6+
RUN apt-get update
7+
RUN apt-get install dnsutils -y
8+
69
CMD [ "/bin/bash" ]

scripts/nebulous/init.sh

+28
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@ export TF_VAR_email_domain=$EMAIL_DOMAIN
9292
export TF_VAR_region=$AWS_DEFAULT_REGION
9393
export TF_VAR_iam_user_arn=$IAM_USER_ARN
9494

95+
HZ_LIVENESS_FAIL_COUNT=0
96+
HZ_IS_LIVE=0
97+
HZ_LIVENESS_URL=livenesstest.$HOSTED_ZONE_NAME
98+
HZ_LIVENESS_JSON="{\"Comment\":\"CREATE sanity check record \",\"Changes\":[{\"Action\":\"CREATE\",\"ResourceRecordSet\":{\"Name\":\"$HZ_LIVENESS_URL\",\"Type\":\"A\",\"TTL\":300,\"ResourceRecords\":[{\"Value\":\"4.4.4.4\"}]}}]}"
99+
echo "Creating $HZ_LIVENESS_URL record for sanity check"
100+
HZ_RECORD_STATUS=$(aws route53 change-resource-record-sets --hosted-zone-id $AWS_HOSTED_ZONE_ID --change-batch "$HZ_LIVENESS_JSON" | jq -r .ChangeInfo.Status)
101+
102+
while [[ $HZ_RECORD_STATUS == 'PENDING' && $HZ_LIVENESS_FAIL_COUNT -lt 8 && $HZ_IS_LIVE -eq 0 ]];
103+
do
104+
HZ_LOOKUP_RESULT=$(nslookup "$HZ_LIVENESS_URL" 8.8.8.8 | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
105+
if [[ "$HZ_LOOKUP_RESULT" ]]; then
106+
HZ_IS_LIVE=1
107+
echo "Sanity check passed"
108+
else
109+
HZ_LIVENESS_FAIL_COUNT=$((HZ_LIVENESS_FAIL_COUNT+1))
110+
echo "Sanity check url, $HZ_LIVENESS_URL, is not ready yet. Sleeping for 30 seconds"
111+
sleep 30
112+
fi
113+
done
114+
115+
echo "Deleting $HZ_LIVENESS_URL record"
116+
aws route53 change-resource-record-sets --hosted-zone-id $AWS_HOSTED_ZONE_ID --change-batch "$( echo "${HZ_LIVENESS_JSON//CREATE/DELETE}" )" > /dev/null
117+
118+
if [[ $HZ_IS_LIVE -eq 0 ]]; then
119+
echo "Error creating an A record in the provided hosted zone! we can't go on, check your zone, credentials, region, etc and try again"
120+
exit 1
121+
fi
122+
95123
if [[ "$AWS_DEFAULT_REGION" == "us-east-1" ]]; then
96124
S3_BUCKET_NAME=$(aws s3api create-bucket --bucket $BUCKET_NAME --region $AWS_DEFAULT_REGION | jq -r .Location | cut -d/ -f2 )
97125
else

0 commit comments

Comments
 (0)