Skip to content

Commit

Permalink
Fix move vmss backup to prep (#105)
Browse files Browse the repository at this point in the history
* added migration graph query

* Fix skipMigrateNATPoolsToNATRules parameter not found in VMSS upgrades

* fix blank std lb name verification

* move VMSS backup to prep stage
  • Loading branch information
mbrat2005 authored Jan 18, 2024
1 parent 0f39987 commit 90551e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'AzureBasicLoadBalancerUpgrade'

# Version number of this module.
ModuleVersion = '2.4.2'
ModuleVersion = '2.4.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -107,7 +107,7 @@
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'Fix skipMigrateNATPoolsToNATRules parameter not found in VMSS upgrades'
ReleaseNotes = 'Fix missed VMSS backups in -multiLBConfig mode'

# Prerelease string of this module
# Prerelease = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ function PublicLBMigrationVmss {
Write-Progress -Status "Public Load Balancer with VMSS backend detected. Initiating Public Load Balancer Migration" -PercentComplete 0 @progressParams
log -Message "[PublicLBMigration] Public Load Balancer with VMSS backend found. Initiating Public Load Balancer Migration"

# Creating a vmss object before it gets changed as a reference for the backend pool migration
Write-Progress -Status "Backing up VMSS" -ParentId 4 @progressParams

# Backup VMSS Configurations
BackupVmss -BasicLoadBalancer $BasicLoadBalancer -RecoveryBackupPath $RecoveryBackupPath

# Remove Public IP Configurations from VMSS
Write-Progress -Status "Removing Public IP Configurations from VMSS" -PercentComplete ((1 / 14) * 100) @progressParams
RemoveVmssPublicIPConfig -BasicLoadBalancer $BasicLoadBalancer
Expand Down Expand Up @@ -201,13 +195,6 @@ function InternalLBMigrationVmss {

log -Message "[InternalLBMigration] Internal Load Balancer with VMSS backend detected. Initiating Internal Load Balancer Migration"

# Creating a vmss object before it gets changed as a reference for the backend pool migration
Write-Progress -Status "Backing up VMSS" -PercentComplete ((1/14) * 100) @progressParams

# Backup VMSS Configurations
Write-Progress -Status "Backing up VMSS Configurations" -PercentComplete ((2/14) * 100) @progressParams
BackupVmss -BasicLoadBalancer $BasicLoadBalancer -RecoveryBackupPath $RecoveryBackupPath

# Remove Public IP Configurations from VMSS
Write-Progress -Status "Removing Public IP Configurations from VMSS" -PercentComplete ((3/14) * 100) @progressParams
RemoveVmssPublicIPConfig -BasicLoadBalancer $BasicLoadBalancer
Expand Down Expand Up @@ -961,11 +948,29 @@ function LBMigrationPrep {
Activity = "Preparing load balancer '$($migrationConfig.BasicLoadBalancer.Name)' for migration"
Parent = 3
}
Write-Progress -Status "Preparing load balancer '$($migrationConfig.BasicLoadBalancer.Name)' for migration" -PercentComplete ((1/4) * 100) @progressParams
Write-Progress -Status "Preparing load balancer '$($migrationConfig.BasicLoadBalancer.Name)' for migration" -PercentComplete ((1/5) * 100) @progressParams

try {
$errorActionPreference = 'Stop'

# Backup Basic Load Balancer Configurations
Write-Progress -Status "Backing up Basic Load Balancer Configurations" -PercentComplete ((2/4) * 100) @progressParams
BackupBasicLoadBalancer -BasicLoadBalancer $migrationConfig.BasicLoadBalancer -RecoveryBackupPath $RecoveryBackupPath
# Backup Basic Load Balancer Configurations
Write-Progress -Status "Backing up Basic Load Balancer Configurations" -PercentComplete ((2/5) * 100) @progressParams
BackupBasicLoadBalancer -BasicLoadBalancer $migrationConfig.BasicLoadBalancer -RecoveryBackupPath $RecoveryBackupPath

# Backup VMSS Configurations
# TO-DO will create a VMSS backup for each LB of the same VMSS but since -multiLBConfig is not restricted to shared backends, there may be different VMSSes anyway
if ($migrationConfig.scenario.backendType -eq 'VMSS') {
Write-Progress -Status "Backing up VMSS Configurations" -PercentComplete ((3/5) * 100) @progressParams
BackupVmss -BasicLoadBalancer $migrationConfig.BasicLoadBalancer -RecoveryBackupPath $RecoveryBackupPath
}
}
catch {
log -message "[LBMigrationPrep] Failed backup preparation step for '$($migrationConfig.BasicLoadBalancer.Name)'"
throw $_
}
}

ForEach ($migrationConfig in $migrationConfigs) {

# get a reference copy of the vmss prior to modifying it
If ($migrationConfig.scenario.backendType -eq 'VMSS') {
Expand All @@ -974,12 +979,12 @@ function LBMigrationPrep {

If ($migrationConfig.scenario.ExternalOrInternal -eq 'External') {
# Migrate public IP addresses on Basic LB to static (if dynamic)
Write-Progress -Status "Migrating public IP addresses on Basic LB to static (if dynamic)" -PercentComplete ((3/4) * 100) @progressParams
Write-Progress -Status "Migrating public IP addresses on Basic LB to static (if dynamic)" -PercentComplete ((4/5) * 100) @progressParams
PublicIPToStatic -BasicLoadBalancer $migrationConfig.BasicLoadBalancer
}

# Deletion of Basic Load Balancer and Delete Basic Load Balancer
Write-Progress -Status "Deletion of Basic Load Balancer and Delete Basic Load Balancer" -PercentComplete ((4/4) * 100) -Completed @progressParams
Write-Progress -Status "Deletion of Basic Load Balancer and Delete Basic Load Balancer" -PercentComplete ((5/5) * 100) -Completed @progressParams
RemoveBasicLoadBalancer -BasicLoadBalancer $migrationConfig.BasicLoadBalancer -BackendType $migrationConfig.scenario.backendType

log -message "[LBMigrationPrep] Completed preparing load balancer '$($migrationConfig.BasicLoadBalancer.Name)' for migration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ function Start-AzBasicLoadBalancerUpgrade {
$StdLoadBalancerName = $LBConfig.standardLoadBalancerName
}
else {
$LBConfig.standardLoadBalancerName = $BasicLoadBalancer.Name
$StdLoadBalancerName = $BasicLoadBalancer.Name
$LBConfig.standardLoadBalancerName = $LBConfig.basicLoadBalancer.Name
$StdLoadBalancerName = $LBConfig.basicLoadBalancer.Name
}

$BasicLoadBalancer = $LBConfig.basicLoadBalancer
Expand Down Expand Up @@ -325,7 +325,7 @@ function Start-AzBasicLoadBalancerUpgrade {
Write-Progress -Activity "Preparing for Migration" -Status "Preparing for Migration" -Id 3 -PercentComplete 0
log -Message "[Start-AzBasicLoadBalancerUpgrade] Preparing for migration by backing up and deleteing the basic LB(s)"
$migrationConfigs = LBMigrationPrep -migrationConfigs $migrationConfigs -RecoveryBackupPath $RecoveryBackupPath
Write-Progress -Activity "Preparing for Migration" -Status "Preparing for Migration" -Completed -Id 3
Write-Progress -Activity "Preparing for Migration" -Status "Completed preparing for migration" -Completed -Id 3

# initiate the migration of each load balancer in the migration config array
Write-Progress -Activity "Starting Migration" -Status "Starting Migration" -Id 4
Expand Down

0 comments on commit 90551e6

Please sign in to comment.