Skip to content

Commit 66d7ef9

Browse files
authored
Support AutoOsUpgrade when App Health Extension Used (#129)
* support autoosupgrade when using health extension probe * v2.4.13 * beta version * release note * prerelease flag * v2.4.14
1 parent fc593e1 commit 66d7ef9

File tree

4 files changed

+206
-8
lines changed

4 files changed

+206
-8
lines changed

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/AzureBasicLoadBalancerUpgrade.psd1

Lines changed: 3 additions & 3 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.4.13'
15+
ModuleVersion = '2.4.14'
1616

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

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'Added NAT pool migration parameter note'
110+
ReleaseNotes = 'Added support to retain AutomaticOSUpgrade setting when App Health extension is used instead of health probe.'
111111

112112
# Prerelease string of this module
113-
# Prerelease = ''
113+
# Prerelease = 'beta'
114114

115115
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
116116
# RequireLicenseAcceptance = $false

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/RemoveBasicLoadBalancer/RemoveBasicLoadBalancer.psm1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ function RemoveBasicLoadBalancer {
1919
log -Message "[RemoveBasicLoadBalancerFromVmss] Building VMSS object from Basic Load Balancer $($BasicLoadBalancer.Name)"
2020
$vmss = GetVmssFromBasicLoadBalancer -BasicLoadBalancer $BasicLoadBalancer
2121

22-
log -Message "[RemoveBasicLoadBalancerFromVmss] Cleaning healthProbe from NetworkProfile of VMSS $($vmss.Name)"
23-
$vmss.VirtualMachineProfile.NetworkProfile.healthProbe = $null
24-
2522
log -Message "[RemoveBasicLoadBalancerFromVmss] Checking Upgrade Policy Mode of VMSS $($vmss.Name)"
2623
if ($vmss.UpgradePolicy.Mode -eq "Rolling") {
2724
log -Message "[RemoveBasicLoadBalancerFromVmss] Upgrade Policy Mode of VMSS $($vmss.Name) is Rolling"
@@ -32,10 +29,20 @@ function RemoveBasicLoadBalancer {
3229
log -Message "[RemoveBasicLoadBalancerFromVmss] Checking Automatic OS Upgrade policy of VMSS $($vmss.Name)"
3330
if ($vmss.upgradePolicy.AutomaticOSUpgradePolicy.enableAutomaticOSUpgrade -eq $true) {
3431
log -Message "[RemoveBasicLoadBalancerFromVmss] Automatic OS Upgrade policy of VMSS $($vmss.Name) is enabled"
35-
log -Message "[RemoveBasicLoadBalancerFromVmss] Disabling Automatic OS Upgrade policy of VMSS $($vmss.Name)--will be reset to 'true' following the LB upgrade."
36-
$vmss.upgradePolicy.AutomaticOSUpgradePolicy.enableAutomaticOSUpgrade = $false
32+
33+
If ($null -ne $vmss.VirtualMachineProfile.NetworkProfile.healthProbe) {
34+
log -Message "[RemoveBasicLoadBalancerFromVmss] VMSS is using LB-based health probe. EnableAutomaticOSUpgrade cannot be true if neither health probe or application health extension exists and the health probe will be removed during migration, so enableAutomaticOSUpgrade will be set to false and reverted post-migration."
35+
$vmss.upgradePolicy.AutomaticOSUpgradePolicy.enableAutomaticOSUpgrade = $false
36+
}
37+
ElseIf ($vmss.VirtualMachineProfile.ExtensionProfile.Extensions.Type -contains 'ApplicationHealthLinux' -or
38+
$vmss.VirtualMachineProfile.ExtensionProfile.Extensions.Type -contains 'ApplicationHealthWindows') {
39+
log -Message "[RemoveBasicLoadBalancerFromVmss] VMSS is using Application Health Extension, so enableAutomaticOSUpgrade can remain enabled."
40+
}
3741
}
3842

43+
log -Message "[RemoveBasicLoadBalancerFromVmss] Cleaning healthProbe from NetworkProfile of VMSS $($vmss.Name)"
44+
$vmss.VirtualMachineProfile.NetworkProfile.healthProbe = $null
45+
3946
log -Message "[RemoveBasicLoadBalancerFromVmss] Cleaning LoadBalancerBackendAddressPools from Basic Load Balancer $($BasicLoadBalancer.Name)"
4047
foreach ($networkInterfaceConfiguration in $vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations) {
4148
foreach ($ipConfiguration in $networkInterfaceConfiguration.IpConfigurations) {

AzureBasicLoadBalancerUpgrade/testEnvs/modules/Microsoft.Compute/virtualMachineScaleSets_custom/deploy.bicep

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ param publicIpDiagnosticSettingsName string = '${name}-diagnosticSettings'
288288
@description('Health probe ID for Rolling upgrade')
289289
param healthProbeId string = ''
290290

291+
param extensionAppHealth object = {
292+
enabled: false
293+
}
294+
291295
var diagnosticsMetrics = [for metric in diagnosticMetricsToEnable: {
292296
category: metric
293297
timeGrain: null
@@ -454,6 +458,25 @@ resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2022-03-01' = {
454458
evictionPolicy: enableEvictionPolicy ? 'Deallocate' : null
455459
billingProfile: !empty(vmPriority) && !empty(maxPriceForLowPriorityVm) ? json('{"maxPrice":"${maxPriceForLowPriorityVm}"}') : null
456460
scheduledEventsProfile: scheduledEventsProfile
461+
extensionProfile: (extensionAppHealth.enabled) ? {
462+
extensions: [
463+
{
464+
name: 'HealthExtension'
465+
properties: {
466+
publisher: 'Microsoft.ManagedServices'
467+
type: 'ApplicationHealthWindows'
468+
autoUpgradeMinorVersion: true
469+
typeHandlerVersion: '1.0'
470+
settings: {
471+
protocol: 'tcp'
472+
port: 3389
473+
intervalInSeconds: 5
474+
numberOfProbes: 1
475+
}
476+
}
477+
}
478+
]
479+
} : null
457480
}
458481
overprovision: overprovision
459482
doNotRunExtensionsOnOverprovisionedVMs: doNotRunExtensionsOnOverprovisionedVMs
@@ -615,6 +638,27 @@ module vmss_azureDiskEncryptionExtension 'extensions/deploy.bicep' = if (extensi
615638
]
616639
}
617640

641+
// module vmss_ApplicationHealthExtension 'extensions/deploy.bicep' = if (extensionAppHealth.enabled) {
642+
// name: '${uniqueString(deployment().name, location)}-VMSS-AppHealthExtension'
643+
// params: {
644+
// virtualMachineScaleSetName: vmss.name
645+
// name: 'health'
646+
// publisher: 'Microsoft.ManagedServices'
647+
// type: 'ApplicationHealthWindows'
648+
// typeHandlerVersion: '1.0'
649+
// autoUpgradeMinorVersion: true
650+
// enableAutomaticUpgrade: true
651+
// settings: {
652+
// protocol: 'tcp'
653+
// port: 3389
654+
// }
655+
// enableDefaultTelemetry: enableReferencedModulesTelemetry
656+
// }
657+
// dependsOn: [
658+
// vmss_desiredStateConfigurationExtension
659+
// ]
660+
// }
661+
618662
resource vmss_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock)) {
619663
name: '${vmss.name}-${lock}-lock'
620664
properties: {
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
targetScope = 'subscription'
2+
param randomGuid string = newGuid()
3+
param location string
4+
param resourceGroupName string
5+
6+
7+
// Resource Group
8+
module rg '../modules/Microsoft.Resources/resourceGroups/deploy.bicep' = {
9+
name: '${resourceGroupName}-${location}'
10+
params: {
11+
name: resourceGroupName
12+
location: location
13+
}
14+
}
15+
16+
// vnet
17+
module virtualNetworks '../modules/Microsoft.Network/virtualNetworks/deploy.bicep' = {
18+
name: '${uniqueString(deployment().name)}-virtualNetworks'
19+
scope: resourceGroup(resourceGroupName)
20+
params: {
21+
// Required parameters
22+
location: location
23+
addressPrefixes: [
24+
'10.0.0.0/16'
25+
]
26+
name: 'vnet-01'
27+
subnets: [
28+
{
29+
name: 'subnet-01'
30+
addressPrefix: '10.0.1.0/24'
31+
}
32+
]
33+
}
34+
dependsOn: [
35+
rg
36+
]
37+
}
38+
39+
// basic lb
40+
module loadbalancer '../modules/Microsoft.Network/loadBalancers_custom/deploy.bicep' = {
41+
name: 'lb-basic-01'
42+
scope: resourceGroup(resourceGroupName)
43+
params: {
44+
name: 'lb-basic-01'
45+
location: location
46+
frontendIPConfigurations: [
47+
{
48+
name: 'fe-01'
49+
subnetId: virtualNetworks.outputs.subnetResourceIds[0]
50+
}
51+
]
52+
backendAddressPools: [
53+
{
54+
name: 'be-01'
55+
}
56+
]
57+
inboundNatRules: []
58+
loadBalancerSku: 'Basic'
59+
loadBalancingRules: [
60+
{
61+
backendAddressPoolName: 'be-01'
62+
backendPort: 80
63+
frontendIPConfigurationName: 'fe-01'
64+
frontendPort: 80
65+
idleTimeoutInMinutes: 4
66+
loadDistribution: 'Default'
67+
name: 'rule-01'
68+
probeName: 'probe-01'
69+
protocol: 'Tcp'
70+
}
71+
]
72+
probes: [
73+
{
74+
intervalInSeconds: 5
75+
name: 'probe-01'
76+
numberOfProbes: 2
77+
port: '80'
78+
protocol: 'Tcp'
79+
}
80+
]
81+
}
82+
dependsOn: [
83+
rg
84+
]
85+
}
86+
87+
88+
module virtualMachineScaleSets '../modules/Microsoft.Compute/virtualMachineScaleSets_custom/deploy.bicep' = {
89+
name: 'vmss-01'
90+
scope: resourceGroup(resourceGroupName)
91+
params: {
92+
location: location
93+
// Required parameters
94+
encryptionAtHost: false
95+
adminUsername: 'admin-vmss'
96+
skuCapacity: 1
97+
upgradePolicyMode:'Automatic'
98+
enableAutomaticUpdates: false
99+
enableAutomaticOSUpgrade: true
100+
//healthProbeId: '${loadbalancer.outputs.resourceId}/probes/probe-01'
101+
imageReference: {
102+
offer: 'WindowsServer'
103+
publisher: 'MicrosoftWindowsServer'
104+
sku: '2022-Datacenter'
105+
version: 'latest'
106+
}
107+
name: 'vmss-01'
108+
osDisk: {
109+
createOption: 'fromImage'
110+
diskSizeGB: '128'
111+
managedDisk: {
112+
storageAccountType: 'Standard_LRS'
113+
}
114+
}
115+
osType: 'Windows'
116+
skuName: 'Standard_DS1_v2'
117+
// Non-required parameters
118+
adminPassword: '${uniqueString(randomGuid)}rpP@340'
119+
nicConfigurations: [
120+
{
121+
ipConfigurations: [
122+
{
123+
name: 'ipconfig1'
124+
properties: {
125+
subnet: {
126+
id: virtualNetworks.outputs.subnetResourceIds[0]
127+
}
128+
loadBalancerBackendAddressPools: [
129+
{
130+
id: loadbalancer.outputs.backendpools[0].id
131+
}
132+
]
133+
}
134+
}
135+
]
136+
nicSuffix: '-nic-01'
137+
}
138+
]
139+
extensionAppHealth: {
140+
enabled: true
141+
}
142+
}
143+
dependsOn: [
144+
rg
145+
]
146+
}
147+

0 commit comments

Comments
 (0)