@@ -23,9 +23,9 @@ az account set --subscription "$SUB_ID"
2323# Verification functions
2424# -------------------------------
2525verify_vnet () {
26- local rg= " $1 " ; local vnet=" $2 "
26+ local vnet=" $1 "
2727 echo " ==> Verifying VNet: $vnet "
28- if az network vnet show -g " $rg " -n " $vnet " & > /dev/null; then
28+ if az network vnet show -g " $RG " -n " $vnet " & > /dev/null; then
2929 echo " [OK] Verified VNet $vnet exists."
3030 else
3131 echo " [ERROR] VNet $vnet not found!" >&2
@@ -34,16 +34,77 @@ verify_vnet() {
3434}
3535
3636verify_subnet () {
37- local rg =" $1 " ; local vnet= " $2 " ; local subnet=" $3 "
37+ local vnet =" $1 " ; local subnet=" $2 "
3838 echo " ==> Verifying subnet: $subnet in $vnet "
39- if az network vnet subnet show -g " $rg " --vnet-name " $vnet " -n " $subnet " & > /dev/null; then
39+ if az network vnet subnet show -g " $RG " --vnet-name " $vnet " -n " $subnet " & > /dev/null; then
4040 echo " [OK] Verified subnet $subnet exists in $vnet ."
4141 else
4242 echo " [ERROR] Subnet $subnet not found in $vnet !" >&2
4343 exit 1
4444 fi
4545}
4646
47+ # -------------------------------
48+ create_vnet_subets () {
49+ local vnet=" $2 " ;
50+ local vnet_cidr=" $3 "
51+ local node_subnet_cidr=" $4 " ;
52+ local extra_subnets=" $5 " ;
53+ local extra_cidrs=" $6 "
54+
55+ echo " ==> Creating VNet: $vnet with CIDR: $vnet_cidr "
56+ az network vnet create -g " $RG " -l " $LOCATION " --name " $vnet " --address-prefixes " $vnet_cidr " -o none
57+
58+ IFS=' ' read -r -a extra_subnet_array <<< " $extra_subnets"
59+ IFS=' ,' read -r -a extra_cidr_array <<< " $extra_cidrs"
60+
61+ for i in " ${! extra_subnet_array[@]} " ; do
62+ subnet_name=" ${extra_subnet_array[$i]} "
63+ subnet_cidr=" ${extra_cidr_array[$i]} "
64+ echo " ==> Creating extra subnet: $subnet_name with CIDR: $subnet_cidr "
65+ az network vnet subnet create -g " $RG " \
66+ --vnet-name " $vnet " --name " $subnet_name " \
67+ --delegations Microsoft.SubnetDelegator/msfttestclients \
68+ --address-prefixes " $subnet_cidr " -o none
69+ done
70+ }
71+
72+ delegate_subnet () {
73+ local vnet=" $1 "
74+ local subnet=" $2 "
75+ local max_attempts=3
76+ local attempt=1
77+
78+ echo " ==> Delegating subnet: $subnet in VNet: $vnet to Subnet Delegator"
79+ subnet_id=$( az network vnet subnet show -g " $RG " --vnet-name " $vnet " -n " $subnet " --query id -o tsv)
80+ modified_custsubnet=" ${subnet_id// \/ /% 2F} "
81+ cmd_subnetdelegator_curl=" 'curl -X PUT \" http://localhost:8080/DelegatedSubnet/$modified_custsubnet \" '"
82+ cmd_subnetdelegator_az=" az containerapp exec -n subnetdelegator-westus-u3h4j -g subnetdelegator-westus --subscription 9b8218f9-902a-4d20-a65c-e98acec5362f --command $cmd_subnetdelegator_curl "
83+
84+ while [ $attempt -le $max_attempts ]; do
85+ echo " Attempt $attempt of $max_attempts ..."
86+ response=$( eval " $cmd_subnetdelegator_az " )
87+
88+ if [[ $response == * " success" * ]]; then
89+ echo " Subnet Delegator successfully registered the subnet"
90+ return 0
91+ else
92+ echo " Subnet Delegator failed to register the subnet (attempt $attempt )"
93+ echo " Response: $response "
94+
95+ if [ $attempt -lt $max_attempts ]; then
96+ echo " Retrying in 5 seconds..."
97+ sleep 5
98+ fi
99+ fi
100+
101+ (( attempt++ ))
102+ done
103+
104+ echo " [ERROR] Failed to delegate subnet after $max_attempts attempts"
105+ exit 1
106+ }
107+
47108# --- Loop over VNets ---
48109for i in " ${! VNAMES[@]} " ; do
49110 VNET=${VNAMES[$i]}
@@ -53,26 +114,14 @@ for i in "${!VNAMES[@]}"; do
53114 EXTRA_SUBNET_CIDRS=${EXTRA_CIDRS_LIST[$i]}
54115
55116 # Create VNet + subnets
56- make -C ./hack/aks swift-delegated-subnet-up \
57- AZCLI=az REGION=$LOCATION GROUP=$RG VNET=$VNET \
58- VNET_CIDR=$VNET_CIDR NODE_SUBNET_CIDR=$NODE_SUBNET_CIDR \
59- EXTRA_SUBNETS=" $EXTRA_SUBNETS " EXTRA_SUBNET_CIDRS=" $EXTRA_SUBNET_CIDRS " \
60- && echo " Created $VNET with subnets $EXTRA_SUBNETS "
61-
62- verify_vnet " $RG " " $VNET " # Verify VNet
63-
64- # Loop over extra subnets to verify and create dummy clusters to delegate the pod subnets.
117+ create_vnet_subets " $VNET " " $VNET_CIDR " " $NODE_SUBNET_CIDR " " $EXTRA_SUBNETS " " $EXTRA_SUBNET_CIDRS "
118+ verify_vnet " $VNET "
119+ # Loop over extra subnets to verify and delegate the pod subnets.
65120 for PODSUBNET in $EXTRA_SUBNETS ; do
66- verify_subnet " $RG " " $VNET " " $PODSUBNET "
67- if [[ " $PODSUBNET " == " pe" ]]; then
68- # Skip creating dummy cluster for private endpoint subnet.
69- continue
121+ verify_subnet " $VNET " " $PODSUBNET "
122+ if [[ " $PODSUBNET " != " pe" ]]; then
123+ delegate_subnet " $VNET " " $PODSUBNET "
70124 fi
71- cluster_name=" ${BUILD_ID} -${VNET} -${PODSUBNET} "
72- make -C ./hack/aks swiftv2-dummy-cluster-subnet-delegator-up \
73- AZCLI=az CLUSTER=$cluster_name GROUP=$RG REGION=$LOCATION \
74- SUB=$SUB_ID VNET=$VNET POD_SUBNET=$PODSUBNET \
75- && echo " Created dummy cluster for $VNET subnet $PODSUBNET "
76125 done
77126done
78127
0 commit comments