Created
July 2, 2020 08:45
-
-
Save sgibson91/e39b3bb294b23cdb89676839fda0476f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get this script's path | |
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" | |
# Read config.json and get BinderHub name | |
configFile="${DIR}/config.json" | |
AKS_RESOURCE_GROUP=$(jq -r '.azure .res_grp_name' "${configFile}") | |
RESOURCE_GROUP_LOCATION=$(jq -r '.azure .location' "${configFile}") | |
BINDERHUB_NAME=$(jq -r '.binderhub .name' "${configFile}") | |
AKS_NAME="${BINDERHUB_NAME}-AKS" | |
CLUSTER_RESOURCE_GROUP="MC_${AKS_RESOURCE_GROUP}_${AKS_NAME}_${RESOURCE_GROUP_LOCATION}" | |
# CLUSTER_RESOURCE_GROUP=MC_binder-prod_turing_westeurope | |
echo "Resource Group: ${CLUSTER_RESOURCE_GROUP}" | |
# az resource list -g "${CLUSTER_RESOURCE_GROUP}" -o table | |
IP_ADDRESS_NAME="$(az resource list -g "${CLUSTER_RESOURCE_GROUP}" --query "[?type == 'Microsoft.Network/publicIPAddresses'].name" -o tsv | grep ^kubernetes-)" | |
echo "IP Address: ${IP_ADDRESS_NAME}" | |
ipAddressAttempts=0 | |
while [ -z "${IP_ADDRESS_NAME}" ]; do | |
((ipAddressAttempts++)) | |
echo "--> IP Address Name pull attempt ${ipAddressAttempts} of 10 failed" | |
if ((ipAddressAttempts > 9)); then | |
echo "--> Failed to pull the IP Address name. You will have to set the A records manually." | |
break | |
fi | |
echo "--> Waiting 30s before trying again" | |
sleep 30 | |
# az resource list -g "${CLUSTER_RESOURCE_GROUP}" -o table | |
IP_ADDRESS_NAME="$(az resource list -g "${CLUSTER_RESOURCE_GROUP}" --query "[?type == 'Microsoft.Network/publicIPAddresses'].name" -o tsv | grep ^kubernetes-)" | |
echo "IP Address: ${IP_ADDRESS_NAME}" | |
done | |
if [ -n "${IP_ADDRESS_NAME}" ]; then | |
IP_ADDRESS_ID="$(az resource show -g "${CLUSTER_RESOURCE_GROUP}" -n "${IP_ADDRESS_NAME}" --resource-type 'Microsoft.Network/publicIPAddresses' --query id -o tsv)" | |
echo "IP Address ID: ${IP_ADDRESS_ID}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment