@@ -33,26 +33,28 @@ import (
3333)
3434
3535var (
36- defaultSpec , defaultVMSS = getDefaultVMSS ()
37- windowsSpec , windowsVMSS = getDefaultWindowsVMSS ()
38- acceleratedNetworkingSpec , acceleratedNetworkingVMSS = getAcceleratedNetworkingVMSS ()
39- customSubnetSpec , customSubnetVMSS = getCustomSubnetVMSS ()
40- customNetworkingSpec , customNetworkingVMSS = getCustomNetworkingVMSS ()
41- spotVMSpec , spotVMVMSS = getSpotVMVMSS ()
42- ephemeralSpec , ephemeralVMSS = getEPHVMSSS ()
43- resourceDiskSpec , resourceDiskVMSS = getResourceDiskVMSS ()
44- evictionSpec , evictionVMSS = getEvictionPolicyVMSS ()
45- maxPriceSpec , maxPriceVMSS = getMaxPriceVMSS ()
46- encryptionSpec , encryptionVMSS = getEncryptionVMSS ()
47- userIdentitySpec , userIdentityVMSS = getUserIdentityVMSS ()
48- hostEncryptionSpec , hostEncryptionVMSS = getHostEncryptionVMSS ()
49- hostEncryptionUnsupportedSpec = getHostEncryptionUnsupportedSpec ()
50- ephemeralReadSpec , ephemeralReadVMSS = getEphemeralReadOnlyVMSS ()
51- defaultExistingSpec , defaultExistingVMSS , defaultExistingVMSSClone = getExistingDefaultVMSS ()
52- userManagedStorageAccountDiagnosticsSpec , userManagedStorageAccountDiagnosticsVMSS = getUserManagedAndStorageAcccountDiagnosticsVMSS ()
53- managedDiagnosticsSpec , managedDiagnoisticsVMSS = getManagedDiagnosticsVMSS ()
54- disabledDiagnosticsSpec , disabledDiagnosticsVMSS = getDisabledDiagnosticsVMSS ()
55- nilDiagnosticsProfileSpec , nilDiagnosticsProfileVMSS = getNilDiagnosticsProfileVMSS ()
36+ defaultSpec , defaultVMSS = getDefaultVMSS ()
37+ windowsSpec , windowsVMSS = getDefaultWindowsVMSS ()
38+ acceleratedNetworkingSpec , acceleratedNetworkingVMSS = getAcceleratedNetworkingVMSS ()
39+ customSubnetSpec , customSubnetVMSS = getCustomSubnetVMSS ()
40+ customNetworkingSpec , customNetworkingVMSS = getCustomNetworkingVMSS ()
41+ spotVMSpec , spotVMVMSS = getSpotVMVMSS ()
42+ ephemeralSpec , ephemeralVMSS = getEPHVMSSS ()
43+ resourceDiskSpec , resourceDiskVMSS = getResourceDiskVMSS ()
44+ evictionSpec , evictionVMSS = getEvictionPolicyVMSS ()
45+ maxPriceSpec , maxPriceVMSS = getMaxPriceVMSS ()
46+ encryptionSpec , encryptionVMSS = getEncryptionVMSS ()
47+ userIdentitySpec , userIdentityVMSS = getUserIdentityVMSS ()
48+ hostEncryptionSpec , hostEncryptionVMSS = getHostEncryptionVMSS ()
49+ hostEncryptionUnsupportedSpec = getHostEncryptionUnsupportedSpec ()
50+ ephemeralReadSpec , ephemeralReadVMSS = getEphemeralReadOnlyVMSS ()
51+ defaultExistingSpec , defaultExistingVMSS , defaultExistingVMSSClone = getExistingDefaultVMSS ()
52+ defaultExistingSpecOnlyCapacityChange , defaultExistingVMSSOnlyCapacityChange , defaultExistingVMSSResultOnlyCapacityChange = getExistingDefaultVMSSOnlyCapacityChange ()
53+ defaultExistingSpecOnlyCapacityChangeWithCustomDataChange , defaultExistingVMSSOnlyCapacityChangeWithCustomDataChange , defaultExistingVMSSResultOnlyCapacityChangeWithCustomDataChange = getExistingDefaultVMSSOnlyCapacityChangeWithCustomDataChange ()
54+ userManagedStorageAccountDiagnosticsSpec , userManagedStorageAccountDiagnosticsVMSS = getUserManagedAndStorageAcccountDiagnosticsVMSS ()
55+ managedDiagnosticsSpec , managedDiagnoisticsVMSS = getManagedDiagnosticsVMSS ()
56+ disabledDiagnosticsSpec , disabledDiagnosticsVMSS = getDisabledDiagnosticsVMSS ()
57+ nilDiagnosticsProfileSpec , nilDiagnosticsProfileVMSS = getNilDiagnosticsProfileVMSS ()
5658)
5759
5860func getDefaultVMSS () (ScaleSetSpec , armcompute.VirtualMachineScaleSet ) {
@@ -430,19 +432,54 @@ func getExistingDefaultVMSS() (s ScaleSetSpec, existing armcompute.VirtualMachin
430432 existingVMSS := newDefaultExistingVMSS ("VM_SIZE" )
431433 existingVMSS .Properties .AdditionalCapabilities = & armcompute.AdditionalCapabilities {UltraSSDEnabled : ptr .To (true )}
432434 existingVMSS .SKU .Capacity = ptr.To [int64 ](2 )
433- existingVMSS .Properties .AdditionalCapabilities = & armcompute.AdditionalCapabilities {UltraSSDEnabled : ptr .To (true )}
434435
435436 clone := newDefaultExistingVMSS ("VM_SIZE" )
436437 clone .SKU .Capacity = ptr.To [int64 ](3 )
437438 clone .Properties .AdditionalCapabilities = & armcompute.AdditionalCapabilities {UltraSSDEnabled : ptr .To (true )}
438439 clone .Properties .VirtualMachineProfile .NetworkProfile = nil
439440
440441 clone .Properties .VirtualMachineProfile .StorageProfile .ImageReference .Version = ptr .To ("2.0" )
441- clone .Properties .VirtualMachineProfile .NetworkProfile = nil
442442
443443 return spec , existingVMSS , clone
444444}
445445
446+ func getExistingDefaultVMSSOnlyCapacityChange () (s ScaleSetSpec , existing armcompute.VirtualMachineScaleSet , result armcompute.VirtualMachineScaleSet ) {
447+ spec := newDefaultVMSSSpec ()
448+ spec .Capacity = 3
449+
450+ existingVMSS := newDefaultExistingVMSS ("VM_SIZE" )
451+
452+ result = newDefaultExistingVMSS ("VM_SIZE" )
453+ result .Properties .VirtualMachineProfile = nil
454+ result .SKU .Capacity = ptr.To [int64 ](3 )
455+
456+ return spec , existingVMSS , result
457+ }
458+
459+ func getExistingDefaultVMSSOnlyCapacityChangeWithCustomDataChange () (s ScaleSetSpec , existing armcompute.VirtualMachineScaleSet , result armcompute.VirtualMachineScaleSet ) {
460+ spec := newDefaultVMSSSpec ()
461+ spec .Capacity = 3
462+ spec .DataDisks = append (spec .DataDisks , infrav1.DataDisk {
463+ NameSuffix : "my_disk_with_ultra_disks" ,
464+ DiskSizeGB : 128 ,
465+ Lun : ptr.To [int32 ](3 ),
466+ ManagedDisk : & infrav1.ManagedDiskParameters {
467+ StorageAccountType : "UltraSSD_LRS" ,
468+ },
469+ })
470+ spec .ShouldPatchCustomData = true
471+
472+ existingVMSS := newDefaultExistingVMSS ("VM_SIZE" )
473+ existingVMSS .Properties .AdditionalCapabilities = & armcompute.AdditionalCapabilities {UltraSSDEnabled : ptr .To (true )}
474+
475+ result = newDefaultExistingVMSS ("VM_SIZE" )
476+ result .SKU .Capacity = ptr.To [int64 ](3 )
477+ result .Properties .AdditionalCapabilities = & armcompute.AdditionalCapabilities {UltraSSDEnabled : ptr .To (true )}
478+ result .Properties .VirtualMachineProfile .NetworkProfile = nil
479+
480+ return spec , existingVMSS , result
481+ }
482+
446483func getUserManagedAndStorageAcccountDiagnosticsVMSS () (ScaleSetSpec , armcompute.VirtualMachineScaleSet ) {
447484 storageURI := "https://fakeurl"
448485 spec := newDefaultVMSSSpec ()
@@ -712,6 +749,20 @@ func TestScaleSetParameters(t *testing.T) {
712749 expected : nilDiagnosticsProfileVMSS ,
713750 expectedError : "" ,
714751 },
752+ {
753+ name : "update for existing vmss with only capacity change" ,
754+ spec : defaultExistingSpecOnlyCapacityChange ,
755+ existing : defaultExistingVMSSOnlyCapacityChange ,
756+ expected : defaultExistingVMSSResultOnlyCapacityChange ,
757+ expectedError : "" ,
758+ },
759+ {
760+ name : "update for existing vmss with only capacity change but should patch custom data" ,
761+ spec : defaultExistingSpecOnlyCapacityChangeWithCustomDataChange ,
762+ existing : defaultExistingVMSSOnlyCapacityChangeWithCustomDataChange ,
763+ expected : defaultExistingVMSSResultOnlyCapacityChangeWithCustomDataChange ,
764+ expectedError : "" ,
765+ },
715766 }
716767 for _ , tc := range testcases {
717768 t .Run (tc .name , func (t * testing.T ) {
@@ -731,7 +782,9 @@ func TestScaleSetParameters(t *testing.T) {
731782 if ! ok {
732783 t .Fatalf ("expected type VirtualMachineScaleSet, got %T" , param )
733784 }
734- result .Properties .VirtualMachineProfile .OSProfile .AdminPassword = nil // Override this field as it's randomly generated. We can't set anything in tc.expected to match it.
785+ if result .Properties .VirtualMachineProfile != nil {
786+ result .Properties .VirtualMachineProfile .OSProfile .AdminPassword = nil // Override this field as it's randomly generated. We can't set anything in tc.expected to match it.
787+ }
735788
736789 if ! reflect .DeepEqual (tc .expected , result ) {
737790 t .Errorf ("Diff between actual result and expected result:\n %s" , cmp .Diff (result , tc .expected ))
0 commit comments