From 58806c32f9469e9892f03c7b7d8ad2df385b6f33 Mon Sep 17 00:00:00 2001 From: Jont828 Date: Mon, 12 Jun 2023 19:02:49 -0400 Subject: [PATCH] Fix race in spec_test.go --- azure/services/scalesets/spec_test.go | 94 ++++++++++++++------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/azure/services/scalesets/spec_test.go b/azure/services/scalesets/spec_test.go index d73547751a8..61d60898f5d 100644 --- a/azure/services/scalesets/spec_test.go +++ b/azure/services/scalesets/spec_test.go @@ -30,6 +30,28 @@ import ( "sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus" ) +var ( + defaultSpec, defaultVMSS = getDefaultVMSS() + windowsSpec, windowsVMSS = getDefaultWindowsVMSS() + acceleratedNetworkingSpec, acceleratedNetworkingVMSS = getAcceleratedNetworkingVMSS() + customSubnetSpec, customSubnetVMSS = getCustomSubnetVMSS() + customNetworkingSpec, customNetworkingVMSS = getCustomNetworkingVMSS() + spotVMSpec, spotVMVMSS = getSpotVMVMSS() + ephemeralSpec, ephemeralVMSS = getEPHVMSSS() + evictionSpec, evictionVMSS = getEvictionPolicyVMSS() + maxPriceSpec, maxPriceVMSS = getMaxPriceVMSS() + encryptionSpec, encryptionVMSS = getEncryptionVMSS() + userIdentitySpec, userIdentityVMSS = getUserIdentityVMSS() + hostEncryptionSpec, hostEncryptionVMSS = getHostEncryptionVMSS() + hostEncryptionUnsupportedSpec = getHostEncryptionUnsupportedSpec() + ephemeralReadSpec, ephemeralReadVMSS = getEphemeralReadOnlyVMSS() + defaultExistingSpec, defaultExistingVMSS, defaultExistingVMSSClone = getExistingDefaultVMSS() + userManagedStorageAccountDiagnosticsSpec, userManagedStorageAccountDiagnosticsVMSS = getUserManagedAndStorageAcccountDiagnosticsVMSS() + managedDiagnosticsSpec, managedDiagnoisticsVMSS = getManagedDiagnosticsVMSS() + disabledDiagnosticsSpec, disabledDiagnosticsVMSS = getDisabledDiagnosticsVMSS() + nilDiagnosticsProfileSpec, nilDiagnosticsProfileVMSS = getNilDiagnosticsProfileVMSS() +) + func getDefaultVMSS() (ScaleSetSpec, compute.VirtualMachineScaleSet) { spec := newDefaultVMSSSpec() spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ @@ -320,6 +342,12 @@ func getHostEncryptionVMSS() (ScaleSetSpec, compute.VirtualMachineScaleSet) { return spec, vmss } +func getHostEncryptionUnsupportedSpec() ScaleSetSpec { + spec, _ := getHostEncryptionVMSS() + spec.SKU = resourceskus.SKU{} + return spec +} + func getEphemeralReadOnlyVMSS() (ScaleSetSpec, compute.VirtualMachineScaleSet) { spec := newDefaultVMSSSpec() spec.Size = "VM_SIZE_EPH" @@ -493,178 +521,156 @@ func getNilDiagnosticsProfileVMSS() (ScaleSetSpec, compute.VirtualMachineScaleSe } func TestScaleSetParameters(t *testing.T) { - defaultSpec, defaultVMSS := getDefaultVMSS() - windowsSpec, windowsVMSS := getDefaultWindowsVMSS() - acceleratedNetworkingSpec, acceleratedNetworkingVMSS := getAcceleratedNetworkingVMSS() - customSubnetSpec, customSubnetVMSS := getCustomSubnetVMSS() - customNetworkingSpec, customNetworkingVMSS := getCustomNetworkingVMSS() - spotVMSpec, spotVMVMSS := getSpotVMVMSS() - ephemeralSpec, ephemeralVMSS := getEPHVMSSS() - evictionSpec, evictionVMSS := getEvictionPolicyVMSS() - maxPriceSpec, maxPriceVMSS := getMaxPriceVMSS() - encryptionSpec, encryptionVMSS := getEncryptionVMSS() - userIdentitySpec, userIdentityVMSS := getUserIdentityVMSS() - hostEncryptionSpec, hostEncryptionVMSS := getHostEncryptionVMSS() - hostEncryptionUnsupportedSpec, _ := getHostEncryptionVMSS() - hostEncryptionUnsupportedSpec.SKU = resourceskus.SKU{} - ephemeralReadSpec, ephemeralReadVMSS := getEphemeralReadOnlyVMSS() - - defaultExistingSpec, defaultExistingVMSS, defaultExistingVMSSClone := getExistingDefaultVMSS() - userManagedStorageAccountDiagnosticsSpec, userManagedStorageAccountDiagnosticsVMSS := getUserManagedAndStorageAcccountDiagnosticsVMSS() - managedDiagnosticsSpec, managedDiagnoisticsVMSS := getManagedDiagnosticsVMSS() - disabledDiagnosticsSpec, disabledDiagnosticsVMSS := getDisabledDiagnosticsVMSS() - nilDiagnosticsProfileSpec, nilDiagnosticsProfileVMSS := getNilDiagnosticsProfileVMSS() - testcases := []struct { name string - spec *ScaleSetSpec + spec ScaleSetSpec existing interface{} expected interface{} expectedError string }{ { name: "get parameters for a vmss", - spec: &defaultSpec, + spec: defaultSpec, existing: nil, expected: defaultVMSS, expectedError: "", }, { name: "get parameters for a windows vmss", - spec: &windowsSpec, + spec: windowsSpec, existing: nil, expected: windowsVMSS, expectedError: "", }, { name: "windows vmss up to date", - spec: &windowsSpec, + spec: windowsSpec, existing: windowsVMSS, expected: nil, expectedError: "", }, { name: "accelerated networking vmss", - spec: &acceleratedNetworkingSpec, + spec: acceleratedNetworkingSpec, existing: nil, expected: acceleratedNetworkingVMSS, expectedError: "", }, { name: "custom subnet vmss", - spec: &customSubnetSpec, + spec: customSubnetSpec, existing: nil, expected: customSubnetVMSS, expectedError: "", }, { name: "custom networking vmss", - spec: &customNetworkingSpec, + spec: customNetworkingSpec, existing: nil, expected: customNetworkingVMSS, expectedError: "", }, { name: "spot vm vmss", - spec: &spotVMSpec, + spec: spotVMSpec, existing: nil, expected: spotVMVMSS, expectedError: "", }, { name: "spot vm and ephemeral disk vmss", - spec: &ephemeralSpec, + spec: ephemeralSpec, existing: nil, expected: ephemeralVMSS, expectedError: "", }, { name: "spot vm and eviction policy vmss", - spec: &evictionSpec, + spec: evictionSpec, existing: nil, expected: evictionVMSS, expectedError: "", }, { name: "spot vm and max price vmss", - spec: &maxPriceSpec, + spec: maxPriceSpec, existing: nil, expected: maxPriceVMSS, expectedError: "", }, { name: "eviction policy vmss", - spec: &evictionSpec, + spec: evictionSpec, existing: nil, expected: evictionVMSS, expectedError: "", }, { name: "encryption vmss", - spec: &encryptionSpec, + spec: encryptionSpec, existing: nil, expected: encryptionVMSS, expectedError: "", }, { name: "user assigned identity vmss", - spec: &userIdentitySpec, + spec: userIdentitySpec, existing: nil, expected: userIdentityVMSS, expectedError: "", }, { name: "host encryption vmss", - spec: &hostEncryptionSpec, + spec: hostEncryptionSpec, existing: nil, expected: hostEncryptionVMSS, expectedError: "", }, { name: "host encryption unsupported vmss", - spec: &hostEncryptionUnsupportedSpec, + spec: hostEncryptionUnsupportedSpec, existing: nil, expected: nil, expectedError: "reconcile error that cannot be recovered occurred: encryption at host is not supported for VM type VM_SIZE_EAH. Object will not be requeued", }, { name: "ephemeral os disk read only vmss", - spec: &ephemeralReadSpec, + spec: ephemeralReadSpec, existing: nil, expected: ephemeralReadVMSS, expectedError: "", }, { name: "update for existing vmss", - spec: &defaultExistingSpec, + spec: defaultExistingSpec, existing: defaultExistingVMSS, expected: defaultExistingVMSSClone, expectedError: "", }, { name: "vm with diagnostics set to User Managed and StorageAccountURI set", - spec: &userManagedStorageAccountDiagnosticsSpec, + spec: userManagedStorageAccountDiagnosticsSpec, existing: nil, expected: userManagedStorageAccountDiagnosticsVMSS, expectedError: "", }, { name: "vm with diagnostics set to Managed", - spec: &managedDiagnosticsSpec, + spec: managedDiagnosticsSpec, existing: nil, expected: managedDiagnoisticsVMSS, expectedError: "", }, { name: "vm with diagnostics set to Disabled", - spec: &disabledDiagnosticsSpec, + spec: disabledDiagnosticsSpec, existing: nil, expected: disabledDiagnosticsVMSS, expectedError: "", }, { name: "vm with DiagnosticsProfile set to nil, do not panic", - spec: &nilDiagnosticsProfileSpec, + spec: nilDiagnosticsProfileSpec, existing: nil, expected: nilDiagnosticsProfileVMSS, expectedError: "",