2022-06-24 15:34:53 +03:00
|
|
|
#!/bin/bash
|
2024-01-25 14:02:23 +03:00
|
|
|
set -e
|
2022-06-24 15:34:53 +03:00
|
|
|
# shared-cluster.sh is used to provide a repeatable production cluster create script
|
|
|
|
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo -e "usage: ${0} <create|delete>"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2024-01-25 14:02:23 +03:00
|
|
|
check_env_set(){
|
|
|
|
if [[ -z "${!1}" ]]; then
|
|
|
|
echo "$1 is a required ENV but is unset."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:56:37 +03:00
|
|
|
check_env_set SHARED_CLUSTER_LOCATION
|
|
|
|
check_env_set SHARED_CLUSTER_NAME
|
2024-01-25 14:02:23 +03:00
|
|
|
check_env_set SHARED_CLUSTER_RESOURCE_GROUP_NAME
|
|
|
|
check_env_set SHARED_CLUSTER_CLUSTER_RESOURCE_GROUP_NAME
|
|
|
|
|
|
|
|
|
2022-06-24 15:34:53 +03:00
|
|
|
if [ "$#" -ne 1 ]; then
|
|
|
|
usage
|
|
|
|
|
|
|
|
elif [[ $1 == create ]]; then
|
|
|
|
echo "creating resource group and network"
|
2024-01-25 14:02:23 +03:00
|
|
|
az group create \
|
|
|
|
--name $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
|
|
|
--location $SHARED_CLUSTER_LOCATION \
|
|
|
|
--tags persist:true # This tag stops the RG being cleaned up
|
2022-06-24 15:34:53 +03:00
|
|
|
|
|
|
|
az network vnet create \
|
2024-01-25 14:02:23 +03:00
|
|
|
--resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
2022-06-24 15:34:53 +03:00
|
|
|
--name aro-vnet \
|
|
|
|
--address-prefixes 10.0.0.0/22
|
|
|
|
|
|
|
|
az network vnet subnet create \
|
2024-01-25 14:02:23 +03:00
|
|
|
--resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
2022-06-24 15:34:53 +03:00
|
|
|
--vnet-name aro-vnet \
|
|
|
|
--name master-subnet \
|
|
|
|
--address-prefixes 10.0.0.0/23 \
|
|
|
|
--service-endpoints Microsoft.ContainerRegistry
|
|
|
|
|
|
|
|
az network vnet subnet create \
|
2024-01-25 14:02:23 +03:00
|
|
|
--resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
2022-06-24 15:34:53 +03:00
|
|
|
--vnet-name aro-vnet \
|
|
|
|
--name worker-subnet \
|
|
|
|
--address-prefixes 10.0.2.0/23 \
|
|
|
|
--service-endpoints Microsoft.ContainerRegistry
|
|
|
|
|
|
|
|
az network vnet subnet update \
|
|
|
|
--name master-subnet \
|
2024-01-25 14:02:23 +03:00
|
|
|
--resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
2022-06-24 15:34:53 +03:00
|
|
|
--vnet-name aro-vnet \
|
|
|
|
--disable-private-link-service-network-policies true
|
|
|
|
echo "resource group and vnet/subnets created..."
|
|
|
|
|
|
|
|
echo "creating cluster..."
|
|
|
|
az aro create \
|
2024-01-25 14:02:23 +03:00
|
|
|
--resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
|
|
|
--cluster-resource-group $SHARED_CLUSTER_CLUSTER_RESOURCE_GROUP_NAME \
|
2024-02-26 13:56:37 +03:00
|
|
|
--name $SHARED_CLUSTER_NAME \
|
2022-06-24 15:34:53 +03:00
|
|
|
--vnet aro-vnet \
|
|
|
|
--master-subnet master-subnet \
|
|
|
|
--worker-subnet worker-subnet
|
|
|
|
|
2024-05-15 12:08:25 +03:00
|
|
|
CLUSTER_RESOURCE_GROUP_ID=$(az aro show \
|
2024-02-26 13:56:37 +03:00
|
|
|
--name $SHARED_CLUSTER_NAME \
|
2024-01-25 14:02:23 +03:00
|
|
|
--resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME \
|
2024-05-15 12:08:25 +03:00
|
|
|
| jq .clusterProfile.resourceGroupId)
|
2024-01-25 14:02:23 +03:00
|
|
|
|
2024-02-26 13:56:37 +03:00
|
|
|
echo "Adding tag to cluster..."
|
2024-01-25 14:02:23 +03:00
|
|
|
# This tag stops the RG being cleaned up
|
|
|
|
az tag create \
|
2024-02-26 13:56:37 +03:00
|
|
|
--resource-id $CLUSTER_RESOURCE_GROUP_ID \
|
2024-01-25 14:02:23 +03:00
|
|
|
--tags persist=true
|
|
|
|
|
2022-06-24 15:34:53 +03:00
|
|
|
elif [[ $1 == "delete" ]]; then
|
2024-01-25 14:02:23 +03:00
|
|
|
echo "Deleting cluster..."
|
2024-02-26 13:56:37 +03:00
|
|
|
az aro delete --name $SHARED_CLUSTER_NAME -g $SHARED_CLUSTER_RESOURCE_GROUP_NAME --yes
|
|
|
|
echo "Deleting Vnet..."
|
2024-01-25 14:02:23 +03:00
|
|
|
az network vnet delete --name aro-vnet -g $SHARED_CLUSTER_RESOURCE_GROUP_NAME
|
2024-02-26 13:56:37 +03:00
|
|
|
echo "Deleting group..."
|
2024-01-25 14:02:23 +03:00
|
|
|
az group delete --resource-group $SHARED_CLUSTER_RESOURCE_GROUP_NAME --yes
|
2022-06-24 15:34:53 +03:00
|
|
|
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|