Skip to content

Commit 5bf8dff

Browse files
authored
mgmt, fix vmss outdated vm (Azure#33444)
* don't fill osDisk for ephemeral VMSS * fix vmss with ephemeral os disk out-of-date vm issue
1 parent f1d0cbd commit 5bf8dff

File tree

4 files changed

+810
-428
lines changed

4 files changed

+810
-428
lines changed

sdk/resourcemanager/azure-resourcemanager-compute/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bugs Fixed
66

77
- Fixed wrong javadocs of `withSsh()` in `VirtualMachine` and `VirtualMachineScaleSet`.
8+
- Fixed a bug that scaling up scale sets results in outdated models for existing VMs.
89

910
## 2.23.0 (2023-01-27)
1011

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/implementation/VMSSPatchPayload.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import java.util.ArrayList;
2020

2121
class VMSSPatchPayload {
22+
/*
23+
* Note: innerModel().virtualMachineProfile().storageProfile().osDisk() won't be set if the scale set has ephemeral OS disk.
24+
* This may change if backend service decides that ephemeral osDisk can be updated.
25+
*/
2226
static VirtualMachineScaleSetUpdate preparePatchPayload(VirtualMachineScaleSet scaleSet) {
2327
VirtualMachineScaleSetUpdate updateParameter = new VirtualMachineScaleSetUpdate();
2428
//
@@ -49,7 +53,14 @@ static VirtualMachineScaleSetUpdate preparePatchPayload(VirtualMachineScaleSet s
4953
.withImageReference(
5054
scaleSet.innerModel().virtualMachineProfile().storageProfile().imageReference());
5155

52-
if (scaleSet.innerModel().virtualMachineProfile().storageProfile().osDisk() != null) {
56+
if (scaleSet.innerModel().virtualMachineProfile().storageProfile().osDisk() != null
57+
// Filling patch payload with osDisk property for VMSS with ephemeral OS disks will be considered updating VM model.
58+
// This may have impact if user want to update the scale set without leaving existing VMs outdated,
59+
// e.g. scale out using `withCapacity`, especially if the scale set's `updatePolicy` is `Rolling` or `Automatic`, which may trigger
60+
// a VM restart.
61+
// Thus, we won't fill for VMSS with ephemeral OS disks.
62+
&& !scaleSet.isEphemeralOSDisk()
63+
) {
5364
VirtualMachineScaleSetUpdateOSDisk osDisk = new VirtualMachineScaleSetUpdateOSDisk();
5465
osDisk
5566
.withCaching(scaleSet.innerModel().virtualMachineProfile().storageProfile().osDisk().caching());

sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetOperationsTests.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,13 +1853,36 @@ public void canCreateVMSSWithEphemeralOSDisk() throws Exception {
18531853
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS)
18541854
.withRootUsername("jvuser")
18551855
.withSsh(sshPublicKey())
1856-
.withUpgradeMode(UpgradeMode.AUTOMATIC)
1856+
.withUpgradeMode(UpgradeMode.MANUAL)
18571857
.withEphemeralOSDisk()
18581858
.withPlacement(DiffDiskPlacement.CACHE_DISK)
1859-
.withCapacity(2)
1859+
.withCapacity(1)
18601860
.create();
18611861
Assertions.assertTrue(uniformVMSS.isEphemeralOSDisk());
18621862

1863+
// somehow newly created vmss with ephemeral OS disk has outdated VMs and there's a delay before vmss detects that
1864+
ResourceManagerUtils.sleep(Duration.ofMinutes(1));
1865+
1866+
// update VMs to latest model, create baseline
1867+
uniformVMSS.virtualMachines().updateInstances(
1868+
uniformVMSS.virtualMachines()
1869+
.list()
1870+
.stream()
1871+
.map(VirtualMachineScaleSetVM::instanceId)
1872+
.toArray(String[]::new));
1873+
1874+
Assertions.assertTrue(uniformVMSS.virtualMachines().list().stream().allMatch(VirtualMachineScaleSetVM::isLatestScaleSetUpdateApplied));
1875+
1876+
// scale up vmss
1877+
uniformVMSS.update()
1878+
.withCapacity(2)
1879+
.apply();
1880+
1881+
ResourceManagerUtils.sleep(Duration.ofMinutes(1));
1882+
1883+
// verify that scaling up won't result in outdated VMs
1884+
Assertions.assertTrue(uniformVMSS.virtualMachines().list().stream().allMatch(VirtualMachineScaleSetVM::isLatestScaleSetUpdateApplied));
1885+
18631886
// flex vmss with ephemeral os disk
18641887
Network network2 =
18651888
this

0 commit comments

Comments
 (0)