diff --git a/azure/converters/subnets.go b/azure/converters/subnets.go index 9ec2e9078b8..7aed7179334 100644 --- a/azure/converters/subnets.go +++ b/azure/converters/subnets.go @@ -18,24 +18,11 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "k8s.io/utils/ptr" - "sigs.k8s.io/cluster-api-provider-azure/azure" ) -// GetSubnetAddresses returns the address prefixes contained in a subnet. -func GetSubnetAddresses(subnet network.Subnet) []string { - var addresses []string - if subnet.SubnetPropertiesFormat != nil && subnet.SubnetPropertiesFormat.AddressPrefix != nil { - addresses = []string{ptr.Deref(subnet.SubnetPropertiesFormat.AddressPrefix, "")} - } else if subnet.SubnetPropertiesFormat != nil && subnet.SubnetPropertiesFormat.AddressPrefixes != nil { - addresses = azure.StringSlice(subnet.SubnetPropertiesFormat.AddressPrefixes) - } - return addresses -} - -// GetSubnetAddressesV2 returns the address prefixes contained in an SDK v2 subnet. -func GetSubnetAddressesV2(subnet *armnetwork.Subnet) []string { +// GetSubnetAddresses returns the address prefixes contained in an SDK v2 subnet. +func GetSubnetAddresses(subnet *armnetwork.Subnet) []string { var addresses []string if subnet.Properties != nil && subnet.Properties.AddressPrefix != nil { addresses = []string{ptr.Deref(subnet.Properties.AddressPrefix, "")} diff --git a/azure/converters/subnets_test.go b/azure/converters/subnets_test.go index 563a066fe50..0b980cadd8a 100644 --- a/azure/converters/subnets_test.go +++ b/azure/converters/subnets_test.go @@ -21,52 +21,11 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" . "github.com/onsi/gomega" "k8s.io/utils/ptr" ) func TestGetSubnetAddresses(t *testing.T) { - tests := []struct { - name string - subnet network.Subnet - want []string - }{ - { - name: "nil properties subnet", - subnet: network.Subnet{}, - }, - { - name: "subnet with single address prefix", - subnet: network.Subnet{ - SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: ptr.To("test-address-prefix"), - }, - }, - want: []string{"test-address-prefix"}, - }, - { - name: "subnet with multiple address prefixes", - subnet: network.Subnet{ - SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefixes: &[]string{"test-address-prefix-1", "test-address-prefix-2"}, - }, - }, - want: []string{"test-address-prefix-1", "test-address-prefix-2"}, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - g := NewGomegaWithT(t) - got := GetSubnetAddresses(tt.subnet) - g.Expect(got).To(Equal(tt.want), fmt.Sprintf("got: %v, want: %v", got, tt.want)) - }) - } -} - -func TestGetSubnetAddressesV2(t *testing.T) { tests := []struct { name string subnet armnetwork.Subnet @@ -100,7 +59,7 @@ func TestGetSubnetAddressesV2(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() g := NewGomegaWithT(t) - got := GetSubnetAddressesV2(&tt.subnet) + got := GetSubnetAddresses(&tt.subnet) g.Expect(got).To(Equal(tt.want), fmt.Sprintf("got: %v, want: %v", got, tt.want)) }) } diff --git a/azure/scope/machine.go b/azure/scope/machine.go index ae3fc8ad2d0..14f3985c8ab 100644 --- a/azure/scope/machine.go +++ b/azure/scope/machine.go @@ -22,7 +22,7 @@ import ( "encoding/json" "strings" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" @@ -147,9 +147,9 @@ func (m *MachineScope) InitMachineCache(ctx context.Context) error { return errors.Wrapf(err, "failed to get VM SKU %s in compute api", m.AzureMachine.Spec.VMSize) } - m.cache.availabilitySetSKU, err = skuCache.Get(ctx, string(compute.AvailabilitySetSkuTypesAligned), resourceskus.AvailabilitySets) + m.cache.availabilitySetSKU, err = skuCache.Get(ctx, string(armcompute.AvailabilitySetSKUTypesAligned), resourceskus.AvailabilitySets) if err != nil { - return errors.Wrapf(err, "failed to get availability set SKU %s in compute api", string(compute.AvailabilitySetSkuTypesAligned)) + return errors.Wrapf(err, "failed to get availability set SKU %s in compute api", string(armcompute.AvailabilitySetSKUTypesAligned)) } } diff --git a/azure/services/async/async_test.go b/azure/services/async/async_test.go index eb5a780d1e6..116bc3fa350 100644 --- a/azure/services/async/async_test.go +++ b/azure/services/async/async_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-05-01/resources" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/Azure/go-autorest/autorest" azureautorest "github.com/Azure/go-autorest/autorest/azure" . "github.com/onsi/gomega" @@ -57,8 +57,8 @@ var ( ResourceGroup: "test-group", Data: "ZmFrZSBiNjQgZnV0dXJlIGRhdGEK", } - fakeExistingResource = resources.GenericResource{} - fakeResourceParameters = resources.GenericResource{} + fakeExistingResource = armresources.GenericResource{} + fakeResourceParameters = armresources.GenericResource{} fakeInternalError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error") fakeNotFoundError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusNotFound}, "Not Found") errCtxExceeded = errors.New("ctx exceeded") diff --git a/azure/services/roleassignments/roleassignments.go b/azure/services/roleassignments/roleassignments.go index 25bf940d674..c649559fc9a 100644 --- a/azure/services/roleassignments/roleassignments.go +++ b/azure/services/roleassignments/roleassignments.go @@ -20,6 +20,7 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/pkg/errors" "sigs.k8s.io/cluster-api-provider-azure/azure" @@ -160,9 +161,9 @@ func (s *Service) getVMSSPrincipalID(ctx context.Context) (*string, error) { if err != nil { return nil, errors.Wrap(err, "failed to get principal ID for VMSS") } - resultVMSS, ok := resultVMSSIface.(compute.VirtualMachineScaleSet) + resultVMSS, ok := resultVMSSIface.(armcompute.VirtualMachineScaleSet) if !ok { - return nil, errors.Errorf("%T is not a compute.VirtualMachineScaleSet", resultVMSSIface) + return nil, errors.Errorf("%T is not an armcompute.VirtualMachineScaleSet", resultVMSSIface) } return resultVMSS.Identity.PrincipalID, nil diff --git a/azure/services/roleassignments/roleassignments_test.go b/azure/services/roleassignments/roleassignments_test.go index f7b55d58862..ea912b3d79e 100644 --- a/azure/services/roleassignments/roleassignments_test.go +++ b/azure/services/roleassignments/roleassignments_test.go @@ -22,6 +22,7 @@ import ( "net/http" "testing" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" . "github.com/onsi/gomega" @@ -174,8 +175,8 @@ func TestReconcileRoleAssignmentsVMSS(t *testing.T) { s.RoleAssignmentResourceType().Return(azure.VirtualMachineScaleSet) s.ResourceGroup().Return("my-rg") s.Name().Return("test-vmss") - mvmss.Get(gomockinternal.AContext(), &fakeVMSSSpec).Return(compute.VirtualMachineScaleSet{ - Identity: &compute.VirtualMachineScaleSetIdentity{ + mvmss.Get(gomockinternal.AContext(), &fakeVMSSSpec).Return(armcompute.VirtualMachineScaleSet{ + Identity: &armcompute.VirtualMachineScaleSetIdentity{ PrincipalID: &fakePrincipalID, }, }, nil) @@ -192,7 +193,7 @@ func TestReconcileRoleAssignmentsVMSS(t *testing.T) { s.ResourceGroup().Return("my-rg") s.Name().Return("test-vmss") s.HasSystemAssignedIdentity().Return(true) - mvmss.Get(gomockinternal.AContext(), &fakeVMSSSpec).Return(compute.VirtualMachineScaleSet{}, + mvmss.Get(gomockinternal.AContext(), &fakeVMSSSpec).Return(armcompute.VirtualMachineScaleSet{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error")) }, }, @@ -207,8 +208,8 @@ func TestReconcileRoleAssignmentsVMSS(t *testing.T) { s.RoleAssignmentResourceType().Return(azure.VirtualMachineScaleSet) s.ResourceGroup().Return("my-rg") s.Name().Return("test-vmss") - mvmss.Get(gomockinternal.AContext(), &fakeVMSSSpec).Return(compute.VirtualMachineScaleSet{ - Identity: &compute.VirtualMachineScaleSetIdentity{ + mvmss.Get(gomockinternal.AContext(), &fakeVMSSSpec).Return(armcompute.VirtualMachineScaleSet{ + Identity: &armcompute.VirtualMachineScaleSetIdentity{ PrincipalID: &fakePrincipalID, }, }, nil) diff --git a/azure/services/subnets/subnets.go b/azure/services/subnets/subnets.go index 3e85b920309..590b5639c20 100644 --- a/azure/services/subnets/subnets.go +++ b/azure/services/subnets/subnets.go @@ -95,7 +95,7 @@ func (s *Service) Reconcile(ctx context.Context) error { return errors.Errorf("%T is not an armnetwork.Subnet", result) } s.Scope.UpdateSubnetID(subnetSpec.ResourceName(), ptr.Deref(subnet.ID, "")) - s.Scope.UpdateSubnetCIDRs(subnetSpec.ResourceName(), converters.GetSubnetAddressesV2(&subnet)) + s.Scope.UpdateSubnetCIDRs(subnetSpec.ResourceName(), converters.GetSubnetAddresses(&subnet)) } } diff --git a/azure/services/virtualnetworks/virtualnetworks.go b/azure/services/virtualnetworks/virtualnetworks.go index 1d25fc22ab0..4069fbf4b83 100644 --- a/azure/services/virtualnetworks/virtualnetworks.go +++ b/azure/services/virtualnetworks/virtualnetworks.go @@ -115,7 +115,7 @@ func (s *Service) Reconcile(ctx context.Context) error { // Subnets that are not part of this cluster spec are silently ignored. if existingVnet.Properties.Subnets != nil { for _, subnet := range existingVnet.Properties.Subnets { - s.Scope.UpdateSubnetCIDRs(ptr.Deref(subnet.Name, ""), converters.GetSubnetAddressesV2(subnet)) + s.Scope.UpdateSubnetCIDRs(ptr.Deref(subnet.Name, ""), converters.GetSubnetAddresses(subnet)) } } } diff --git a/exp/api/v1beta1/azuremachinepool_webhook.go b/exp/api/v1beta1/azuremachinepool_webhook.go index ec2c6088797..15c7af5ee3b 100644 --- a/exp/api/v1beta1/azuremachinepool_webhook.go +++ b/exp/api/v1beta1/azuremachinepool_webhook.go @@ -21,7 +21,7 @@ import ( "fmt" "reflect" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/blang/semver" "github.com/pkg/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -298,7 +298,7 @@ func (amp *AzureMachinePool) ValidateDiagnostics() error { func (amp *AzureMachinePool) ValidateOrchestrationMode(c client.Client) func() error { return func() error { // Only Flexible orchestration mode requires validation. - if amp.Spec.OrchestrationMode == infrav1.OrchestrationModeType(compute.OrchestrationModeFlexible) { + if amp.Spec.OrchestrationMode == infrav1.OrchestrationModeType(armcompute.OrchestrationModeFlexible) { parent, err := azureutil.FindParentMachinePoolWithRetry(amp.Name, c, 5) if err != nil { return errors.Wrap(err, "failed to find parent MachinePool") diff --git a/exp/api/v1beta1/azuremachinepool_webhook_test.go b/exp/api/v1beta1/azuremachinepool_webhook_test.go index 183115ced0c..18e11070338 100644 --- a/exp/api/v1beta1/azuremachinepool_webhook_test.go +++ b/exp/api/v1beta1/azuremachinepool_webhook_test.go @@ -24,7 +24,7 @@ import ( "fmt" "testing" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" guuid "github.com/google/uuid" . "github.com/onsi/gomega" "github.com/pkg/errors" @@ -222,19 +222,19 @@ func TestAzureMachinePool_ValidateCreate(t *testing.T) { }, { name: "azuremachinepool with Flexible orchestration mode", - amp: createMachinePoolWithOrchestrationMode(compute.OrchestrationModeFlexible), + amp: createMachinePoolWithOrchestrationMode(armcompute.OrchestrationModeFlexible), version: "v1.26.0", wantErr: false, }, { name: "azuremachinepool with Flexible orchestration mode and invalid Kubernetes version", - amp: createMachinePoolWithOrchestrationMode(compute.OrchestrationModeFlexible), + amp: createMachinePoolWithOrchestrationMode(armcompute.OrchestrationModeFlexible), version: "v1.25.6", wantErr: true, }, { name: "azuremachinepool with Flexible orchestration mode and invalid Kubernetes version, no owner", - amp: createMachinePoolWithOrchestrationMode(compute.OrchestrationModeFlexible), + amp: createMachinePoolWithOrchestrationMode(armcompute.OrchestrationModeFlexible), version: "v1.25.6", ownerNotFound: true, wantErr: true, @@ -631,7 +631,7 @@ func createMachinePoolWithStrategy(strategy AzureMachinePoolDeploymentStrategy) } } -func createMachinePoolWithOrchestrationMode(mode compute.OrchestrationMode) *AzureMachinePool { +func createMachinePoolWithOrchestrationMode(mode armcompute.OrchestrationMode) *AzureMachinePool { return &AzureMachinePool{ Spec: AzureMachinePoolSpec{ OrchestrationMode: infrav1.OrchestrationModeType(mode),