|
1 | 1 | #!/usr/bin/env bash |
2 | | -set -e |
| 2 | +set -euo pipefail |
3 | 3 | trap 'echo "[ERROR] Failed during Resource group or AKS cluster creation." >&2' ERR |
4 | | - |
5 | 4 | SUBSCRIPTION_ID=$1 |
6 | 5 | LOCATION=$2 |
7 | 6 | RG=$3 |
8 | 7 | VM_SKU_DEFAULT=$4 |
9 | 8 | VM_SKU_HIGHNIC=$5 |
10 | 9 |
|
11 | | -echo "Subscription id: $SUBSCRIPTION_ID" |
12 | | -echo "Resource group: $RG" |
13 | | -echo "Location: $LOCATION" |
14 | | -echo "VM SKU (default): $VM_SKU_DEFAULT" |
15 | | -echo "VM SKU (high-NIC): $VM_SKU_HIGHNIC" |
16 | | -az account set --subscription "$SUBSCRIPTION_ID" |
17 | | - |
18 | | -# Enable parallel cluster creation |
19 | | -create_cluster() { |
20 | | - local CLUSTER=$1 |
21 | | - echo "==> Creating AKS cluster: $CLUSTER" |
22 | | - |
23 | | - az aks create -g "$RG" -n "$CLUSTER" -l "$LOCATION" \ |
24 | | - --network-plugin azure --node-count 1 \ |
25 | | - --node-vm-size "$VM_SKU_DEFAULT" \ |
26 | | - --enable-managed-identity --generate-ssh-keys \ |
27 | | - --load-balancer-sku standard --yes --only-show-errors |
28 | | - |
29 | | - echo "==> Adding high-NIC nodepool to $CLUSTER" |
30 | | - az aks nodepool add -g "$RG" -n highnic \ |
31 | | - --cluster-name "$CLUSTER" --node-count 2 \ |
32 | | - --node-vm-size "$VM_SKU_HIGHNIC" --mode User --only-show-errors |
33 | | - |
34 | | - echo "Finished AKS cluster: $CLUSTER" |
| 10 | +CLUSTER_COUNT=2 |
| 11 | +CLUSTER_PREFIX="aks" |
| 12 | +DEFAULT_NODE_COUNT=1 |
| 13 | +COMMON_TAGS="fastpathenabled=true RGOwner=LongRunningTestPipelines stampcreatorserviceinfo=true" |
| 14 | + |
| 15 | +wait_for_provisioning() { # Helper for safe retry/wait for provisioning states (basic) |
| 16 | + local rg="$1" clusterName="$2" |
| 17 | + echo "Waiting for AKS '$clusterName' in RG '$rg' to reach Succeeded/Failed (polling)..." |
| 18 | + while :; do |
| 19 | + state=$(az aks show --resource-group "$rg" --name "$clusterName" --query provisioningState -o tsv 2>/dev/null || true) |
| 20 | + if [ -z "$state" ]; then |
| 21 | + sleep 3 |
| 22 | + continue |
| 23 | + fi |
| 24 | + case "$state" in |
| 25 | + Succeeded|Succeeded*) echo "Provisioning state: $state"; break ;; |
| 26 | + Failed|Canceled|Rejected) echo "Provisioning finished with state: $state"; break ;; |
| 27 | + *) printf "."; sleep 6 ;; |
| 28 | + esac |
| 29 | + done |
35 | 30 | } |
36 | 31 |
|
37 | | -# Run both clusters in parallel |
38 | | -create_cluster "aks-cluster-a" & |
39 | | -pid_a=$! |
40 | | - |
41 | | -create_cluster "aks-cluster-b" & |
42 | | -pid_b=$! |
43 | | - |
44 | | -# Wait for both to finish |
45 | | -wait $pid_a $pid_b |
46 | 32 |
|
47 | | -echo "AKS clusters created successfully!" |
| 33 | +for i in $(seq 1 "$CLUSTER_COUNT"); do |
| 34 | + echo "==============================" |
| 35 | + echo " Working on cluster set #$i" |
| 36 | + echo "==============================" |
| 37 | + |
| 38 | + CLUSTER_NAME="${CLUSTER_PREFIX}-${i}" |
| 39 | + echo "Creating AKS cluster '$CLUSTER_NAME' in RG '$RG'" |
| 40 | + |
| 41 | + make -C ./hack/aks azcfg AZCLI=az REGION=$LOCATION |
| 42 | + |
| 43 | + make -C ./hack/aks swiftv2-podsubnet-cluster-up \ |
| 44 | + AZCLI=az REGION=$LOCATION \ |
| 45 | + SUB=$SUBSCRIPTION_ID \ |
| 46 | + GROUP=$RG \ |
| 47 | + CLUSTER=$CLUSTER_NAME \ |
| 48 | + NODE_COUNT=$DEFAULT_NODE_COUNT \ |
| 49 | + VM_SIZE=$VM_SKU_DEFAULT \ |
| 50 | + |
| 51 | + echo " - waiting for AKS provisioning state..." |
| 52 | + wait_for_provisioning "$RG" "$CLUSTER_NAME" |
| 53 | + |
| 54 | + echo "Adding multi-tenant nodepool ' to '$CLUSTER_NAME'" |
| 55 | + make -C ./hack/aks linux-swiftv2-nodepool-up \ |
| 56 | + AZCLI=az REGION=$LOCATION \ |
| 57 | + GROUP=$RG \ |
| 58 | + VM_SIZE=$VM_SKU_HIGHNIC \ |
| 59 | + CLUSTER=$CLUSTER_NAME \ |
| 60 | + SUB=$SUBSCRIPTION_ID \ |
| 61 | + |
| 62 | +done |
| 63 | +echo "All done. Created $CLUSTER_COUNT cluster set(s)." |
0 commit comments