Skip to content

Commit 76a6f78

Browse files
committed
check and fail on 0 instance vmss
1 parent 89c8ec1 commit 76a6f78

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/AzureBasicLoadBalancerUpgrade.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'AzureBasicLoadBalancerUpgrade'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.5.2'
15+
ModuleVersion = '2.5.3'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -107,7 +107,7 @@
107107
# IconUri = ''
108108

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'Fix Write-Progress error when running in PowerShell 5.1 (bad param)'
110+
ReleaseNotes = 'Check for and fail on VMSSes with no instances.'
111111

112112
# Prerelease string of this module
113113
# Prerelease = 'beta'

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/ValidateScenario/ValidateScenario.psm1

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ function _GetScenarioBackendType {
5454
}
5555
}
5656

57-
5857
If (($backendMemberTypes | Sort-Object | Get-Unique).count -gt 1) {
5958
log -ErrorAction Stop -Message "[Test-SupportedMigrationScenario] Basic Load Balancer backend pools can contain only VMs or VMSSes, contains: '$($backendMemberTypes -join ',')'" -Severity 'Error'
6059
return
@@ -69,7 +68,43 @@ function _GetScenarioBackendType {
6968
}
7069
ElseIf ([string]::IsNullOrEmpty($backendMemberTypes[0])) {
7170
log -Message "[Test-SupportedMigrationScenario] Basic Load Balancer backend pools are empty"
72-
$backendType = 'Empty'
71+
72+
# check that there are no VMSSes associated with the Basic Load Balancer which have no instances
73+
log -Message "[Test-SupportedMigrationScenario] Checking if there are any VMSSes associated with the Basic Load Balancer but which have no instances..."
74+
$graphQuery = @"
75+
resources
76+
| where type =~ 'microsoft.compute/virtualmachinescalesets' and location =~ '$($BasicLoadBalancer.Location)'
77+
| where tostring(properties.virtualMachineProfile.networkProfile.networkInterfaceConfigurations) has '$($BasicLoadBalancer.id)'
78+
| count as vmssCount
79+
"@
80+
81+
log -Severity Verbose -Message "[Test-SupportedMigrationScenario]Graph Query Text: `n$graphQuery"
82+
$waitingForARG = $false
83+
$timeoutStopwatch = [System.Diagnostics.Stopwatch]::StartNew()
84+
do {
85+
If (!$waitingForARG) {
86+
log -Message "[Test-SupportedMigrationScenario] Querying Resource Graph for VMSSes which reference this Load Balancer in their network profiles..."
87+
}
88+
Else {
89+
log -Message "[Test-SupportedMigrationScenario] Waiting 15 seconds before querying ARG again..."
90+
Start-Sleep 15
91+
}
92+
93+
$associatedVMSSCount = Search-AzGraph -Query $graphQuery
94+
95+
$waitingForARG = $true
96+
} while ($associatedVMSSCount.count -eq 0 -and $env:LBMIG_WAIT_FOR_ARG -and $timeoutStopwatch.Elapsed.Minutes -lt 15)
97+
98+
If ($timeoutStopwatch.Elapsed.Minutes -gt 15) {
99+
log -Severity Error -Message "[Test-SupportedMigrationScenario] Resource Graph query timed out before results were returned! The Resource Graph lags behind ARM by several minutes--if the resources to migrate were just created (as in a test), test the query from the log to determine if this was an ingestion lag or synax failure. Once the issue has been corrected, follow the documented migration recovery steps here: https://learn.microsoft.com/azure/load-balancer/upgrade-basic-standard-virtual-machine-scale-sets#what-happens-if-my-upgrade-fails-mid-migration" -terminateOnError
100+
}
101+
102+
If ($associatedVMSSCount.vmssCount -gt 0) {
103+
log -Message "[Test-SupportedMigrationScenario] Basic Load Balancer has a VMSS associated with it which has no instances. This scenario is not currently supported. WORKAROUND: scale your VMSS to at least one instance or remove the VMSS from the LB in the VMSS profile." -Severity 'Error' -terminateOnError
104+
}
105+
Else {
106+
$backendType = 'Empty'
107+
}
73108
}
74109
Else {
75110
log -ErrorAction Stop -Message "[Test-SupportedMigrationScenario] Basic Load Balancer backend pools can contain only VMs or VMSSes, contains: '$($backendMemberTypes -join ',')'" -Severity 'Error'

0 commit comments

Comments
 (0)