Skip to content

Commit

Permalink
refactor AZ script and helper func for proper AZ selection
Browse files Browse the repository at this point in the history
... to account for regions with varied number of AZs and the eventuality
that AZ names could be something other than 1,2,3
  • Loading branch information
jfchevrette committed Feb 10, 2025
1 parent 9ebbd9e commit 66f57ba
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 121 deletions.
21 changes: 8 additions & 13 deletions dev-infrastructure/modules/aks-cluster-base.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ param dnsServiceIP string = '10.130.0.10'
// Passed Params and Overrides
param location string

@description('List of Availability Zones to use for the AKS cluster')
param locationAvailabilityZones array
var locationHasAvailabilityZones = length(locationAvailabilityZones) > 0

@description('Set to true to prevent resources from being pruned after 48 hours')
param persist bool = false

Expand Down Expand Up @@ -58,13 +62,6 @@ var istioIngressGatewayIPAddressIPTagsArray = [
}
]

@description('List of Availability Zones for zone-redundant resources')
param zoneRedundancyZones array = [
'1'
'2'
'3'
]

@maxLength(24)
param aksKeyVaultName string

Expand Down Expand Up @@ -255,7 +252,7 @@ module istioIngressGatewayIPAddress '../modules/network/publicipaddress.bicep' =
name: istioIngressGatewayIPAddressName
ipTags: istioIngressGatewayIPAddressIPTagsArray
location: location
zones: zoneRedundancyZones
zones: locationHasAvailabilityZones ? locationAvailabilityZones : null
// Role Assignment needed for the public IP address to be used on the Load Balancer
roleAssignmentProperties: {
principalId: aksClusterUserDefinedManagedIdentity.properties.principalId
Expand All @@ -272,7 +269,7 @@ module aksClusterOutboundIPAddress '../modules/network/publicipaddress.bicep' =
name: aksClusterOutboundIPAddressName
ipTags: aksClusterOutboundIPAddressIPTagsArray
location: location
zones: zoneRedundancyZones
zones: locationHasAvailabilityZones ? locationAvailabilityZones : null
// Role Assignment needed for the public IP address to be used on the Load Balancer
roleAssignmentProperties: {
principalId: aksClusterUserDefinedManagedIdentity.properties.principalId
Expand Down Expand Up @@ -338,7 +335,7 @@ resource aksCluster 'Microsoft.ContainerService/managedClusters@2024-04-02-previ
vnetSubnetID: aksNodeSubnet.id
podSubnetID: aksPodSubnet.id
maxPods: 100
availabilityZones: zoneRedundancyZones
availabilityZones: locationHasAvailabilityZones ? locationAvailabilityZones : null
securityProfile: {
enableSecureBoot: false
enableVTPM: false
Expand Down Expand Up @@ -492,9 +489,7 @@ resource userAgentPools 'Microsoft.ContainerService/managedClusters/agentPools@2
vnetSubnetID: aksNodeSubnet.id
podSubnetID: aksPodSubnet.id
maxPods: 225
availabilityZones: [
'${(i + 1)}'
]
availabilityZones: locationHasAvailabilityZones ? [locationAvailabilityZones[i]] : null
securityProfile: {
enableSecureBoot: false
enableVTPM: false
Expand Down
18 changes: 9 additions & 9 deletions dev-infrastructure/scripts/list-az-regions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ az rest \
--method get \
--uri "/subscriptions/$(az account show --query id --output tsv)/locations?api-version=2024-11-01" \
| jq -r '
# First, print items with availabilityZoneMappings set
"Regions with Availability Zones:",
(.value[] | select(.availabilityZoneMappings) | .name),
"",
# Then, print items without availabilityZoneMappings
"Regions without Availability Zones:",
(.value[] | select(.availabilityZoneMappings | not) | .name)
'

reduce .value[] as $item ({}; .[$item.name] = {
availabilityZones: (
if $item.availabilityZoneMappings then
$item.availabilityZoneMappings | map(.logicalZone)
else
[]
end
)
}) | to_entries | sort_by(.key) | from_entries'
Loading

0 comments on commit 66f57ba

Please sign in to comment.