Skip to content

Commit

Permalink
mgmt, fix vmss outdated vm (Azure#33444)
Browse files Browse the repository at this point in the history
* don't fill osDisk for ephemeral VMSS

* fix vmss with ephemeral os disk out-of-date vm issue
  • Loading branch information
XiaofeiCao committed Feb 10, 2023
1 parent f1d0cbd commit 5bf8dff
Show file tree
Hide file tree
Showing 4 changed files with 810 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bugs Fixed

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

## 2.23.0 (2023-01-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import java.util.ArrayList;

class VMSSPatchPayload {
/*
* Note: innerModel().virtualMachineProfile().storageProfile().osDisk() won't be set if the scale set has ephemeral OS disk.
* This may change if backend service decides that ephemeral osDisk can be updated.
*/
static VirtualMachineScaleSetUpdate preparePatchPayload(VirtualMachineScaleSet scaleSet) {
VirtualMachineScaleSetUpdate updateParameter = new VirtualMachineScaleSetUpdate();
//
Expand Down Expand Up @@ -49,7 +53,14 @@ static VirtualMachineScaleSetUpdate preparePatchPayload(VirtualMachineScaleSet s
.withImageReference(
scaleSet.innerModel().virtualMachineProfile().storageProfile().imageReference());

if (scaleSet.innerModel().virtualMachineProfile().storageProfile().osDisk() != null) {
if (scaleSet.innerModel().virtualMachineProfile().storageProfile().osDisk() != null
// Filling patch payload with osDisk property for VMSS with ephemeral OS disks will be considered updating VM model.
// This may have impact if user want to update the scale set without leaving existing VMs outdated,
// e.g. scale out using `withCapacity`, especially if the scale set's `updatePolicy` is `Rolling` or `Automatic`, which may trigger
// a VM restart.
// Thus, we won't fill for VMSS with ephemeral OS disks.
&& !scaleSet.isEphemeralOSDisk()
) {
VirtualMachineScaleSetUpdateOSDisk osDisk = new VirtualMachineScaleSetUpdateOSDisk();
osDisk
.withCaching(scaleSet.innerModel().virtualMachineProfile().storageProfile().osDisk().caching());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,13 +1853,36 @@ public void canCreateVMSSWithEphemeralOSDisk() throws Exception {
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS)
.withRootUsername("jvuser")
.withSsh(sshPublicKey())
.withUpgradeMode(UpgradeMode.AUTOMATIC)
.withUpgradeMode(UpgradeMode.MANUAL)
.withEphemeralOSDisk()
.withPlacement(DiffDiskPlacement.CACHE_DISK)
.withCapacity(2)
.withCapacity(1)
.create();
Assertions.assertTrue(uniformVMSS.isEphemeralOSDisk());

// somehow newly created vmss with ephemeral OS disk has outdated VMs and there's a delay before vmss detects that
ResourceManagerUtils.sleep(Duration.ofMinutes(1));

// update VMs to latest model, create baseline
uniformVMSS.virtualMachines().updateInstances(
uniformVMSS.virtualMachines()
.list()
.stream()
.map(VirtualMachineScaleSetVM::instanceId)
.toArray(String[]::new));

Assertions.assertTrue(uniformVMSS.virtualMachines().list().stream().allMatch(VirtualMachineScaleSetVM::isLatestScaleSetUpdateApplied));

// scale up vmss
uniformVMSS.update()
.withCapacity(2)
.apply();

ResourceManagerUtils.sleep(Duration.ofMinutes(1));

// verify that scaling up won't result in outdated VMs
Assertions.assertTrue(uniformVMSS.virtualMachines().list().stream().allMatch(VirtualMachineScaleSetVM::isLatestScaleSetUpdateApplied));

// flex vmss with ephemeral os disk
Network network2 =
this
Expand Down
Loading

0 comments on commit 5bf8dff

Please sign in to comment.