From f393cfacffd69ccd427b869011af76fc897f964b Mon Sep 17 00:00:00 2001 From: Matt Boersma Date: Wed, 11 Jan 2023 09:44:28 -0700 Subject: [PATCH] Use k8s utils/pointer instead of Azure autorest/to --- api/v1beta1/azurecluster_default_test.go | 64 +-- .../azureclustertemplate_default_test.go | 16 +- .../azureclustertemplate_validation_test.go | 16 +- api/v1beta1/azureimage_validation_test.go | 8 +- api/v1beta1/azuremachine_default_test.go | 42 +- api/v1beta1/azuremachine_validation_test.go | 96 ++-- .../azuremachinetemplate_webhook_test.go | 41 +- azure/converters/diagnostics.go | 8 +- azure/converters/diagnostics_test.go | 10 +- azure/converters/image.go | 24 +- azure/converters/image_test.go | 38 +- azure/converters/managedagentpool_test.go | 58 +-- azure/converters/publicips.go | 6 +- azure/converters/publicips_test.go | 10 +- azure/converters/resourcehealth_test.go | 10 +- azure/converters/rules.go | 8 +- azure/converters/spotinstances_test.go | 4 +- azure/converters/subnets.go | 7 +- azure/converters/subnets_test.go | 4 +- azure/converters/tags.go | 6 +- azure/converters/tags_test.go | 10 +- azure/converters/vm.go | 11 +- azure/converters/vm_test.go | 36 +- azure/converters/vmss.go | 38 +- azure/converters/vmss_test.go | 106 ++--- azure/pointers.go | 37 ++ azure/scope/cluster.go | 22 +- azure/scope/cluster_test.go | 18 +- azure/scope/machine.go | 14 +- azure/scope/machine_test.go | 47 +- azure/scope/machinepool.go | 11 +- azure/scope/machinepool_test.go | 24 +- azure/scope/machinepoolmachine_test.go | 6 +- azure/scope/managedcontrolplane.go | 6 +- azure/scope/managedcontrolplane_test.go | 12 +- azure/scope/managedmachinepool.go | 8 +- azure/scope/managedmachinepool_test.go | 34 +- azure/services/agentpools/agentpools.go | 4 +- azure/services/agentpools/agentpools_test.go | 22 +- azure/services/agentpools/spec.go | 14 +- azure/services/agentpools/spec_test.go | 268 ++++++------ .../availabilitysets/availabilitysets_test.go | 8 +- azure/services/availabilitysets/spec.go | 12 +- azure/services/availabilitysets/spec_test.go | 4 +- azure/services/bastionhosts/spec.go | 14 +- azure/services/groups/groups_test.go | 14 +- azure/services/groups/spec.go | 8 +- .../inboundnatrules/inboundnatrules_test.go | 11 +- azure/services/inboundnatrules/spec.go | 10 +- .../loadbalancers/loadbalancers_test.go | 8 +- azure/services/loadbalancers/spec.go | 54 +-- azure/services/loadbalancers/spec_test.go | 118 ++--- .../managedclusters/managedclusters.go | 4 +- azure/services/managedclusters/spec.go | 16 +- azure/services/managedclusters/spec_test.go | 56 +-- .../services/natgateways/natgateways_test.go | 4 +- azure/services/natgateways/spec.go | 10 +- azure/services/networkinterfaces/spec.go | 32 +- azure/services/networkinterfaces/spec_test.go | 230 +++++----- azure/services/privatedns/link_spec.go | 8 +- azure/services/privatedns/link_spec_test.go | 12 +- azure/services/privatedns/privatedns_test.go | 10 +- azure/services/privatedns/record_spec.go | 4 +- azure/services/privatedns/record_spec_test.go | 10 +- azure/services/privatedns/zone_spec.go | 4 +- azure/services/privatedns/zone_spec_test.go | 8 +- azure/services/publicips/publicips_test.go | 10 +- azure/services/publicips/spec.go | 14 +- azure/services/publicips/spec_test.go | 46 +- .../resourcehealth/resourcehealth_test.go | 6 +- azure/services/resourceskus/cache_test.go | 84 ++-- .../roleassignments/roleassignments_test.go | 4 +- azure/services/roleassignments/spec.go | 4 +- azure/services/routetables/spec.go | 6 +- azure/services/scalesets/client.go | 4 +- azure/services/scalesets/scalesets.go | 116 ++--- azure/services/scalesets/scalesets_test.go | 413 +++++++++--------- .../services/scalesets/vmssextension_spec.go | 10 +- .../scalesets/vmssextension_spec_test.go | 10 +- azure/services/scalesetvms/client.go | 4 +- .../services/scalesetvms/scalesetvms_test.go | 4 +- .../securitygroups/securitygroups_test.go | 60 +-- azure/services/securitygroups/spec.go | 16 +- azure/services/securitygroups/spec_test.go | 48 +- azure/services/subnets/spec.go | 14 +- azure/services/subnets/spec_test.go | 24 +- azure/services/subnets/subnets.go | 4 +- azure/services/subnets/subnets_test.go | 92 ++-- azure/services/tags/tags.go | 6 +- azure/services/tags/tags_test.go | 48 +- .../virtualmachineimages/cache_test.go | 4 +- .../virtualmachineimages/images_test.go | 70 +-- azure/services/virtualmachines/client.go | 4 +- azure/services/virtualmachines/spec.go | 40 +- azure/services/virtualmachines/spec_test.go | 270 ++++++------ .../virtualmachines/virtualmachines.go | 12 +- .../virtualmachines/virtualmachines_test.go | 18 +- azure/services/virtualnetworks/spec.go | 8 +- .../virtualnetworks/virtualnetworks.go | 8 +- .../virtualnetworks/virtualnetworks_test.go | 32 +- azure/services/vmextensions/spec.go | 10 +- azure/services/vmextensions/spec_test.go | 10 +- azure/services/vnetpeerings/spec.go | 6 +- azure/types_test.go | 4 +- .../v1beta1/azuremachinepool_default_test.go | 6 +- exp/api/v1beta1/azuremachinepool_test.go | 8 +- .../v1beta1/azuremachinepool_webhook_test.go | 18 +- .../azuremanagedcontrolplane_default.go | 34 +- .../azuremanagedcontrolplane_webhook.go | 26 +- .../azuremanagedcontrolplane_webhook_test.go | 201 +++++---- .../azuremanagedmachinepool_webhook.go | 12 +- .../azuremanagedmachinepool_webhook_test.go | 158 +++---- .../azuremachinepool_controller_unit_test.go | 4 +- exp/controllers/helpers_test.go | 4 +- go.mod | 2 +- internal/test/env/env.go | 4 +- test/e2e/aks_autoscaler.go | 10 +- test/e2e/aks_azure_cluster_autoscaler.go | 4 +- test/e2e/aks_machinepools.go | 8 +- test/e2e/aks_public_ip_prefix.go | 18 +- test/e2e/azure_clusterproxy.go | 4 +- test/e2e/azure_privatecluster.go | 3 +- test/e2e/kubernetes/pvc/pvc.go | 4 +- util/webhook/validator_test.go | 26 +- 124 files changed, 2012 insertions(+), 1978 deletions(-) create mode 100644 azure/pointers.go diff --git a/api/v1beta1/azurecluster_default_test.go b/api/v1beta1/azurecluster_default_test.go index 8306138f1bc8..a62e54b7471c 100644 --- a/api/v1beta1/azurecluster_default_test.go +++ b/api/v1beta1/azurecluster_default_test.go @@ -21,8 +21,8 @@ import ( "reflect" "testing" - "github.com/Azure/go-autorest/autorest/to" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" ) func TestResourceGroupDefault(t *testing.T) { @@ -139,7 +139,7 @@ func TestVnetDefaults(t *testing.T) { }, }, NodeOutboundLB: &LoadBalancerSpec{ - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32Ptr(1), }, }, }, @@ -629,10 +629,10 @@ func TestSubnetDefaults(t *testing.T) { Description: "allow port 50000", Protocol: "*", Priority: 2202, - SourcePorts: to.StringPtr("*"), - DestinationPorts: to.StringPtr("*"), - Source: to.StringPtr("*"), - Destination: to.StringPtr("*"), + SourcePorts: pointer.String("*"), + DestinationPorts: pointer.String("*"), + Source: pointer.String("*"), + Destination: pointer.String("*"), }, }, }, @@ -664,10 +664,10 @@ func TestSubnetDefaults(t *testing.T) { Description: "allow port 50000", Protocol: "*", Priority: 2202, - SourcePorts: to.StringPtr("*"), - DestinationPorts: to.StringPtr("*"), - Source: to.StringPtr("*"), - Destination: to.StringPtr("*"), + SourcePorts: pointer.String("*"), + DestinationPorts: pointer.String("*"), + Source: pointer.String("*"), + Destination: pointer.String("*"), Direction: SecurityRuleDirectionInbound, }, }, @@ -868,7 +868,7 @@ func TestAPIServerLBDefaults(t *testing.T) { LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -912,7 +912,7 @@ func TestAPIServerLBDefaults(t *testing.T) { LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Internal, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, Name: "cluster-test-internal-lb", }, @@ -960,7 +960,7 @@ func TestAPIServerLBDefaults(t *testing.T) { LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Internal, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, Name: "cluster-test-internal-lb", }, @@ -1143,11 +1143,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) { BackendPool: BackendPool{ Name: "cluster-test-outboundBackendPool", }, - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32(1), LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -1324,11 +1324,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) { BackendPool: BackendPool{ Name: "cluster-test-outboundBackendPool", }, - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32(1), LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -1433,14 +1433,14 @@ func TestNodeOutboundLBDefaults(t *testing.T) { Name: "pip-cluster-test-node-outbound", }, }}, - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32(1), BackendPool: BackendPool{ Name: "cluster-test-outboundBackendPool", }, LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, Name: "cluster-test", }, @@ -1616,12 +1616,12 @@ func TestNodeOutboundLBDefaults(t *testing.T) { NetworkSpec: NetworkSpec{ APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Public}}, NodeOutboundLB: &LoadBalancerSpec{ - FrontendIPsCount: to.Int32Ptr(2), + FrontendIPsCount: pointer.Int32(2), BackendPool: BackendPool{ Name: "custom-backend-pool", }, LoadBalancerClassSpec: LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), }, }, }, @@ -1656,11 +1656,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) { BackendPool: BackendPool{ Name: "custom-backend-pool", }, - FrontendIPsCount: to.Int32Ptr(2), // we expect the original value to be respected here + FrontendIPsCount: pointer.Int32(2), // we expect the original value to be respected here LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(15), // we expect the original value to be respected here + IdleTimeoutInMinutes: pointer.Int32(15), // we expect the original value to be respected here }, Name: "cluster-test", }, @@ -1750,11 +1750,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) { BackendPool: BackendPool{ Name: "user-defined-name-outboundBackendPool", }, - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32(1), LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, ControlPlaneOutboundLB: &LoadBalancerSpec{ @@ -1850,9 +1850,9 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) { NetworkSpec: NetworkSpec{ APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Internal}}, ControlPlaneOutboundLB: &LoadBalancerSpec{ - FrontendIPsCount: to.Int32Ptr(2), + FrontendIPsCount: pointer.Int32(2), LoadBalancerClassSpec: LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), }, }, }, @@ -1888,11 +1888,11 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) { }, }, }, - FrontendIPsCount: to.Int32Ptr(2), + FrontendIPsCount: pointer.Int32(2), LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), }, }, }, @@ -1913,7 +1913,7 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) { Name: "custom-outbound-lb", }, LoadBalancerClassSpec: LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), }, }, }, @@ -1943,11 +1943,11 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) { }, }, }, - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32(1), LoadBalancerClassSpec: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), }, }, }, diff --git a/api/v1beta1/azureclustertemplate_default_test.go b/api/v1beta1/azureclustertemplate_default_test.go index 5ee613a3befe..9390e9d0e070 100644 --- a/api/v1beta1/azureclustertemplate_default_test.go +++ b/api/v1beta1/azureclustertemplate_default_test.go @@ -21,8 +21,8 @@ import ( "reflect" "testing" - "github.com/Azure/go-autorest/autorest/to" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" ) func TestVnetTemplateDefaults(t *testing.T) { @@ -472,7 +472,7 @@ func TestAPIServerLBClassDefaults(t *testing.T) { APIServerLB: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -509,7 +509,7 @@ func TestAPIServerLBClassDefaults(t *testing.T) { APIServerLB: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Internal, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -591,7 +591,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) { NodeOutboundLB: &LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -728,7 +728,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) { NodeOutboundLB: &LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -798,7 +798,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) { NodeOutboundLB: &LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -926,7 +926,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) { NetworkSpec: NetworkTemplateSpec{ APIServerLB: LoadBalancerClassSpec{Type: Internal}, NodeOutboundLB: &LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), }, }, }, @@ -943,7 +943,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) { NetworkSpec: NetworkTemplateSpec{ APIServerLB: LoadBalancerClassSpec{Type: Internal}, NodeOutboundLB: &LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(15), + IdleTimeoutInMinutes: pointer.Int32(15), SKU: SKUStandard, Type: Public, }, diff --git a/api/v1beta1/azureclustertemplate_validation_test.go b/api/v1beta1/azureclustertemplate_validation_test.go index 09556e1a377c..0c48b2385a83 100644 --- a/api/v1beta1/azureclustertemplate_validation_test.go +++ b/api/v1beta1/azureclustertemplate_validation_test.go @@ -19,10 +19,10 @@ package v1beta1 import ( "testing" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/pointer" ) func TestValdateVnetCIDRs(t *testing.T) { @@ -446,7 +446,7 @@ func TestValidateAPIServerLBTemplate(t *testing.T) { APIServerLB: LoadBalancerClassSpec{ SKU: SKUStandard, Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -468,7 +468,7 @@ func TestValidateAPIServerLBTemplate(t *testing.T) { APIServerLB: LoadBalancerClassSpec{ SKU: SKU("wrong"), Type: Public, - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -490,7 +490,7 @@ func TestValidateAPIServerLBTemplate(t *testing.T) { APIServerLB: LoadBalancerClassSpec{ SKU: SKUStandard, Type: LBType("wrong"), - IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes), + IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes), }, }, }, @@ -580,7 +580,7 @@ func TestControlPlaneOutboundLBTemplate(t *testing.T) { Type: Internal, }, ControlPlaneOutboundLB: &LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(2), + IdleTimeoutInMinutes: pointer.Int32(2), }, }, }, @@ -603,7 +603,7 @@ func TestControlPlaneOutboundLBTemplate(t *testing.T) { Type: Internal, }, ControlPlaneOutboundLB: &LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(60), + IdleTimeoutInMinutes: pointer.Int32(60), }, }, }, @@ -710,7 +710,7 @@ func TestNodeOutboundLBTemplate(t *testing.T) { Type: Public, }, NodeOutboundLB: &LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(2), + IdleTimeoutInMinutes: pointer.Int32(2), }, }, }, @@ -733,7 +733,7 @@ func TestNodeOutboundLBTemplate(t *testing.T) { Type: Public, }, NodeOutboundLB: &LoadBalancerClassSpec{ - IdleTimeoutInMinutes: to.Int32Ptr(60), + IdleTimeoutInMinutes: pointer.Int32(60), }, }, }, diff --git a/api/v1beta1/azureimage_validation_test.go b/api/v1beta1/azureimage_validation_test.go index b22bbff2d0e7..0f77737a3ae1 100644 --- a/api/v1beta1/azureimage_validation_test.go +++ b/api/v1beta1/azureimage_validation_test.go @@ -19,9 +19,9 @@ package v1beta1 import ( "testing" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/pointer" ) func TestImageOptional(t *testing.T) { @@ -74,15 +74,15 @@ func TestComputeImageGalleryValid(t *testing.T) { }, "AzureComputeGalleryImage - fully specified private image": { expectedErrors: 0, - image: createTestComputeImage(to.StringPtr("SUB1234"), to.StringPtr("RG1234")), + image: createTestComputeImage(pointer.String("SUB1234"), pointer.String("RG1234")), }, "AzureComputeGalleryImage - private image with missing subscription": { expectedErrors: 1, - image: createTestComputeImage(nil, to.StringPtr("RG1234")), + image: createTestComputeImage(nil, pointer.String("RG1234")), }, "AzureComputeGalleryImage - private image with missing resource group": { expectedErrors: 1, - image: createTestComputeImage(to.StringPtr("SUB1234"), nil), + image: createTestComputeImage(pointer.String("SUB1234"), nil), }, } diff --git a/api/v1beta1/azuremachine_default_test.go b/api/v1beta1/azuremachine_default_test.go index 0159de02fbb3..b0a860249a0b 100644 --- a/api/v1beta1/azuremachine_default_test.go +++ b/api/v1beta1/azuremachine_default_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/uuid" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" ) func TestAzureMachineSpec_SetDefaultSSHPublicKey(t *testing.T) { @@ -107,13 +107,13 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: "ReadWrite", }, { NameSuffix: "testdisk2", DiskSizeGB: 30, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), CachingType: "ReadWrite", }, }, @@ -124,13 +124,13 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(5), + Lun: pointer.Int32(5), CachingType: "ReadWrite", }, { NameSuffix: "testdisk2", DiskSizeGB: 30, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), CachingType: "ReadWrite", }, }, @@ -138,13 +138,13 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(5), + Lun: pointer.Int32(5), CachingType: "ReadWrite", }, { NameSuffix: "testdisk2", DiskSizeGB: 30, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), CachingType: "ReadWrite", }, }, @@ -155,7 +155,7 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: "ReadWrite", }, { @@ -166,7 +166,7 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk3", DiskSizeGB: 30, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), CachingType: "ReadWrite", }, { @@ -179,25 +179,25 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: "ReadWrite", }, { NameSuffix: "testdisk2", DiskSizeGB: 30, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), CachingType: "ReadWrite", }, { NameSuffix: "testdisk3", DiskSizeGB: 30, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), CachingType: "ReadWrite", }, { NameSuffix: "testdisk4", DiskSizeGB: 30, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), CachingType: "ReadWrite", }, }, @@ -208,12 +208,12 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), }, { NameSuffix: "testdisk2", DiskSizeGB: 30, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), }, { NameSuffix: "testdisk3", @@ -221,26 +221,26 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), }, }, output: []DataDisk{ { NameSuffix: "testdisk1", DiskSizeGB: 30, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: "ReadWrite", }, { NameSuffix: "testdisk2", DiskSizeGB: 30, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), CachingType: "ReadWrite", }, { NameSuffix: "testdisk3", DiskSizeGB: 30, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -318,7 +318,7 @@ func TestAzureMachineSpec_SetNetworkInterfacesDefaults(t *testing.T) { machine: &AzureMachine{ Spec: AzureMachineSpec{ SubnetName: "test-subnet", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), }, }, want: &AzureMachine{ @@ -329,7 +329,7 @@ func TestAzureMachineSpec_SetNetworkInterfacesDefaults(t *testing.T) { { SubnetName: "test-subnet", PrivateIPConfigs: 1, - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), }, }, }, diff --git a/api/v1beta1/azuremachine_validation_test.go b/api/v1beta1/azuremachine_validation_test.go index 931bd668a344..5e99ae654dc9 100644 --- a/api/v1beta1/azuremachine_validation_test.go +++ b/api/v1beta1/azuremachine_validation_test.go @@ -24,11 +24,11 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/uuid" . "github.com/onsi/gomega" "golang.org/x/crypto/ssh" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/pointer" ) func TestAzureMachine_ValidateSSHKey(t *testing.T) { @@ -101,7 +101,7 @@ func TestAzureMachine_ValidateOSDisk(t *testing.T) { name: "valid ephemeral os disk spec", wantErr: false, osDisk: OSDisk{ - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), CachingType: "None", OSType: "blah", DiffDiskSettings: &DiffDiskSettings{ @@ -116,7 +116,7 @@ func TestAzureMachine_ValidateOSDisk(t *testing.T) { name: "byoc encryption with ephemeral os disk spec", wantErr: true, osDisk: OSDisk{ - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), CachingType: "None", OSType: "blah", DiffDiskSettings: &DiffDiskSettings{ @@ -152,42 +152,42 @@ func generateNegativeTestCases() []osDiskTestInput { invalidDiskSpecs := []OSDisk{ {}, { - DiskSizeGB: to.Int32Ptr(0), + DiskSizeGB: pointer.Int32(0), OSType: "blah", }, { - DiskSizeGB: to.Int32Ptr(-10), + DiskSizeGB: pointer.Int32(-10), OSType: "blah", }, { - DiskSizeGB: to.Int32Ptr(2050), + DiskSizeGB: pointer.Int32(2050), OSType: "blah", }, { - DiskSizeGB: to.Int32Ptr(20), + DiskSizeGB: pointer.Int32(20), OSType: "", }, { - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "blah", ManagedDisk: &ManagedDiskParameters{}, }, { - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "blah", ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "", }, }, { - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "blah", ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "invalid_type", }, }, { - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "blah", ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", @@ -211,7 +211,7 @@ func generateNegativeTestCases() []osDiskTestInput { func generateValidOSDisk() OSDisk { return OSDisk{ - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "Linux", ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", @@ -250,13 +250,13 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, { NameSuffix: "my_other_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -268,13 +268,13 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, { NameSuffix: "disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -286,13 +286,13 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, { NameSuffix: "my_other_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -304,7 +304,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 0, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -316,7 +316,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "", DiskSizeGB: 0, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -328,7 +328,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: "invalidCacheType", }, }, @@ -340,7 +340,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -355,7 +355,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, { @@ -364,7 +364,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -379,7 +379,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "invalid storage account", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -394,7 +394,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS), }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.CachingTypesNone), }, }, @@ -409,7 +409,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS), }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.CachingTypesReadWrite), }, }, @@ -424,7 +424,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS), }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.CachingTypesReadOnly), }, }, @@ -526,7 +526,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, @@ -535,7 +535,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { { NameSuffix: "my_other_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, @@ -546,7 +546,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { { NameSuffix: "my_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, @@ -555,7 +555,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { { NameSuffix: "my_other_disk", DiskSizeGB: 64, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, @@ -573,7 +573,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -584,7 +584,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -599,7 +599,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), }, }, oldDisks: []DataDisk{ @@ -620,7 +620,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -631,7 +631,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, { @@ -640,7 +640,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -655,7 +655,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, { @@ -664,7 +664,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -675,7 +675,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) { ManagedDisk: &ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), CachingType: string(compute.PossibleCachingTypesValues()[0]), }, }, @@ -708,7 +708,7 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) { { name: "valid config with deprecated network fields", subnetName: "subnet1", - acceleratedNetworking: to.BoolPtr(true), + acceleratedNetworking: pointer.Bool(true), networkInterfaces: nil, wantErr: false, }, @@ -718,7 +718,7 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) { acceleratedNetworking: nil, networkInterfaces: []NetworkInterface{{ SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }}, wantErr: false, @@ -730,12 +730,12 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) { networkInterfaces: []NetworkInterface{ { SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }, { SubnetName: "subnet2", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 30, }, }, @@ -755,10 +755,10 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) { { name: "invalid config using both deprecated acceleratedNetworking and networkInterfaces", subnetName: "", - acceleratedNetworking: to.BoolPtr(true), + acceleratedNetworking: pointer.Bool(true), networkInterfaces: []NetworkInterface{{ SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }}, wantErr: true, @@ -769,7 +769,7 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) { acceleratedNetworking: nil, networkInterfaces: []NetworkInterface{{ SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 0, }}, wantErr: true, diff --git a/api/v1beta1/azuremachinetemplate_webhook_test.go b/api/v1beta1/azuremachinetemplate_webhook_test.go index 2f2f3d5b5d5a..838fbed0d0ed 100644 --- a/api/v1beta1/azuremachinetemplate_webhook_test.go +++ b/api/v1beta1/azuremachinetemplate_webhook_test.go @@ -21,7 +21,6 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" admissionv1 "k8s.io/api/admission/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -175,7 +174,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), }, DataDisks: []DataDisk{}, SSHPublicKey: "", @@ -191,7 +190,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), }, DataDisks: []DataDisk{}, SSHPublicKey: "fake ssh key", @@ -211,7 +210,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), }, DataDisks: []DataDisk{}, SSHPublicKey: "fake ssh key", @@ -230,7 +229,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), }, DataDisks: []DataDisk{}, SSHPublicKey: "fake ssh key", @@ -253,7 +252,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "", }, DataDisks: []DataDisk{}, @@ -273,7 +272,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -300,7 +299,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -320,7 +319,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -344,13 +343,13 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, SSHPublicKey: "fake ssh key", SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), }, }, }, @@ -363,7 +362,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -373,7 +372,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { NetworkInterfaces: []NetworkInterface{ { SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }, }, @@ -393,13 +392,13 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, SSHPublicKey: "fake ssh key", SubnetName: "", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), NetworkInterfaces: []NetworkInterface{}, }, }, @@ -413,7 +412,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -423,7 +422,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { NetworkInterfaces: []NetworkInterface{ { SubnetName: "", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }, }, @@ -443,7 +442,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -451,7 +450,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { NetworkInterfaces: []NetworkInterface{ { SubnetName: "subnet1", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }, }, @@ -467,7 +466,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { FailureDomain: &failureDomain, OSDisk: OSDisk{ OSType: "type", - DiskSizeGB: to.Int32Ptr(11), + DiskSizeGB: pointer.Int32(11), CachingType: "None", }, DataDisks: []DataDisk{}, @@ -475,7 +474,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) { NetworkInterfaces: []NetworkInterface{ { SubnetName: "subnet2", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), PrivateIPConfigs: 1, }, }, diff --git a/azure/converters/diagnostics.go b/azure/converters/diagnostics.go index 04ee6793b0e2..4a9eedb0d4d7 100644 --- a/azure/converters/diagnostics.go +++ b/azure/converters/diagnostics.go @@ -18,7 +18,7 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -29,19 +29,19 @@ func GetDiagnosticsProfile(diagnostics *infrav1.Diagnostics) *compute.Diagnostic case infrav1.DisabledDiagnosticsStorage: return &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(false), + Enabled: pointer.Bool(false), }, } case infrav1.ManagedDiagnosticsStorage: return &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), + Enabled: pointer.Bool(true), }, } case infrav1.UserManagedDiagnosticsStorage: return &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), + Enabled: pointer.Bool(true), StorageURI: &diagnostics.Boot.UserManaged.StorageAccountURI, }, } diff --git a/azure/converters/diagnostics_test.go b/azure/converters/diagnostics_test.go index d2a1f28237b0..509aae42f489 100644 --- a/azure/converters/diagnostics_test.go +++ b/azure/converters/diagnostics_test.go @@ -20,8 +20,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -40,7 +40,7 @@ func TestGetDiagnosticsProfile(t *testing.T) { }, want: &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), + Enabled: pointer.Bool(true), }, }, }, @@ -56,8 +56,8 @@ func TestGetDiagnosticsProfile(t *testing.T) { }, want: &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), - StorageURI: to.StringPtr("https://fake"), + Enabled: pointer.Bool(true), + StorageURI: pointer.String("https://fake"), }, }, }, @@ -70,7 +70,7 @@ func TestGetDiagnosticsProfile(t *testing.T) { }, want: &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(false), + Enabled: pointer.Bool(false), }, }, }, diff --git a/azure/converters/image.go b/azure/converters/image.go index 767ede42f555..3d228fa6d136 100644 --- a/azure/converters/image.go +++ b/azure/converters/image.go @@ -20,8 +20,8 @@ import ( "fmt" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -57,7 +57,7 @@ func computeImageToSDK(image *infrav1.Image) (*compute.ImageReference, error) { idTemplate := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/galleries/%s/images/%s/versions/%s" if image.SharedGallery != nil { return &compute.ImageReference{ - ID: to.StringPtr(fmt.Sprintf(idTemplate, + ID: pointer.String(fmt.Sprintf(idTemplate, image.SharedGallery.SubscriptionID, image.SharedGallery.ResourceGroup, image.SharedGallery.Gallery, @@ -71,9 +71,9 @@ func computeImageToSDK(image *infrav1.Image) (*compute.ImageReference, error) { // If they are not, we assume use of community gallery. if image.ComputeGallery.ResourceGroup != nil && image.ComputeGallery.SubscriptionID != nil { return &compute.ImageReference{ - ID: to.StringPtr(fmt.Sprintf(idTemplate, - to.String(image.ComputeGallery.SubscriptionID), - to.String(image.ComputeGallery.ResourceGroup), + ID: pointer.String(fmt.Sprintf(idTemplate, + pointer.StringDeref(image.ComputeGallery.SubscriptionID, ""), + pointer.StringDeref(image.ComputeGallery.ResourceGroup, ""), image.ComputeGallery.Gallery, image.ComputeGallery.Name, image.ComputeGallery.Version, @@ -82,7 +82,7 @@ func computeImageToSDK(image *infrav1.Image) (*compute.ImageReference, error) { } return &compute.ImageReference{ - CommunityGalleryImageID: to.StringPtr(fmt.Sprintf("/CommunityGalleries/%s/Images/%s/Versions/%s", + CommunityGalleryImageID: pointer.String(fmt.Sprintf("/CommunityGalleries/%s/Images/%s/Versions/%s", image.ComputeGallery.Gallery, image.ComputeGallery.Name, image.ComputeGallery.Version)), @@ -109,18 +109,18 @@ func ImageToPlan(image *infrav1.Image) *compute.Plan { // Plan is needed for third party Marketplace images. if image.Marketplace != nil && image.Marketplace.ThirdPartyImage { return &compute.Plan{ - Publisher: to.StringPtr(image.Marketplace.Publisher), - Name: to.StringPtr(image.Marketplace.SKU), - Product: to.StringPtr(image.Marketplace.Offer), + Publisher: pointer.String(image.Marketplace.Publisher), + Name: pointer.String(image.Marketplace.SKU), + Product: pointer.String(image.Marketplace.Offer), } } // Plan is needed when using a Azure Compute Gallery image with Plan details. if image.ComputeGallery != nil && image.ComputeGallery.Plan != nil { return &compute.Plan{ - Publisher: to.StringPtr(image.ComputeGallery.Plan.Publisher), - Name: to.StringPtr(image.ComputeGallery.Plan.SKU), - Product: to.StringPtr(image.ComputeGallery.Plan.Offer), + Publisher: pointer.String(image.ComputeGallery.Plan.Publisher), + Name: pointer.String(image.ComputeGallery.Plan.SKU), + Product: pointer.String(image.ComputeGallery.Plan.Offer), } } diff --git a/azure/converters/image_test.go b/azure/converters/image_test.go index c68e3faa80ac..2192960f4f01 100644 --- a/azure/converters/image_test.go +++ b/azure/converters/image_test.go @@ -20,8 +20,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -44,9 +44,9 @@ func Test_ImageToPlan(t *testing.T) { }, expect: func(g *GomegaWithT, result *compute.Plan) { g.Expect(result).To(Equal(&compute.Plan{ - Name: to.StringPtr("my-sku"), - Publisher: to.StringPtr("my-publisher"), - Product: to.StringPtr("my-offer"), + Name: pointer.String("my-sku"), + Publisher: pointer.String("my-publisher"), + Product: pointer.String("my-offer"), })) }, }, @@ -59,16 +59,16 @@ func Test_ImageToPlan(t *testing.T) { Gallery: "fake-gallery-name", Name: "fake-image-name", Version: "v1.0.0", - Publisher: to.StringPtr("my-publisher"), - Offer: to.StringPtr("my-offer"), - SKU: to.StringPtr("my-sku"), + Publisher: pointer.String("my-publisher"), + Offer: pointer.String("my-offer"), + SKU: pointer.String("my-sku"), }, }, expect: func(g *GomegaWithT, result *compute.Plan) { g.Expect(result).To(Equal(&compute.Plan{ - Name: to.StringPtr("my-sku"), - Publisher: to.StringPtr("my-publisher"), - Product: to.StringPtr("my-offer"), + Name: pointer.String("my-sku"), + Publisher: pointer.String("my-publisher"), + Product: pointer.String("my-offer"), })) }, }, @@ -119,16 +119,16 @@ func Test_ImageToPlan(t *testing.T) { }, expect: func(g *GomegaWithT, result *compute.Plan) { g.Expect(result).To(Equal(&compute.Plan{ - Name: to.StringPtr("my-sku"), - Publisher: to.StringPtr("my-publisher"), - Product: to.StringPtr("my-offer"), + Name: pointer.String("my-sku"), + Publisher: pointer.String("my-publisher"), + Product: pointer.String("my-offer"), })) }, }, { name: "Should return nil for an image ID", image: &infrav1.Image{ - ID: to.StringPtr("fake/image/id"), + ID: pointer.String("fake/image/id"), }, expect: func(g *GomegaWithT, result *compute.Plan) { g.Expect(result).To(BeNil()) @@ -157,8 +157,8 @@ func Test_ComputeImageToSDK(t *testing.T) { name: "Should return parsed compute gallery image id", image: &infrav1.Image{ ComputeGallery: &infrav1.AzureComputeGalleryImage{ - ResourceGroup: to.StringPtr("my-resourcegroup"), - SubscriptionID: to.StringPtr("my-subscription-id"), + ResourceGroup: pointer.String("my-resourcegroup"), + SubscriptionID: pointer.String("my-subscription-id"), Gallery: "my-gallery", Name: "my-image", Version: "my-version", @@ -167,7 +167,7 @@ func Test_ComputeImageToSDK(t *testing.T) { expect: func(g *GomegaWithT, result *compute.ImageReference, err error) { g.Expect(err).Should(BeNil()) g.Expect(result).To(Equal(&compute.ImageReference{ - ID: to.StringPtr("/subscriptions/my-subscription-id/resourceGroups/my-resourcegroup/providers/Microsoft.Compute/galleries/my-gallery/images/my-image/versions/my-version"), + ID: pointer.String("/subscriptions/my-subscription-id/resourceGroups/my-resourcegroup/providers/Microsoft.Compute/galleries/my-gallery/images/my-image/versions/my-version"), })) }, }, @@ -185,7 +185,7 @@ func Test_ComputeImageToSDK(t *testing.T) { expect: func(g *GomegaWithT, result *compute.ImageReference, err error) { g.Expect(err).Should(BeNil()) g.Expect(result).To(Equal(&compute.ImageReference{ - ID: to.StringPtr("/subscriptions/my-subscription-id/resourceGroups/my-resourcegroup/providers/Microsoft.Compute/galleries/my-gallery/images/my-image/versions/my-version"), + ID: pointer.String("/subscriptions/my-subscription-id/resourceGroups/my-resourcegroup/providers/Microsoft.Compute/galleries/my-gallery/images/my-image/versions/my-version"), })) }, }, @@ -201,7 +201,7 @@ func Test_ComputeImageToSDK(t *testing.T) { expect: func(g *GomegaWithT, result *compute.ImageReference, err error) { g.Expect(err).Should(BeNil()) g.Expect(result).To(Equal(&compute.ImageReference{ - CommunityGalleryImageID: to.StringPtr("/CommunityGalleries/my-gallery/Images/my-image/Versions/my-version"), + CommunityGalleryImageID: pointer.String("/CommunityGalleries/my-gallery/Images/my-image/Versions/my-version"), })) }, }, diff --git a/azure/converters/managedagentpool_test.go b/azure/converters/managedagentpool_test.go index 6122e02699d9..c8627ba1a6ab 100644 --- a/azure/converters/managedagentpool_test.go +++ b/azure/converters/managedagentpool_test.go @@ -20,8 +20,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -34,55 +34,55 @@ func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) { { name: "Should set all values correctly", pool: containerservice.AgentPool{ - Name: to.StringPtr("agentpool1"), + Name: pointer.String("agentpool1"), ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ - VMSize: to.StringPtr("Standard_D2s_v3"), + VMSize: pointer.String("Standard_D2s_v3"), OsType: azure.LinuxOS, - OsDiskSizeGB: to.Int32Ptr(100), - Count: to.Int32Ptr(2), + OsDiskSizeGB: pointer.Int32(100), + Count: pointer.Int32(2), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - OrchestratorVersion: to.StringPtr("1.22.6"), - VnetSubnetID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123"), + OrchestratorVersion: pointer.String("1.22.6"), + VnetSubnetID: pointer.String("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123"), Mode: containerservice.AgentPoolModeUser, - EnableAutoScaling: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MinCount: to.Int32Ptr(2), - NodeTaints: to.StringSlicePtr([]string{"key1=value1:NoSchedule"}), - AvailabilityZones: to.StringSlicePtr([]string{"zone1"}), - MaxPods: to.Int32Ptr(60), + EnableAutoScaling: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MinCount: pointer.Int32(2), + NodeTaints: &[]string{"key1=value1:NoSchedule"}, + AvailabilityZones: &[]string{"zone1"}, + MaxPods: pointer.Int32(60), OsDiskType: containerservice.OSDiskTypeManaged, NodeLabels: map[string]*string{ - "custom": to.StringPtr("default"), + "custom": pointer.String("default"), }, Tags: map[string]*string{ - "custom": to.StringPtr("default"), + "custom": pointer.String("default"), }, }, }, expect: func(g *GomegaWithT, result containerservice.ManagedClusterAgentPoolProfile) { g.Expect(result).To(Equal(containerservice.ManagedClusterAgentPoolProfile{ - Name: to.StringPtr("agentpool1"), - VMSize: to.StringPtr("Standard_D2s_v3"), + Name: pointer.String("agentpool1"), + VMSize: pointer.String("Standard_D2s_v3"), OsType: azure.LinuxOS, - OsDiskSizeGB: to.Int32Ptr(100), - Count: to.Int32Ptr(2), + OsDiskSizeGB: pointer.Int32(100), + Count: pointer.Int32(2), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - OrchestratorVersion: to.StringPtr("1.22.6"), - VnetSubnetID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123"), + OrchestratorVersion: pointer.String("1.22.6"), + VnetSubnetID: pointer.String("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123"), Mode: containerservice.AgentPoolModeUser, - EnableAutoScaling: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MinCount: to.Int32Ptr(2), - NodeTaints: to.StringSlicePtr([]string{"key1=value1:NoSchedule"}), - AvailabilityZones: to.StringSlicePtr([]string{"zone1"}), - MaxPods: to.Int32Ptr(60), + EnableAutoScaling: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MinCount: pointer.Int32(2), + NodeTaints: &[]string{"key1=value1:NoSchedule"}, + AvailabilityZones: &[]string{"zone1"}, + MaxPods: pointer.Int32(60), OsDiskType: containerservice.OSDiskTypeManaged, NodeLabels: map[string]*string{ - "custom": to.StringPtr("default"), + "custom": pointer.String("default"), }, Tags: map[string]*string{ - "custom": to.StringPtr("default"), + "custom": pointer.String("default"), }, })) }, diff --git a/azure/converters/publicips.go b/azure/converters/publicips.go index 2862e6227e1a..b1cf4ab3c778 100644 --- a/azure/converters/publicips.go +++ b/azure/converters/publicips.go @@ -18,7 +18,7 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -30,8 +30,8 @@ func IPTagsToSDK(ipTags []infrav1.IPTag) *[]network.IPTag { skdIPTags := make([]network.IPTag, len(ipTags)) for i, ipTag := range ipTags { skdIPTags[i] = network.IPTag{ - IPTagType: to.StringPtr(ipTag.Type), - Tag: to.StringPtr(ipTag.Tag), + IPTagType: pointer.String(ipTag.Type), + Tag: pointer.String(ipTag.Tag), } } return &skdIPTags diff --git a/azure/converters/publicips_test.go b/azure/converters/publicips_test.go index 19b21e2be75d..effdb86e11b5 100644 --- a/azure/converters/publicips_test.go +++ b/azure/converters/publicips_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -50,12 +50,12 @@ func TestIPTagsToSDK(t *testing.T) { }, want: &[]network.IPTag{ { - IPTagType: to.StringPtr("tag"), - Tag: to.StringPtr("value"), + IPTagType: pointer.String("tag"), + Tag: pointer.String("value"), }, { - IPTagType: to.StringPtr("internal"), - Tag: to.StringPtr("foo"), + IPTagType: pointer.String("internal"), + Tag: pointer.String("foo"), }, }, }, diff --git a/azure/converters/resourcehealth_test.go b/azure/converters/resourcehealth_test.go index 37d58a7e08b9..4e7e2c9bc16b 100644 --- a/azure/converters/resourcehealth_test.go +++ b/azure/converters/resourcehealth_test.go @@ -20,9 +20,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/resourcehealth/mgmt/2020-05-01/resourcehealth" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/utils/pointer" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) @@ -55,8 +55,8 @@ func TestAzureAvailabilityStatusToCondition(t *testing.T) { avail: resourcehealth.AvailabilityStatus{ Properties: &resourcehealth.AvailabilityStatusProperties{ AvailabilityState: resourcehealth.AvailabilityStateValuesUnavailable, - ReasonType: to.StringPtr("this Is a reason "), - Summary: to.StringPtr("The Summary"), + ReasonType: pointer.String("this Is a reason "), + Summary: pointer.String("The Summary"), }, }, expected: &clusterv1.Condition{ @@ -71,8 +71,8 @@ func TestAzureAvailabilityStatusToCondition(t *testing.T) { avail: resourcehealth.AvailabilityStatus{ Properties: &resourcehealth.AvailabilityStatusProperties{ AvailabilityState: resourcehealth.AvailabilityStateValuesDegraded, - ReasonType: to.StringPtr("TheReason"), - Summary: to.StringPtr("The Summary"), + ReasonType: pointer.String("TheReason"), + Summary: pointer.String("The Summary"), }, }, expected: &clusterv1.Condition{ diff --git a/azure/converters/rules.go b/azure/converters/rules.go index 6986ca777d5f..50b2af2602d5 100644 --- a/azure/converters/rules.go +++ b/azure/converters/rules.go @@ -18,22 +18,22 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) // SecurityRuleToSDK converts a CAPZ security rule to an Azure network security rule. func SecurityRuleToSDK(rule infrav1.SecurityRule) network.SecurityRule { secRule := network.SecurityRule{ - Name: to.StringPtr(rule.Name), + Name: pointer.String(rule.Name), SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{ - Description: to.StringPtr(rule.Description), + Description: pointer.String(rule.Description), SourceAddressPrefix: rule.Source, SourcePortRange: rule.SourcePorts, DestinationAddressPrefix: rule.Destination, DestinationPortRange: rule.DestinationPorts, Access: network.SecurityRuleAccessAllow, - Priority: to.Int32Ptr(rule.Priority), + Priority: pointer.Int32(rule.Priority), }, } diff --git a/azure/converters/spotinstances_test.go b/azure/converters/spotinstances_test.go index 818543b8c3d4..230e2523701c 100644 --- a/azure/converters/spotinstances_test.go +++ b/azure/converters/spotinstances_test.go @@ -21,9 +21,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -75,7 +75,7 @@ func TestGetSpotVMOptions(t *testing.T) { vmPriorityTypes: compute.VirtualMachinePriorityTypesSpot, vmEvictionPolicyTypes: "", billingProfile: &compute.BillingProfile{ - MaxPrice: to.Float64Ptr(1000), + MaxPrice: pointer.Float64(1000), }, }, }, diff --git a/azure/converters/subnets.go b/azure/converters/subnets.go index e61d84fbbc97..345cde875eb6 100644 --- a/azure/converters/subnets.go +++ b/azure/converters/subnets.go @@ -18,16 +18,17 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" + "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{to.String(subnet.SubnetPropertiesFormat.AddressPrefix)} + addresses = []string{pointer.StringDeref(subnet.SubnetPropertiesFormat.AddressPrefix, "")} } else if subnet.SubnetPropertiesFormat != nil && subnet.SubnetPropertiesFormat.AddressPrefixes != nil { - addresses = to.StringSlice(subnet.SubnetPropertiesFormat.AddressPrefixes) + addresses = azure.StringSlice(subnet.SubnetPropertiesFormat.AddressPrefixes) } return addresses } diff --git a/azure/converters/subnets_test.go b/azure/converters/subnets_test.go index 832c7c8ed33c..584158b8472e 100644 --- a/azure/converters/subnets_test.go +++ b/azure/converters/subnets_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" ) func TestGetSubnetAddresses(t *testing.T) { @@ -39,7 +39,7 @@ func TestGetSubnetAddresses(t *testing.T) { name: "subnet with single address prefix", subnet: network.Subnet{ SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr("test-address-prefix"), + AddressPrefix: pointer.String("test-address-prefix"), }, }, want: []string{"test-address-prefix"}, diff --git a/azure/converters/tags.go b/azure/converters/tags.go index 5e4e0f1ff6bb..c082802aed2a 100644 --- a/azure/converters/tags.go +++ b/azure/converters/tags.go @@ -17,7 +17,7 @@ limitations under the License. package converters import ( - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -30,7 +30,7 @@ func MapToTags(src map[string]*string) infrav1.Tags { tags := make(infrav1.Tags, len(src)) for k, v := range src { - tags[k] = to.String(v) + tags[k] = pointer.StringDeref(v, "") } return tags @@ -45,7 +45,7 @@ func TagsToMap(src infrav1.Tags) map[string]*string { tags := make(map[string]*string, len(src)) for k, v := range src { - tags[k] = to.StringPtr(v) + tags[k] = pointer.String(v) } return tags diff --git a/azure/converters/tags_test.go b/azure/converters/tags_test.go index d193a951a7e1..4f952973f84c 100644 --- a/azure/converters/tags_test.go +++ b/azure/converters/tags_test.go @@ -19,8 +19,8 @@ package converters import ( "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -39,7 +39,7 @@ func Test_TagsToMap(t *testing.T) { }, { tags: infrav1.Tags{"env": "prod"}, - expect: map[string]*string{"env": to.StringPtr("prod")}, + expect: map[string]*string{"env": pointer.String("prod")}, }, } @@ -68,7 +68,7 @@ func Test_MapToTags(t *testing.T) { expect: infrav1.Tags{}, }, { - tags: map[string]*string{"env": to.StringPtr("prod")}, + tags: map[string]*string{"env": pointer.String("prod")}, expect: infrav1.Tags{"env": "prod"}, }, } @@ -134,8 +134,8 @@ func Test_MapToTagsMapRoundTrip(t *testing.T) { expect: map[string]*string{}, }, { - tags: map[string]*string{"env": to.StringPtr("prod")}, - expect: map[string]*string{"env": to.StringPtr("prod")}, + tags: map[string]*string{"env": pointer.String("prod")}, + expect: map[string]*string{"env": pointer.String("prod")}, }, } diff --git a/azure/converters/vm.go b/azure/converters/vm.go index d2cf9276a1fb..0216b8e14543 100644 --- a/azure/converters/vm.go +++ b/azure/converters/vm.go @@ -18,9 +18,10 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" corev1 "k8s.io/api/core/v1" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" + "sigs.k8s.io/cluster-api-provider-azure/azure" ) // VM describes an Azure virtual machine. @@ -48,9 +49,9 @@ type VM struct { // SDKToVM converts an Azure SDK VirtualMachine to the CAPZ VM type. func SDKToVM(v compute.VirtualMachine) *VM { vm := &VM{ - ID: to.String(v.ID), - Name: to.String(v.Name), - State: infrav1.ProvisioningState(to.String(v.ProvisioningState)), + ID: pointer.StringDeref(v.ID, ""), + Name: pointer.StringDeref(v.Name, ""), + State: infrav1.ProvisioningState(pointer.StringDeref(v.ProvisioningState, "")), } if v.VirtualMachineProperties != nil && v.VirtualMachineProperties.HardwareProfile != nil { @@ -58,7 +59,7 @@ func SDKToVM(v compute.VirtualMachine) *VM { } if v.Zones != nil && len(*v.Zones) > 0 { - vm.AvailabilityZone = to.StringSlice(v.Zones)[0] + vm.AvailabilityZone = azure.StringSlice(v.Zones)[0] } if len(v.Tags) > 0 { diff --git a/azure/converters/vm_test.go b/azure/converters/vm_test.go index 7c5b845907cf..12d89340900a 100644 --- a/azure/converters/vm_test.go +++ b/azure/converters/vm_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -35,10 +35,10 @@ func TestSDKToVM(t *testing.T) { { name: "Basic conversion with required fields", sdk: compute.VirtualMachine{ - ID: to.StringPtr("test-vm-id"), - Name: to.StringPtr("test-vm-name"), + ID: pointer.String("test-vm-id"), + Name: pointer.String("test-vm-name"), VirtualMachineProperties: &compute.VirtualMachineProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), }, }, want: &VM{ @@ -50,10 +50,10 @@ func TestSDKToVM(t *testing.T) { { name: "Should convert and populate with VMSize", sdk: compute.VirtualMachine{ - ID: to.StringPtr("test-vm-id"), - Name: to.StringPtr("test-vm-name"), + ID: pointer.String("test-vm-id"), + Name: pointer.String("test-vm-name"), VirtualMachineProperties: &compute.VirtualMachineProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), HardwareProfile: &compute.HardwareProfile{ VMSize: compute.VirtualMachineSizeTypesStandardA1, }, @@ -69,10 +69,10 @@ func TestSDKToVM(t *testing.T) { { name: "Should convert and populate with availability zones", sdk: compute.VirtualMachine{ - ID: to.StringPtr("test-vm-id"), - Name: to.StringPtr("test-vm-name"), + ID: pointer.String("test-vm-id"), + Name: pointer.String("test-vm-name"), VirtualMachineProperties: &compute.VirtualMachineProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), }, Zones: &[]string{"1", "2"}, }, @@ -86,12 +86,12 @@ func TestSDKToVM(t *testing.T) { { name: "Should convert and populate with tags", sdk: compute.VirtualMachine{ - ID: to.StringPtr("test-vm-id"), - Name: to.StringPtr("test-vm-name"), + ID: pointer.String("test-vm-id"), + Name: pointer.String("test-vm-name"), VirtualMachineProperties: &compute.VirtualMachineProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), }, - Tags: map[string]*string{"foo": to.StringPtr("bar")}, + Tags: map[string]*string{"foo": pointer.String("bar")}, }, want: &VM{ ID: "test-vm-id", @@ -103,16 +103,16 @@ func TestSDKToVM(t *testing.T) { { name: "Should convert and populate with all fields", sdk: compute.VirtualMachine{ - ID: to.StringPtr("test-vm-id"), - Name: to.StringPtr("test-vm-name"), + ID: pointer.String("test-vm-id"), + Name: pointer.String("test-vm-name"), VirtualMachineProperties: &compute.VirtualMachineProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), HardwareProfile: &compute.HardwareProfile{ VMSize: compute.VirtualMachineSizeTypesStandardA1, }, }, Zones: &[]string{"1"}, - Tags: map[string]*string{"foo": to.StringPtr("bar")}, + Tags: map[string]*string{"foo": pointer.String("bar")}, }, want: &VM{ ID: "test-vm-id", diff --git a/azure/converters/vmss.go b/azure/converters/vmss.go index 4c72ae1be32a..6315f1bd0709 100644 --- a/azure/converters/vmss.go +++ b/azure/converters/vmss.go @@ -18,7 +18,7 @@ package converters import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" azprovider "sigs.k8s.io/cloud-provider-azure/pkg/provider" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" @@ -27,18 +27,18 @@ import ( // SDKToVMSS converts an Azure SDK VirtualMachineScaleSet to the AzureMachinePool type. func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.VirtualMachineScaleSetVM) *azure.VMSS { vmss := &azure.VMSS{ - ID: to.String(sdkvmss.ID), - Name: to.String(sdkvmss.Name), - State: infrav1.ProvisioningState(to.String(sdkvmss.ProvisioningState)), + ID: pointer.StringDeref(sdkvmss.ID, ""), + Name: pointer.StringDeref(sdkvmss.Name, ""), + State: infrav1.ProvisioningState(pointer.StringDeref(sdkvmss.ProvisioningState, "")), } if sdkvmss.Sku != nil { - vmss.Sku = to.String(sdkvmss.Sku.Name) - vmss.Capacity = to.Int64(sdkvmss.Sku.Capacity) + vmss.Sku = pointer.StringDeref(sdkvmss.Sku.Name, "") + vmss.Capacity = pointer.Int64Deref(sdkvmss.Sku.Capacity, 0) } if sdkvmss.Zones != nil && len(*sdkvmss.Zones) > 0 { - vmss.Zones = to.StringSlice(sdkvmss.Zones) + vmss.Zones = azure.StringSlice(sdkvmss.Zones) } if len(sdkvmss.Tags) > 0 { @@ -65,7 +65,7 @@ func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.Vi // SDKVMToVMSSVM converts an Azure SDK VM to a VMSS VM. func SDKVMToVMSSVM(sdkInstance compute.VirtualMachine) *azure.VMSSVM { instance := azure.VMSSVM{ - ID: to.String(sdkInstance.ID), + ID: pointer.StringDeref(sdkInstance.ID, ""), } if sdkInstance.VirtualMachineProperties == nil { @@ -74,7 +74,7 @@ func SDKVMToVMSSVM(sdkInstance compute.VirtualMachine) *azure.VMSSVM { instance.State = infrav1.Creating if sdkInstance.ProvisioningState != nil { - instance.State = infrav1.ProvisioningState(to.String(sdkInstance.ProvisioningState)) + instance.State = infrav1.ProvisioningState(pointer.StringDeref(sdkInstance.ProvisioningState, "")) } if sdkInstance.OsProfile != nil && sdkInstance.OsProfile.ComputerName != nil { @@ -88,7 +88,7 @@ func SDKVMToVMSSVM(sdkInstance compute.VirtualMachine) *azure.VMSSVM { if sdkInstance.Zones != nil && len(*sdkInstance.Zones) > 0 { // An instance should have only 1 zone, so use the first item of the slice. - instance.AvailabilityZone = to.StringSlice(sdkInstance.Zones)[0] + instance.AvailabilityZone = azure.StringSlice(sdkInstance.Zones)[0] } return &instance @@ -98,14 +98,14 @@ func SDKVMToVMSSVM(sdkInstance compute.VirtualMachine) *azure.VMSSVM { func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *azure.VMSSVM { // Convert resourceGroup Name ID ( ProviderID in capz objects ) var convertedID string - convertedID, err := azprovider.ConvertResourceGroupNameToLower(to.String(sdkInstance.ID)) + convertedID, err := azprovider.ConvertResourceGroupNameToLower(pointer.StringDeref(sdkInstance.ID, "")) if err != nil { - convertedID = to.String(sdkInstance.ID) + convertedID = pointer.StringDeref(sdkInstance.ID, "") } instance := azure.VMSSVM{ ID: convertedID, - InstanceID: to.String(sdkInstance.InstanceID), + InstanceID: pointer.StringDeref(sdkInstance.InstanceID, ""), } if sdkInstance.VirtualMachineScaleSetVMProperties == nil { @@ -114,7 +114,7 @@ func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *azure.VMSSVM { instance.State = infrav1.Creating if sdkInstance.ProvisioningState != nil { - instance.State = infrav1.ProvisioningState(to.String(sdkInstance.ProvisioningState)) + instance.State = infrav1.ProvisioningState(pointer.StringDeref(sdkInstance.ProvisioningState, "")) } if sdkInstance.OsProfile != nil && sdkInstance.OsProfile.ComputerName != nil { @@ -128,7 +128,7 @@ func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *azure.VMSSVM { if sdkInstance.Zones != nil && len(*sdkInstance.Zones) > 0 { // an instance should only have 1 zone, so we select the first item of the slice - instance.AvailabilityZone = to.StringSlice(sdkInstance.Zones)[0] + instance.AvailabilityZone = azure.StringSlice(sdkInstance.Zones)[0] } return &instance @@ -140,11 +140,11 @@ func SDKImageToImage(sdkImageRef *compute.ImageReference, isThirdPartyImage bool ID: sdkImageRef.ID, Marketplace: &infrav1.AzureMarketplaceImage{ ImagePlan: infrav1.ImagePlan{ - Publisher: to.String(sdkImageRef.Publisher), - Offer: to.String(sdkImageRef.Offer), - SKU: to.String(sdkImageRef.Sku), + Publisher: pointer.StringDeref(sdkImageRef.Publisher, ""), + Offer: pointer.StringDeref(sdkImageRef.Offer, ""), + SKU: pointer.StringDeref(sdkImageRef.Sku, ""), }, - Version: to.String(sdkImageRef.Version), + Version: pointer.StringDeref(sdkImageRef.Version, ""), ThirdPartyImage: isThirdPartyImage, }, } diff --git a/azure/converters/vmss_test.go b/azure/converters/vmss_test.go index 604a0df28174..f1aa7cdf793c 100644 --- a/azure/converters/vmss_test.go +++ b/azure/converters/vmss_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -38,47 +38,47 @@ func Test_SDKToVMSS(t *testing.T) { Name: "ShouldPopulateWithData", SubjectFactory: func(g *gomega.GomegaWithT) (compute.VirtualMachineScaleSet, []compute.VirtualMachineScaleSetVM) { tags := map[string]*string{ - "foo": to.StringPtr("bazz"), + "foo": pointer.String("bazz"), } zones := []string{"zone0", "zone1"} return compute.VirtualMachineScaleSet{ Sku: &compute.Sku{ - Name: to.StringPtr("skuName"), - Tier: to.StringPtr("skuTier"), - Capacity: to.Int64Ptr(2), + Name: pointer.String("skuName"), + Tier: pointer.String("skuTier"), + Capacity: pointer.Int64(2), }, - Zones: to.StringSlicePtr(zones), - ID: to.StringPtr("vmssID"), - Name: to.StringPtr("vmssName"), - Location: to.StringPtr("westus2"), + Zones: &zones, + ID: pointer.String("vmssID"), + Name: pointer.String("vmssName"), + Location: pointer.String("westus2"), Tags: tags, VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{ - SinglePlacementGroup: to.BoolPtr(false), - ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + SinglePlacementGroup: pointer.Bool(false), + ProvisioningState: pointer.String(string(compute.ProvisioningState1Succeeded)), }, }, []compute.VirtualMachineScaleSetVM{ { - InstanceID: to.StringPtr("0"), - ID: to.StringPtr("vm/0"), - Name: to.StringPtr("vm0"), - Zones: to.StringSlicePtr([]string{"zone0"}), + InstanceID: pointer.String("0"), + ID: pointer.String("vm/0"), + Name: pointer.String("vm0"), + Zones: &[]string{"zone0"}, VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + ProvisioningState: pointer.String(string(compute.ProvisioningState1Succeeded)), OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("instance-000000"), + ComputerName: pointer.String("instance-000000"), }, }, }, { - InstanceID: to.StringPtr("1"), - ID: to.StringPtr("vm/1"), - Name: to.StringPtr("vm1"), - Zones: to.StringSlicePtr([]string{"zone1"}), + InstanceID: pointer.String("1"), + ID: pointer.String("vm/1"), + Name: pointer.String("vm1"), + Zones: &[]string{"zone1"}, VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + ProvisioningState: pointer.String(string(compute.ProvisioningState1Succeeded)), OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("instance-000001"), + ComputerName: pointer.String("instance-000001"), }, }, }, @@ -133,7 +133,7 @@ func Test_SDKToVMSSVM(t *testing.T) { { Name: "minimal VM", SDKInstance: compute.VirtualMachineScaleSetVM{ - ID: to.StringPtr("vm/0"), + ID: pointer.String("vm/0"), }, VMSSVM: &azure.VMSSVM{ ID: "vm/0", @@ -142,7 +142,7 @@ func Test_SDKToVMSSVM(t *testing.T) { { Name: "VM with nil properties", SDKInstance: compute.VirtualMachineScaleSetVM{ - ID: to.StringPtr("vm/0.5"), + ID: pointer.String("vm/0.5"), VirtualMachineScaleSetVMProperties: nil, }, VMSSVM: &azure.VMSSVM{ @@ -152,10 +152,10 @@ func Test_SDKToVMSSVM(t *testing.T) { { Name: "VM with state", SDKInstance: compute.VirtualMachineScaleSetVM{ - ID: to.StringPtr("/subscriptions/foo/resourceGroups/MY_RESOURCE_GROUP/providers/bar"), + ID: pointer.String("/subscriptions/foo/resourceGroups/MY_RESOURCE_GROUP/providers/bar"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), - OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("instance-000000")}, + ProvisioningState: pointer.String(string(compute.ProvisioningState1Succeeded)), + OsProfile: &compute.OSProfile{ComputerName: pointer.String("instance-000000")}, }, }, VMSSVM: &azure.VMSSVM{ @@ -167,12 +167,12 @@ func Test_SDKToVMSSVM(t *testing.T) { { Name: "VM with storage", SDKInstance: compute.VirtualMachineScaleSetVM{ - ID: to.StringPtr("/subscriptions/foo/resourceGroups/MY_RESOURCE_GROUP/providers/bar"), + ID: pointer.String("/subscriptions/foo/resourceGroups/MY_RESOURCE_GROUP/providers/bar"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("instance-000001")}, + OsProfile: &compute.OSProfile{ComputerName: pointer.String("instance-000001")}, StorageProfile: &compute.StorageProfile{ ImageReference: &compute.ImageReference{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), }, }, }, @@ -181,7 +181,7 @@ func Test_SDKToVMSSVM(t *testing.T) { ID: "/subscriptions/foo/resourceGroups/my_resource_group/providers/bar", Name: "instance-000001", Image: infrav1.Image{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), Marketplace: &infrav1.AzureMarketplaceImage{}, }, State: "Creating", @@ -190,9 +190,9 @@ func Test_SDKToVMSSVM(t *testing.T) { { Name: "VM with zones", SDKInstance: compute.VirtualMachineScaleSetVM{ - ID: to.StringPtr("/subscriptions/foo/resourceGroups/MY_RESOURCE_GROUP/providers/bar"), + ID: pointer.String("/subscriptions/foo/resourceGroups/MY_RESOURCE_GROUP/providers/bar"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("instance-000002")}, + OsProfile: &compute.OSProfile{ComputerName: pointer.String("instance-000002")}, }, Zones: &[]string{"zone0", "zone1"}, }, @@ -225,26 +225,26 @@ func Test_SDKImageToImage(t *testing.T) { { Name: "minimal image", SDKImageRef: &compute.ImageReference{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), }, IsThirdParty: false, Image: infrav1.Image{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), Marketplace: &infrav1.AzureMarketplaceImage{}, }, }, { Name: "marketplace image", SDKImageRef: &compute.ImageReference{ - ID: to.StringPtr("imageID"), - Publisher: to.StringPtr("publisher"), - Offer: to.StringPtr("offer"), - Sku: to.StringPtr("sku"), - Version: to.StringPtr("version"), + ID: pointer.String("imageID"), + Publisher: pointer.String("publisher"), + Offer: pointer.String("offer"), + Sku: pointer.String("sku"), + Version: pointer.String("version"), }, IsThirdParty: true, Image: infrav1.Image{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), Marketplace: &infrav1.AzureMarketplaceImage{ ImagePlan: infrav1.ImagePlan{ Publisher: "publisher", @@ -277,7 +277,7 @@ func Test_SDKVMToVMSSVM(t *testing.T) { { Name: "minimal VM", Subject: compute.VirtualMachine{ - ID: to.StringPtr("vmID1"), + ID: pointer.String("vmID1"), }, Expected: &azure.VMSSVM{ ID: "vmID1", @@ -286,13 +286,13 @@ func Test_SDKVMToVMSSVM(t *testing.T) { { Name: "VM with zones", Subject: compute.VirtualMachine{ - ID: to.StringPtr("vmID2"), + ID: pointer.String("vmID2"), VirtualMachineProperties: &compute.VirtualMachineProperties{ OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("vmwithzones"), + ComputerName: pointer.String("vmwithzones"), }, }, - Zones: to.StringSlicePtr([]string{"zone0", "zone1"}), + Zones: &[]string{"zone0", "zone1"}, }, Expected: &azure.VMSSVM{ ID: "vmID2", @@ -304,14 +304,14 @@ func Test_SDKVMToVMSSVM(t *testing.T) { { Name: "VM with storage", Subject: compute.VirtualMachine{ - ID: to.StringPtr("vmID3"), + ID: pointer.String("vmID3"), VirtualMachineProperties: &compute.VirtualMachineProperties{ OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("vmwithstorage"), + ComputerName: pointer.String("vmwithstorage"), }, StorageProfile: &compute.StorageProfile{ ImageReference: &compute.ImageReference{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), }, }, }, @@ -319,7 +319,7 @@ func Test_SDKVMToVMSSVM(t *testing.T) { Expected: &azure.VMSSVM{ ID: "vmID3", Image: infrav1.Image{ - ID: to.StringPtr("imageID"), + ID: pointer.String("imageID"), Marketplace: &infrav1.AzureMarketplaceImage{}, }, Name: "vmwithstorage", @@ -329,12 +329,12 @@ func Test_SDKVMToVMSSVM(t *testing.T) { { Name: "VM with provisioning state", Subject: compute.VirtualMachine{ - ID: to.StringPtr("vmID4"), + ID: pointer.String("vmID4"), VirtualMachineProperties: &compute.VirtualMachineProperties{ OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("vmwithstate"), + ComputerName: pointer.String("vmwithstate"), }, - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), }, }, Expected: &azure.VMSSVM{ diff --git a/azure/pointers.go b/azure/pointers.go new file mode 100644 index 000000000000..350bc33379d7 --- /dev/null +++ b/azure/pointers.go @@ -0,0 +1,37 @@ +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package azure + +import "k8s.io/utils/pointer" + +// StringSlice returns a string slice value for the passed string slice pointer. It returns a nil +// slice if the pointer is nil. +func StringSlice(s *[]string) []string { + if s != nil { + return *s + } + return nil +} + +// StringMapPtr returns a pointer to a given string map, or nil if the map is nil. +func StringMapPtr(m map[string]string) *map[string]*string { //nolint:gocritic + msp := make(map[string]*string, len(m)) + for k, v := range m { + msp[k] = pointer.String(v) + } + return &msp +} diff --git a/azure/scope/cluster.go b/azure/scope/cluster.go index da4dd6b03ed8..511a08d82312 100644 --- a/azure/scope/cluster.go +++ b/azure/scope/cluster.go @@ -26,9 +26,9 @@ import ( "strings" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" "k8s.io/utils/net" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/bastionhosts" @@ -539,10 +539,10 @@ func (s *ClusterScope) Vnet() *infrav1.VnetSpec { // IsVnetManaged returns true if the vnet is managed. func (s *ClusterScope) IsVnetManaged() bool { if s.cache.isVnetManaged != nil { - return to.Bool(s.cache.isVnetManaged) + return pointer.BoolDeref(s.cache.isVnetManaged, false) } isVnetManaged := s.Vnet().ID == "" || s.Vnet().Tags.HasOwned(s.ClusterName()) - s.cache.isVnetManaged = to.BoolPtr(isVnetManaged) + s.cache.isVnetManaged = pointer.Bool(isVnetManaged) return isVnetManaged } @@ -855,10 +855,10 @@ func (s *ClusterScope) SetControlPlaneSecurityRules() { Priority: 2200, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionInbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr("22"), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String("22"), }, infrav1.SecurityRule{ Name: "allow_apiserver", @@ -866,10 +866,10 @@ func (s *ClusterScope) SetControlPlaneSecurityRules() { Priority: 2201, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionInbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr(strconv.Itoa(int(s.APIServerPort()))), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String(strconv.Itoa(int(s.APIServerPort()))), }, } s.AzureCluster.Spec.NetworkSpec.UpdateControlPlaneSubnet(subnet) diff --git a/azure/scope/cluster_test.go b/azure/scope/cluster_test.go index 6f7c15ade1c6..5f840c09ab3d 100644 --- a/azure/scope/cluster_test.go +++ b/azure/scope/cluster_test.go @@ -25,11 +25,11 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/bastionhosts" @@ -326,7 +326,7 @@ func TestPublicIPSpecs(t *testing.T) { }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ - FrontendIPsCount: to.Int32Ptr(0), + FrontendIPsCount: pointer.Int32(0), }, APIServerLB: infrav1.LoadBalancerSpec{ LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{ @@ -370,7 +370,7 @@ func TestPublicIPSpecs(t *testing.T) { }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ - FrontendIPsCount: to.Int32Ptr(1), + FrontendIPsCount: pointer.Int32(1), FrontendIPs: []infrav1.FrontendIP{ { Name: "my-frontend-ip", @@ -437,7 +437,7 @@ func TestPublicIPSpecs(t *testing.T) { }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ - FrontendIPsCount: to.Int32Ptr(3), + FrontendIPsCount: pointer.Int32(3), FrontendIPs: []infrav1.FrontendIP{ { Name: "my-frontend-ip-1", @@ -1497,7 +1497,7 @@ func TestIsVnetManaged(t *testing.T) { Spec: infrav1.AzureClusterSpec{}, }, cache: &ClusterCache{ - isVnetManaged: to.BoolPtr(false), + isVnetManaged: pointer.Bool(false), }, }, want: false, @@ -1509,7 +1509,7 @@ func TestIsVnetManaged(t *testing.T) { Spec: infrav1.AzureClusterSpec{}, }, cache: &ClusterCache{ - isVnetManaged: to.BoolPtr(true), + isVnetManaged: pointer.Bool(true), }, }, want: true, @@ -1524,8 +1524,8 @@ func TestIsVnetManaged(t *testing.T) { if !reflect.DeepEqual(got, tt.want) { t.Errorf("IsVnetManaged() = \n%t, want \n%t", got, tt.want) } - if to.Bool(tt.clusterScope.cache.isVnetManaged) != got { - t.Errorf("IsVnetManaged() = \n%t, cache = \n%t", got, to.Bool(tt.clusterScope.cache.isVnetManaged)) + if pointer.BoolDeref(tt.clusterScope.cache.isVnetManaged, false) != got { + t.Errorf("IsVnetManaged() = \n%t, cache = \n%t", got, pointer.BoolDeref(tt.clusterScope.cache.isVnetManaged, false)) } }) } @@ -2534,7 +2534,7 @@ func TestAPIServerPort(t *testing.T) { name: "Non nil cluster network and non nil apiserverport", clusterName: "my-cluster", clusterNetowrk: &clusterv1.ClusterNetwork{ - APIServerPort: to.Int32Ptr(7000), + APIServerPort: pointer.Int32(7000), }, expectAPIServerPort: 7000, }, diff --git a/azure/scope/machine.go b/azure/scope/machine.go index c2f839f69bbb..7ad36016d654 100644 --- a/azure/scope/machine.go +++ b/azure/scope/machine.go @@ -24,10 +24,10 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/availabilitysets" @@ -219,7 +219,7 @@ func (m *MachineScope) InboundNatSpecs() []azure.ResourceSpecGetter { if frontEndIPs := m.APIServerLB().FrontendIPs; len(frontEndIPs) > 0 { ipConfig := frontEndIPs[0].Name id := azure.FrontendIPConfigID(m.SubscriptionID(), m.ResourceGroup(), m.APIServerLBName(), ipConfig) - spec.FrontendIPConfigurationID = to.StringPtr(id) + spec.FrontendIPConfigurationID = pointer.String(id) } return []azure.ResourceSpecGetter{spec} @@ -460,7 +460,7 @@ func (m *MachineScope) GetVMID() string { // ProviderID returns the AzureMachine providerID from the spec. func (m *MachineScope) ProviderID() string { - parsed, err := noderefutil.NewProviderID(to.String(m.AzureMachine.Spec.ProviderID)) + parsed, err := noderefutil.NewProviderID(pointer.StringDeref(m.AzureMachine.Spec.ProviderID, "")) if err != nil { return "" } @@ -524,7 +524,7 @@ func (m *MachineScope) AvailabilitySetID() string { // SetProviderID sets the AzureMachine providerID in spec. func (m *MachineScope) SetProviderID(v string) { - m.AzureMachine.Spec.ProviderID = to.StringPtr(v) + m.AzureMachine.Spec.ProviderID = pointer.String(v) } // VMState returns the AzureMachine VM state. @@ -552,7 +552,7 @@ func (m *MachineScope) SetNotReady() { // SetFailureMessage sets the AzureMachine status failure message. func (m *MachineScope) SetFailureMessage(v error) { - m.AzureMachine.Status.FailureMessage = to.StringPtr(v.Error()) + m.AzureMachine.Status.FailureMessage = pointer.String(v.Error()) } // SetFailureReason sets the AzureMachine status failure reason. @@ -699,11 +699,11 @@ func (m *MachineScope) GetVMImage(ctx context.Context) (*infrav1.Image, error) { runtime := m.AzureMachine.Annotations["runtime"] windowsServerVersion := m.AzureMachine.Annotations["windowsServerVersion"] log.Info("No image specified for machine, using default Windows Image", "machine", m.AzureMachine.GetName(), "runtime", runtime, "windowsServerVersion", windowsServerVersion) - return svc.GetDefaultWindowsImage(ctx, m.Location(), to.String(m.Machine.Spec.Version), runtime, windowsServerVersion) + return svc.GetDefaultWindowsImage(ctx, m.Location(), pointer.StringDeref(m.Machine.Spec.Version, ""), runtime, windowsServerVersion) } log.Info("No image specified for machine, using default Linux Image", "machine", m.AzureMachine.GetName()) - return svc.GetDefaultUbuntuImage(ctx, m.Location(), to.String(m.Machine.Spec.Version)) + return svc.GetDefaultUbuntuImage(ctx, m.Location(), pointer.StringDeref(m.Machine.Spec.Version, "")) } // SetSubnetName defaults the AzureMachine subnet name to the name of one the subnets with the machine role when there is only one of them. diff --git a/azure/scope/machine_test.go b/azure/scope/machine_test.go index 349358b41ce3..efe42c47ab5b 100644 --- a/azure/scope/machine_test.go +++ b/azure/scope/machine_test.go @@ -23,7 +23,6 @@ import ( azureautorest "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" @@ -59,7 +58,7 @@ func TestMachineScope_Name(t *testing.T) { Name: "machine-with-a-long-name", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), OSDisk: infrav1.OSDisk{ OSType: "Windows", }, @@ -165,7 +164,7 @@ func TestMachineScope_GetVMID(t *testing.T) { Name: "not-this-name", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), }, }, }, @@ -179,7 +178,7 @@ func TestMachineScope_GetVMID(t *testing.T) { Name: "machine-name", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("foo"), + ProviderID: pointer.String("foo"), }, }, }, @@ -210,7 +209,7 @@ func TestMachineScope_ProviderID(t *testing.T) { Name: "not-this-name", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), }, }, }, @@ -224,7 +223,7 @@ func TestMachineScope_ProviderID(t *testing.T) { Name: "machine-name", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("foo"), + ProviderID: pointer.String("foo"), }, }, }, @@ -403,7 +402,7 @@ func TestMachineScope_InboundNatSpecs(t *testing.T) { Name: "machine-name", LoadBalancerName: "foo-loadbalancer", ResourceGroup: "my-rg", - FrontendIPConfigurationID: to.StringPtr(azure.FrontendIPConfigID("123", "my-rg", "foo-loadbalancer", "foo-frontend-ip")), + FrontendIPConfigurationID: pointer.String(azure.FrontendIPConfigID("123", "my-rg", "foo-loadbalancer", "foo-frontend-ip")), }, }, }, @@ -476,14 +475,14 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) { ResourceGroup: "my-rg", Scope: azure.GenerateSubscriptionScope("123"), RoleDefinitionID: azure.GenerateContributorRoleDefinitionID("123"), - PrincipalID: to.StringPtr("fakePrincipalID"), + PrincipalID: pointer.String("fakePrincipalID"), }, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.machineScope.RoleAssignmentSpecs(to.StringPtr("fakePrincipalID")); !reflect.DeepEqual(got, tt.want) { + if got := tt.machineScope.RoleAssignmentSpecs(pointer.String("fakePrincipalID")); !reflect.DeepEqual(got, tt.want) { t.Errorf("RoleAssignmentSpecs() = %v, want %v", got, tt.want) } }) @@ -1679,7 +1678,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -1783,7 +1782,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -1800,7 +1799,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, cache: &MachineCache{ VMSKU: resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v2"), + Name: pointer.String("Standard_D2v2"), }, }, }, @@ -1826,7 +1825,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { IPv6Enabled: false, EnableIPForwarding: false, SKU: &resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v2"), + Name: pointer.String("Standard_D2v2"), }, ClusterName: "cluster", AdditionalTags: infrav1.Tags{ @@ -1899,7 +1898,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -2003,7 +2002,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -2114,7 +2113,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -2221,7 +2220,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -2328,7 +2327,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{{ SubnetName: "subnet1", PrivateIPConfigs: 1, @@ -2436,7 +2435,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{ { SubnetName: "subnet1", @@ -2573,7 +2572,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), AllocatePublicIP: true, NetworkInterfaces: []infrav1.NetworkInterface{ { @@ -2711,7 +2710,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { Name: "machine", }, Spec: infrav1.AzureMachineSpec{ - ProviderID: to.StringPtr("azure://compute/virtual-machines/machine-name"), + ProviderID: pointer.String("azure://compute/virtual-machines/machine-name"), NetworkInterfaces: []infrav1.NetworkInterface{ { SubnetName: "subnet1", @@ -2799,7 +2798,7 @@ func TestDiskSpecs(t *testing.T) { }, Spec: infrav1.AzureMachineSpec{ OSDisk: infrav1.OSDisk{ - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "Linux", }, }, @@ -2841,7 +2840,7 @@ func TestDiskSpecs(t *testing.T) { }, Spec: infrav1.AzureMachineSpec{ OSDisk: infrav1.OSDisk{ - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "Linux", }, DataDisks: []infrav1.DataDisk{ @@ -2891,7 +2890,7 @@ func TestDiskSpecs(t *testing.T) { }, Spec: infrav1.AzureMachineSpec{ OSDisk: infrav1.OSDisk{ - DiskSizeGB: to.Int32Ptr(30), + DiskSizeGB: pointer.Int32(30), OSType: "Linux", }, DataDisks: []infrav1.DataDisk{ diff --git a/azure/scope/machinepool.go b/azure/scope/machinepool.go index d479cbc8498c..893d35697c29 100644 --- a/azure/scope/machinepool.go +++ b/azure/scope/machinepool.go @@ -24,7 +24,6 @@ import ( "time" azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -122,7 +121,7 @@ func (m *MachinePoolScope) ScaleSetSpec() azure.ScaleSetSpec { return azure.ScaleSetSpec{ Name: m.Name(), Size: m.AzureMachinePool.Spec.Template.VMSize, - Capacity: int64(to.Int32(m.MachinePool.Spec.Replicas)), + Capacity: int64(pointer.Int32Deref(m.MachinePool.Spec.Replicas, 0)), SSHKeyData: m.AzureMachinePool.Spec.Template.SSHPublicKey, OSDisk: m.AzureMachinePool.Spec.Template.OSDisk, DataDisks: m.AzureMachinePool.Spec.Template.DataDisks, @@ -198,7 +197,7 @@ func (m *MachinePoolScope) NeedsRequeue() bool { // DesiredReplicas returns the replica count on machine pool or 0 if machine pool replicas is nil. func (m MachinePoolScope) DesiredReplicas() int32 { - return to.Int32(m.MachinePool.Spec.Replicas) + return pointer.Int32Deref(m.MachinePool.Spec.Replicas, 0) } // MaxSurge returns the number of machines to surge, or 0 if the deployment strategy does not support surge. @@ -362,7 +361,7 @@ func (m *MachinePoolScope) createMachine(ctx context.Context, machine azure.VMSS APIVersion: infrav1exp.GroupVersion.String(), Kind: "AzureMachinePool", Name: m.AzureMachinePool.Name, - BlockOwnerDeletion: to.BoolPtr(true), + BlockOwnerDeletion: pointer.Bool(true), UID: m.AzureMachinePool.UID, }, }, @@ -589,9 +588,9 @@ func (m *MachinePoolScope) GetVMImage(ctx context.Context) (*infrav1.Image, erro runtime := m.AzureMachinePool.Annotations["runtime"] windowsServerVersion := m.AzureMachinePool.Annotations["windowsServerVersion"] log.V(4).Info("No image specified for machine, using default Windows Image", "machine", m.MachinePool.GetName(), "runtime", runtime, "windowsServerVersion", windowsServerVersion) - defaultImage, err = svc.GetDefaultWindowsImage(ctx, m.Location(), to.String(m.MachinePool.Spec.Template.Spec.Version), runtime, windowsServerVersion) + defaultImage, err = svc.GetDefaultWindowsImage(ctx, m.Location(), pointer.StringDeref(m.MachinePool.Spec.Template.Spec.Version, ""), runtime, windowsServerVersion) } else { - defaultImage, err = svc.GetDefaultUbuntuImage(ctx, m.Location(), to.String(m.MachinePool.Spec.Template.Spec.Version)) + defaultImage, err = svc.GetDefaultUbuntuImage(ctx, m.Location(), pointer.StringDeref(m.MachinePool.Spec.Template.Spec.Version, "")) } if err != nil { diff --git a/azure/scope/machinepool_test.go b/azure/scope/machinepool_test.go index 85b81b20177f..fec2c30575fe 100644 --- a/azure/scope/machinepool_test.go +++ b/azure/scope/machinepool_test.go @@ -24,13 +24,13 @@ import ( azureautorest "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure" @@ -113,7 +113,7 @@ func TestMachinePoolScope_NetworkInterfaces(t *testing.T) { }, Spec: infrav1exp.AzureMachinePoolSpec{ Template: infrav1exp.AzureMachinePoolMachineTemplate{ - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), SubnetName: "node-subnet", }, }, @@ -261,7 +261,7 @@ func TestMachinePoolScope_MaxSurge(t *testing.T) { { Name: "default surge should be 1 regardless of replica count with no surger", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool) { - mp.Spec.Replicas = to.Int32Ptr(3) + mp.Spec.Replicas = pointer.Int32(3) }, Verify: func(g *WithT, surge int, err error) { g.Expect(surge).To(Equal(1)) @@ -271,7 +271,7 @@ func TestMachinePoolScope_MaxSurge(t *testing.T) { { Name: "default surge should be 2 as specified by the surger", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool) { - mp.Spec.Replicas = to.Int32Ptr(3) + mp.Spec.Replicas = pointer.Int32(3) two := intstr.FromInt(2) amp.Spec.Strategy = infrav1exp.AzureMachinePoolDeploymentStrategy{ Type: infrav1exp.RollingUpdateAzureMachinePoolDeploymentStrategyType, @@ -288,7 +288,7 @@ func TestMachinePoolScope_MaxSurge(t *testing.T) { { Name: "default surge should be 2 (50%) of the desired replicas", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool) { - mp.Spec.Replicas = to.Int32Ptr(4) + mp.Spec.Replicas = pointer.Int32(4) fiftyPercent := intstr.FromString("50%") amp.Spec.Strategy = infrav1exp.AzureMachinePoolDeploymentStrategy{ Type: infrav1exp.RollingUpdateAzureMachinePoolDeploymentStrategyType, @@ -400,7 +400,7 @@ func TestMachinePoolScope_GetVMImage(t *testing.T) { { Name: "should set and default the image if no image is specified for the AzureMachinePool", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool) { - mp.Spec.Template.Spec.Version = to.StringPtr("v1.19.11") + mp.Spec.Template.Spec.Version = pointer.String("v1.19.11") }, Verify: func(g *WithT, amp *infrav1exp.AzureMachinePool, vmImage *infrav1.Image, err error) { g.Expect(err).NotTo(HaveOccurred()) @@ -422,7 +422,7 @@ func TestMachinePoolScope_GetVMImage(t *testing.T) { { Name: "should not default or set the image on the AzureMachinePool if it already exists", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool) { - mp.Spec.Template.Spec.Version = to.StringPtr("v1.19.11") + mp.Spec.Template.Spec.Version = pointer.String("v1.19.11") amp.Spec.Template.Image = &infrav1.Image{ Marketplace: &infrav1.AzureMarketplaceImage{ ImagePlan: infrav1.ImagePlan{ @@ -506,7 +506,7 @@ func TestMachinePoolScope_NeedsRequeue(t *testing.T) { Name: "should requeue if the machine is not in succeeded state", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool, vmss *azure.VMSS) { creating := infrav1.Creating - mp.Spec.Replicas = to.Int32Ptr(0) + mp.Spec.Replicas = pointer.Int32(0) amp.Status.ProvisioningState = &creating }, Verify: func(g *WithT, requeue bool) { @@ -517,7 +517,7 @@ func TestMachinePoolScope_NeedsRequeue(t *testing.T) { Name: "should not requeue if the machine is in succeeded state", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool, vmss *azure.VMSS) { succeeded := infrav1.Succeeded - mp.Spec.Replicas = to.Int32Ptr(0) + mp.Spec.Replicas = pointer.Int32(0) amp.Status.ProvisioningState = &succeeded }, Verify: func(g *WithT, requeue bool) { @@ -528,7 +528,7 @@ func TestMachinePoolScope_NeedsRequeue(t *testing.T) { Name: "should requeue if the machine is in succeeded state but desired replica count does not match", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool, vmss *azure.VMSS) { succeeded := infrav1.Succeeded - mp.Spec.Replicas = to.Int32Ptr(1) + mp.Spec.Replicas = pointer.Int32(1) amp.Status.ProvisioningState = &succeeded }, Verify: func(g *WithT, requeue bool) { @@ -539,7 +539,7 @@ func TestMachinePoolScope_NeedsRequeue(t *testing.T) { Name: "should not requeue if the machine is in succeeded state but desired replica count does match", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool, vmss *azure.VMSS) { succeeded := infrav1.Succeeded - mp.Spec.Replicas = to.Int32Ptr(1) + mp.Spec.Replicas = pointer.Int32(1) amp.Status.ProvisioningState = &succeeded vmss.Instances = []azure.VMSSVM{ { @@ -555,7 +555,7 @@ func TestMachinePoolScope_NeedsRequeue(t *testing.T) { Name: "should requeue if an instance VM image does not match the VM image of the VMSS", Setup: func(mp *expv1.MachinePool, amp *infrav1exp.AzureMachinePool, vmss *azure.VMSS) { succeeded := infrav1.Succeeded - mp.Spec.Replicas = to.Int32Ptr(1) + mp.Spec.Replicas = pointer.Int32(1) amp.Status.ProvisioningState = &succeeded vmss.Instances = []azure.VMSSVM{ { diff --git a/azure/scope/machinepoolmachine_test.go b/azure/scope/machinepoolmachine_test.go index 72b77167a213..7988ad9ca485 100644 --- a/azure/scope/machinepoolmachine_test.go +++ b/azure/scope/machinepoolmachine_test.go @@ -20,13 +20,13 @@ import ( "context" "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure" mock_scope "sigs.k8s.io/cluster-api-provider-azure/azure/scope/mocks" @@ -237,7 +237,7 @@ func TestMachineScope_UpdateNodeStatus(t *testing.T) { Spec: expv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ - Version: to.StringPtr("v1.19.11"), + Version: pointer.String("v1.19.11"), }, }, }, @@ -335,7 +335,7 @@ func TestMachinePoolMachineScope_CordonAndDrain(t *testing.T) { Spec: expv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ - Version: to.StringPtr("v1.19.11"), + Version: pointer.String("v1.19.11"), }, }, }, diff --git a/azure/scope/managedcontrolplane.go b/azure/scope/managedcontrolplane.go index af8713dc4ed7..f334cd901f5a 100644 --- a/azure/scope/managedcontrolplane.go +++ b/azure/scope/managedcontrolplane.go @@ -23,11 +23,11 @@ import ( "time" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" "golang.org/x/mod/semver" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/groups" @@ -350,7 +350,7 @@ func (s *ManagedControlPlaneScope) IsIPv6Enabled() bool { // IsVnetManaged returns true if the vnet is managed. func (s *ManagedControlPlaneScope) IsVnetManaged() bool { if s.cache.isVnetManaged != nil { - return to.Bool(s.cache.isVnetManaged) + return pointer.BoolDeref(s.cache.isVnetManaged, false) } // TODO refactor `IsVnetManaged` so that it is able to use an upstream context // see https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/2581 @@ -361,7 +361,7 @@ func (s *ManagedControlPlaneScope) IsVnetManaged() bool { if err != nil { log.Error(err, "Unable to determine if ManagedControlPlaneScope VNET is managed by capz", "AzureManagedCluster", s.ClusterName()) } - s.cache.isVnetManaged = to.BoolPtr(isManaged) + s.cache.isVnetManaged = pointer.Bool(isManaged) return isManaged } diff --git a/azure/scope/managedcontrolplane_test.go b/azure/scope/managedcontrolplane_test.go index e730cf517e6c..0c4fce9bb9e8 100644 --- a/azure/scope/managedcontrolplane_test.go +++ b/azure/scope/managedcontrolplane_test.go @@ -21,10 +21,10 @@ import ( "testing" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools" "sigs.k8s.io/cluster-api-provider-azure/azure/services/managedclusters" @@ -120,7 +120,7 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { SKU: "Standard_D2s_v3", Mode: "System", Replicas: 1, - Version: to.StringPtr("1.21.1"), + Version: pointer.String("1.21.1"), Cluster: "cluster1", VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", Headers: map[string]string{}, @@ -336,7 +336,7 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) { Replicas: 1, Cluster: "cluster1", VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", - OSType: to.StringPtr(azure.LinuxOS), + OSType: pointer.String(azure.LinuxOS), Headers: map[string]string{}, }, &agentpools.AgentPoolSpec{ @@ -346,7 +346,7 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) { Replicas: 1, Cluster: "cluster1", VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", - OSType: to.StringPtr(azure.WindowsOS), + OSType: pointer.String(azure.WindowsOS), Headers: map[string]string{}, }, }, @@ -484,7 +484,7 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { }, }, Cache: &ManagedControlPlaneCache{ - isVnetManaged: to.BoolPtr(true), + isVnetManaged: pointer.Bool(true), }, }, Expected: true, @@ -522,7 +522,7 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { }, }, Cache: &ManagedControlPlaneCache{ - isVnetManaged: to.BoolPtr(false), + isVnetManaged: pointer.Bool(false), }, }, Expected: false, diff --git a/azure/scope/managedmachinepool.go b/azure/scope/managedmachinepool.go index a6a32e9b9767..1cf4afee8dbe 100644 --- a/azure/scope/managedmachinepool.go +++ b/azure/scope/managedmachinepool.go @@ -21,8 +21,8 @@ import ( "fmt" "strings" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools" @@ -156,7 +156,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane } agentPoolSpec := &agentpools.AgentPoolSpec{ - Name: to.String(managedMachinePool.Spec.Name), + Name: pointer.StringDeref(managedMachinePool.Spec.Name, ""), ResourceGroup: managedControlPlane.Spec.ResourceGroupName, Cluster: managedControlPlane.Name, SKU: managedMachinePool.Spec.SKU, @@ -195,7 +195,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane } if managedMachinePool.Spec.Scaling != nil { - agentPoolSpec.EnableAutoScaling = to.BoolPtr(true) + agentPoolSpec.EnableAutoScaling = pointer.Bool(true) agentPoolSpec.MaxCount = managedMachinePool.Spec.Scaling.MaxSize agentPoolSpec.MinCount = managedMachinePool.Spec.Scaling.MinSize } @@ -203,7 +203,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane if len(managedMachinePool.Spec.NodeLabels) > 0 { agentPoolSpec.NodeLabels = make(map[string]*string, len(managedMachinePool.Spec.NodeLabels)) for k, v := range managedMachinePool.Spec.NodeLabels { - agentPoolSpec.NodeLabels[k] = to.StringPtr(v) + agentPoolSpec.NodeLabels[k] = pointer.String(v) } } diff --git a/azure/scope/managedmachinepool_test.go b/azure/scope/managedmachinepool_test.go index d9b9761bdb1b..d69160abdace 100644 --- a/azure/scope/managedmachinepool_test.go +++ b/azure/scope/managedmachinepool_test.go @@ -22,11 +22,11 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools" @@ -109,9 +109,9 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { Mode: "User", Cluster: "cluster1", Replicas: 1, - EnableAutoScaling: to.BoolPtr(true), - MinCount: to.Int32Ptr(2), - MaxCount: to.Int32Ptr(10), + EnableAutoScaling: pointer.Bool(true), + MinCount: pointer.Int32(2), + MaxCount: pointer.Int32(10), VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", Headers: map[string]string{}, }, @@ -209,7 +209,7 @@ func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { Cluster: "cluster1", Replicas: 1, NodeLabels: map[string]*string{ - "custom": to.StringPtr("default"), + "custom": pointer.String("default"), }, VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", Headers: map[string]string{}, @@ -404,7 +404,7 @@ func TestManagedMachinePoolScope_MaxPods(t *testing.T) { Mode: "System", Cluster: "cluster1", Replicas: 1, - MaxPods: to.Int32Ptr(12), + MaxPods: pointer.Int32(12), VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", Headers: map[string]string{}, }, @@ -601,7 +601,7 @@ func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { Mode: "User", Cluster: "cluster1", Replicas: 1, - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeEphemeral)), VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", Headers: map[string]string{}, }, @@ -687,7 +687,7 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { }, ManagedMachinePool: ManagedMachinePool{ MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithKubeletDiskType("pool1", (*infrav1exp.KubeletDiskType)(to.StringPtr("Temporary"))), + InfraMachinePool: getAzureMachinePoolWithKubeletDiskType("pool1", (*infrav1exp.KubeletDiskType)(pointer.String("Temporary"))), }, }, Expected: &agentpools.AgentPoolSpec{ @@ -696,7 +696,7 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { Mode: "User", Cluster: "cluster1", Replicas: 1, - KubeletDiskType: (*infrav1exp.KubeletDiskType)(to.StringPtr("Temporary")), + KubeletDiskType: (*infrav1exp.KubeletDiskType)(pointer.String("Temporary")), VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/", Headers: map[string]string{}, }, @@ -738,7 +738,7 @@ func getAzureMachinePool(name string, mode infrav1exp.NodePoolMode) *infrav1exp. Spec: infrav1exp.AzureManagedMachinePoolSpec{ Mode: string(mode), SKU: "Standard_D2s_v3", - Name: to.StringPtr(name), + Name: pointer.String(name), }, } } @@ -746,15 +746,15 @@ func getAzureMachinePool(name string, mode infrav1exp.NodePoolMode) *infrav1exp. func getAzureMachinePoolWithScaling(name string, min, max int32) *infrav1exp.AzureManagedMachinePool { managedPool := getAzureMachinePool(name, infrav1exp.NodePoolModeUser) managedPool.Spec.Scaling = &infrav1exp.ManagedMachinePoolScaling{ - MinSize: to.Int32Ptr(min), - MaxSize: to.Int32Ptr(max), + MinSize: pointer.Int32(min), + MaxSize: pointer.Int32(max), } return managedPool } func getAzureMachinePoolWithMaxPods(name string, maxPods int32) *infrav1exp.AzureManagedMachinePool { managedPool := getAzureMachinePool(name, infrav1exp.NodePoolModeSystem) - managedPool.Spec.MaxPods = to.Int32Ptr(maxPods) + managedPool.Spec.MaxPods = pointer.Int32(maxPods) return managedPool } @@ -766,7 +766,7 @@ func getAzureMachinePoolWithTaints(name string, taints infrav1exp.Taints) *infra func getAzureMachinePoolWithOsDiskType(name string, osDiskType string) *infrav1exp.AzureManagedMachinePool { managedPool := getAzureMachinePool(name, infrav1exp.NodePoolModeUser) - managedPool.Spec.OsDiskType = to.StringPtr(osDiskType) + managedPool.Spec.OsDiskType = pointer.String(osDiskType) return managedPool } @@ -805,18 +805,18 @@ func getMachinePool(name string) *expv1.MachinePool { func getLinuxAzureMachinePool(name string) *infrav1exp.AzureManagedMachinePool { managedPool := getAzureMachinePool(name, infrav1exp.NodePoolModeUser) - managedPool.Spec.OSType = to.StringPtr(azure.LinuxOS) + managedPool.Spec.OSType = pointer.String(azure.LinuxOS) return managedPool } func getWindowsAzureMachinePool(name string) *infrav1exp.AzureManagedMachinePool { managedPool := getAzureMachinePool(name, infrav1exp.NodePoolModeUser) - managedPool.Spec.OSType = to.StringPtr(azure.WindowsOS) + managedPool.Spec.OSType = pointer.String(azure.WindowsOS) return managedPool } func getMachinePoolWithVersion(name, version string) *expv1.MachinePool { machine := getMachinePool(name) - machine.Spec.Template.Spec.Version = to.StringPtr(version) + machine.Spec.Template.Spec.Version = pointer.String(version) return machine } diff --git a/azure/services/agentpools/agentpools.go b/azure/services/agentpools/agentpools.go index 9b440075675f..9361c29cff2e 100644 --- a/azure/services/agentpools/agentpools.go +++ b/azure/services/agentpools/agentpools.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async" @@ -84,7 +84,7 @@ func (s *Service) Reconcile(ctx context.Context) error { return errors.Errorf("%T is not a containerservice.AgentPool", result) } // When autoscaling is set, add the annotation to the machine pool and update the replica count. - if to.Bool(agentPool.EnableAutoScaling) { + if pointer.BoolDeref(agentPool.EnableAutoScaling, false) { s.scope.SetCAPIMachinePoolAnnotation(clusterv1.ReplicasManagedByAnnotation, "true") s.scope.SetCAPIMachinePoolReplicas(agentPool.Count) } else { // Otherwise, remove the annotation. diff --git a/azure/services/agentpools/agentpools_test.go b/azure/services/agentpools/agentpools_test.go index 67a9a79cfd40..bea0a8aa474c 100644 --- a/azure/services/agentpools/agentpools_test.go +++ b/azure/services/agentpools/agentpools_test.go @@ -22,9 +22,9 @@ import ( "testing" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools/mock_agentpools" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -38,24 +38,24 @@ var ( Name: "fake-agent-pool-name", ResourceGroup: "fake-rg", Cluster: "fake-cluster", - Version: to.StringPtr("fake-version"), + Version: pointer.String("fake-version"), SKU: "fake-sku", Replicas: 1, OSDiskSizeGB: 2, VnetSubnetID: "fake-vnet-subnet-id", Mode: "fake-mode", - MaxCount: to.Int32Ptr(5), - MinCount: to.Int32Ptr(1), - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, + MaxCount: pointer.Int32(5), + MinCount: pointer.Int32(1), + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, NodeTaints: []string{"fake-taint"}, - EnableAutoScaling: to.BoolPtr(true), + EnableAutoScaling: pointer.Bool(true), AvailabilityZones: []string{"fake-zone"}, - MaxPods: to.Int32Ptr(10), - OsDiskType: to.StringPtr("fake-os-disk-type"), - EnableUltraSSD: to.BoolPtr(true), - OSType: to.StringPtr("fake-os-type"), + MaxPods: pointer.Int32(10), + OsDiskType: pointer.String("fake-os-disk-type"), + EnableUltraSSD: pointer.Bool(true), + OSType: pointer.String("fake-os-type"), Headers: map[string]string{"fake-header": "fake-value"}, - KubeletDiskType: (*infrav1exp.KubeletDiskType)(to.StringPtr("fake-kubelet-disk-type")), + KubeletDiskType: (*infrav1exp.KubeletDiskType)(pointer.String("fake-kubelet-disk-type")), } internalError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error") diff --git a/azure/services/agentpools/spec.go b/azure/services/agentpools/spec.go index d29572ff9811..ff362cca452a 100644 --- a/azure/services/agentpools/spec.go +++ b/azure/services/agentpools/spec.go @@ -22,9 +22,9 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -224,7 +224,7 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p // When autoscaling is set, the count of the nodes differ based on the autoscaler and should not depend on the // count present in MachinePool or AzureManagedMachinePool, hence we should not make an update API call based // on difference in count. - if to.Bool(s.EnableAutoScaling) { + if pointer.BoolDeref(s.EnableAutoScaling, false) { normalizedProfile.Count = existingProfile.Count } @@ -283,7 +283,7 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p EnableAutoScaling: s.EnableAutoScaling, EnableUltraSSD: s.EnableUltraSSD, KubeletConfig: kubeletConfig, - KubeletDiskType: containerservice.KubeletDiskType(to.String((*string)(s.KubeletDiskType))), + KubeletDiskType: containerservice.KubeletDiskType(pointer.StringDeref((*string)(s.KubeletDiskType), "")), MaxCount: s.MaxCount, MaxPods: s.MaxPods, MinCount: s.MinCount, @@ -292,15 +292,15 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p NodeTaints: nodeTaints, OrchestratorVersion: s.Version, OsDiskSizeGB: &s.OSDiskSizeGB, - OsDiskType: containerservice.OSDiskType(to.String(s.OsDiskType)), - OsType: containerservice.OSType(to.String(s.OSType)), - ScaleSetPriority: containerservice.ScaleSetPriority(to.String(s.ScaleSetPriority)), + OsDiskType: containerservice.OSDiskType(pointer.StringDeref(s.OsDiskType, "")), + OsType: containerservice.OSType(pointer.StringDeref(s.OSType, "")), + ScaleSetPriority: containerservice.ScaleSetPriority(pointer.StringDeref(s.ScaleSetPriority, "")), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, VMSize: sku, VnetSubnetID: vnetSubnetID, EnableNodePublicIP: s.EnableNodePublicIP, NodePublicIPPrefixID: s.NodePublicIPPrefixID, - Tags: *to.StringMapPtr(s.AdditionalTags), + Tags: *azure.StringMapPtr(s.AdditionalTags), }, } diff --git a/azure/services/agentpools/spec_test.go b/azure/services/agentpools/spec_test.go index 82d317fbc6c2..ca9ae3dfd4c5 100644 --- a/azure/services/agentpools/spec_test.go +++ b/azure/services/agentpools/spec_test.go @@ -23,10 +23,10 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -37,20 +37,20 @@ var ( ResourceGroup: "fake-rg", Cluster: "fake-cluster", AvailabilityZones: []string{"fake-zone"}, - EnableAutoScaling: to.BoolPtr(true), - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), + EnableAutoScaling: pointer.Bool(true), + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), Mode: "fake-mode", - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, NodeTaints: []string{"fake-taint"}, OSDiskSizeGB: 2, - OsDiskType: to.StringPtr("fake-os-disk-type"), - OSType: to.StringPtr("fake-os-type"), + OsDiskType: pointer.String("fake-os-disk-type"), + OSType: pointer.String("fake-os-type"), Replicas: 1, SKU: "fake-sku", - Version: to.StringPtr("fake-version"), + Version: pointer.String("fake-version"), VnetSubnetID: "fake-vnet-subnet-id", Headers: map[string]string{"fake-header": "fake-value"}, AdditionalTags: infrav1.Tags{"fake": "tag"}, @@ -60,20 +60,20 @@ var ( ResourceGroup: "fake-rg", Cluster: "fake-cluster", AvailabilityZones: []string{"fake-zone"}, - EnableAutoScaling: to.BoolPtr(true), - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), + EnableAutoScaling: pointer.Bool(true), + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), Mode: "fake-mode", - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, NodeTaints: []string{"fake-taint"}, OSDiskSizeGB: 2, - OsDiskType: to.StringPtr("fake-os-disk-type"), - OSType: to.StringPtr("fake-os-type"), + OsDiskType: pointer.String("fake-os-disk-type"), + OSType: pointer.String("fake-os-type"), Replicas: 1, SKU: "fake-sku", - Version: to.StringPtr("fake-version"), + Version: pointer.String("fake-version"), VnetSubnetID: "fake-vnet-subnet-id", Headers: map[string]string{"fake-header": "fake-value"}, AdditionalTags: infrav1.Tags{"fake": "tag"}, @@ -83,20 +83,20 @@ var ( ResourceGroup: "fake-rg", Cluster: "fake-cluster", AvailabilityZones: []string{"fake-zone"}, - EnableAutoScaling: to.BoolPtr(false), - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), + EnableAutoScaling: pointer.Bool(false), + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), Mode: "fake-mode", - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, NodeTaints: []string{"fake-taint"}, OSDiskSizeGB: 2, - OsDiskType: to.StringPtr("fake-os-disk-type"), - OSType: to.StringPtr("fake-os-type"), + OsDiskType: pointer.String("fake-os-disk-type"), + OSType: pointer.String("fake-os-type"), Replicas: 0, SKU: "fake-sku", - Version: to.StringPtr("fake-version"), + Version: pointer.String("fake-version"), VnetSubnetID: "fake-vnet-subnet-id", Headers: map[string]string{"fake-header": "fake-value"}, AdditionalTags: infrav1.Tags{"fake": "tag"}, @@ -105,117 +105,117 @@ var ( fakeAgentPoolAutoScalingOutOfDate = containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(1), // updates if changed - EnableAutoScaling: to.BoolPtr(false), // updates if changed - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), // updates if changed - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), // updates if changed - Mode: containerservice.AgentPoolMode("fake-mode"), // updates if changed - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, // updates if changed + Count: pointer.Int32(1), // updates if changed + EnableAutoScaling: pointer.Bool(false), // updates if changed + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), // updates if changed + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), // updates if changed + Mode: containerservice.AgentPoolMode("fake-mode"), // updates if changed + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, // updates if changed NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), // updates if changed - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), // updates if changed + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } fakeAgentPoolMaxCountOutOfDate = containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(1), // updates if changed - EnableAutoScaling: to.BoolPtr(true), // updates if changed - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(3), // updates if changed - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), // updates if changed - Mode: containerservice.AgentPoolMode("fake-mode"), // updates if changed - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, // updates if changed + Count: pointer.Int32(1), // updates if changed + EnableAutoScaling: pointer.Bool(true), // updates if changed + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(3), // updates if changed + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), // updates if changed + Mode: containerservice.AgentPoolMode("fake-mode"), // updates if changed + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, // updates if changed NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), // updates if changed - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), // updates if changed + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } fakeAgentPoolMinCountOutOfDate = containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(1), // updates if changed - EnableAutoScaling: to.BoolPtr(true), // updates if changed - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), // updates if changed - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(3), // updates if changed - Mode: containerservice.AgentPoolMode("fake-mode"), // updates if changed - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, // updates if changed + Count: pointer.Int32(1), // updates if changed + EnableAutoScaling: pointer.Bool(true), // updates if changed + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), // updates if changed + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(3), // updates if changed + Mode: containerservice.AgentPoolMode("fake-mode"), // updates if changed + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, // updates if changed NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), // updates if changed - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), // updates if changed + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } fakeAgentPoolModeOutOfDate = containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(1), // updates if changed - EnableAutoScaling: to.BoolPtr(true), // updates if changed - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), // updates if changed - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(3), // updates if changed - Mode: containerservice.AgentPoolMode("fake-old-mode"), // updates if changed - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, // updates if changed + Count: pointer.Int32(1), // updates if changed + EnableAutoScaling: pointer.Bool(true), // updates if changed + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), // updates if changed + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(3), // updates if changed + Mode: containerservice.AgentPoolMode("fake-old-mode"), // updates if changed + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, // updates if changed NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), // updates if changed - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), // updates if changed + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } fakeAgentPoolNodeLabelsOutOfDate = containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(1), // updates if changed - EnableAutoScaling: to.BoolPtr(true), // updates if changed - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), // updates if changed - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(3), // updates if changed + Count: pointer.Int32(1), // updates if changed + EnableAutoScaling: pointer.Bool(true), // updates if changed + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), // updates if changed + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(3), // updates if changed Mode: containerservice.AgentPoolMode("fake-old-mode"), // updates if changed NodeLabels: map[string]*string{ - "fake-label": to.StringPtr("fake-value"), - "fake-old-label": to.StringPtr("fake-old-value")}, // updates if changed + "fake-label": pointer.String("fake-value"), + "fake-old-label": pointer.String("fake-old-value")}, // updates if changed NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), // updates if changed - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), // updates if changed + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } ) @@ -227,29 +227,29 @@ func fakeAgentPoolWithProvisioningState(provisioningState string) containerservi func fakeAgentPoolWithProvisioningStateAndCountAndAutoscaling(provisioningState string, count int32, autoscaling bool) containerservice.AgentPool { var state *string if provisioningState != "" { - state = to.StringPtr(provisioningState) + state = pointer.String(provisioningState) } return containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(count), - EnableAutoScaling: to.BoolPtr(autoscaling), - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), + Count: pointer.Int32(count), + EnableAutoScaling: pointer.Bool(autoscaling), + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), Mode: containerservice.AgentPoolMode("fake-mode"), - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), ProvisioningState: state, - Tags: map[string]*string{"fake": to.StringPtr("tag")}, + Tags: map[string]*string{"fake": pointer.String("tag")}, Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } } @@ -258,24 +258,24 @@ func fakeAgentPoolWithAutoscalingAndCount(enableAutoScaling bool, count int32) c return containerservice.AgentPool{ ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{ AvailabilityZones: &[]string{"fake-zone"}, - Count: to.Int32Ptr(count), - EnableAutoScaling: to.BoolPtr(enableAutoScaling), - EnableUltraSSD: to.BoolPtr(true), - MaxCount: to.Int32Ptr(5), - MaxPods: to.Int32Ptr(10), - MinCount: to.Int32Ptr(1), + Count: pointer.Int32(count), + EnableAutoScaling: pointer.Bool(enableAutoScaling), + EnableUltraSSD: pointer.Bool(true), + MaxCount: pointer.Int32(5), + MaxPods: pointer.Int32(10), + MinCount: pointer.Int32(1), Mode: containerservice.AgentPoolMode("fake-mode"), - NodeLabels: map[string]*string{"fake-label": to.StringPtr("fake-value")}, + NodeLabels: map[string]*string{"fake-label": pointer.String("fake-value")}, NodeTaints: &[]string{"fake-taint"}, - OrchestratorVersion: to.StringPtr("fake-version"), - OsDiskSizeGB: to.Int32Ptr(2), + OrchestratorVersion: pointer.String("fake-version"), + OsDiskSizeGB: pointer.Int32(2), OsDiskType: containerservice.OSDiskType("fake-os-disk-type"), OsType: containerservice.OSType("fake-os-type"), - ProvisioningState: to.StringPtr("Succeeded"), - Tags: map[string]*string{"fake": to.StringPtr("tag")}, + ProvisioningState: pointer.String("Succeeded"), + Tags: map[string]*string{"fake": pointer.String("tag")}, Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - VMSize: to.StringPtr("fake-sku"), - VnetSubnetID: to.StringPtr("fake-vnet-subnet-id"), + VMSize: pointer.String("fake-sku"), + VnetSubnetID: pointer.String("fake-vnet-subnet-id"), }, } } @@ -424,58 +424,58 @@ func TestMergeSystemNodeLabels(t *testing.T) { { name: "update an existing label", capzLabels: map[string]*string{ - "foo": to.StringPtr("bar"), + "foo": pointer.String("bar"), }, aksLabels: map[string]*string{ - "foo": to.StringPtr("baz"), + "foo": pointer.String("baz"), }, expected: map[string]*string{ - "foo": to.StringPtr("bar"), + "foo": pointer.String("bar"), }, }, { name: "delete labels", capzLabels: map[string]*string{}, aksLabels: map[string]*string{ - "foo": to.StringPtr("bar"), - "hello": to.StringPtr("world"), + "foo": pointer.String("bar"), + "hello": pointer.String("world"), }, expected: map[string]*string{}, }, { name: "delete one label", capzLabels: map[string]*string{ - "foo": to.StringPtr("bar"), + "foo": pointer.String("bar"), }, aksLabels: map[string]*string{ - "foo": to.StringPtr("bar"), - "hello": to.StringPtr("world"), + "foo": pointer.String("bar"), + "hello": pointer.String("world"), }, expected: map[string]*string{ - "foo": to.StringPtr("bar"), + "foo": pointer.String("bar"), }, }, { name: "retain system label during update", capzLabels: map[string]*string{ - "foo": to.StringPtr("bar"), + "foo": pointer.String("bar"), }, aksLabels: map[string]*string{ - "kubernetes.azure.com/scalesetpriority": to.StringPtr("spot"), + "kubernetes.azure.com/scalesetpriority": pointer.String("spot"), }, expected: map[string]*string{ - "foo": to.StringPtr("bar"), - "kubernetes.azure.com/scalesetpriority": to.StringPtr("spot"), + "foo": pointer.String("bar"), + "kubernetes.azure.com/scalesetpriority": pointer.String("spot"), }, }, { name: "retain system label during delete", capzLabels: map[string]*string{}, aksLabels: map[string]*string{ - "kubernetes.azure.com/scalesetpriority": to.StringPtr("spot"), + "kubernetes.azure.com/scalesetpriority": pointer.String("spot"), }, expected: map[string]*string{ - "kubernetes.azure.com/scalesetpriority": to.StringPtr("spot"), + "kubernetes.azure.com/scalesetpriority": pointer.String("spot"), }, }, } diff --git a/azure/services/availabilitysets/availabilitysets_test.go b/azure/services/availabilitysets/availabilitysets_test.go index a38340341327..001f17dbe454 100644 --- a/azure/services/availabilitysets/availabilitysets_test.go +++ b/azure/services/availabilitysets/availabilitysets_test.go @@ -24,10 +24,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" "sigs.k8s.io/cluster-api-provider-azure/azure/services/availabilitysets/mock_availabilitysets" @@ -40,8 +40,8 @@ var ( fakeSku = resourceskus.SKU{ Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.MaximumPlatformFaultDomainCount), - Value: to.StringPtr(strconv.Itoa(fakeFaultDomainCount)), + Name: pointer.String(resourceskus.MaximumPlatformFaultDomainCount), + Value: pointer.String(strconv.Itoa(fakeFaultDomainCount)), }, }, } @@ -67,7 +67,7 @@ var ( fakeSetWithVMs = compute.AvailabilitySet{ AvailabilitySetProperties: &compute.AvailabilitySetProperties{ VirtualMachines: &[]compute.SubResource{ - {ID: to.StringPtr("vm-id")}, + {ID: pointer.String("vm-id")}, }, }, } diff --git a/azure/services/availabilitysets/spec.go b/azure/services/availabilitysets/spec.go index 30f7e155b73f..9b69d9d75f2f 100644 --- a/azure/services/availabilitysets/spec.go +++ b/azure/services/availabilitysets/spec.go @@ -21,8 +21,8 @@ import ( "strconv" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" "sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus" @@ -76,11 +76,11 @@ func (s *AvailabilitySetSpec) Parameters(ctx context.Context, existing interface if err != nil { return nil, errors.Wrapf(err, "unable to parse availability set fault domain count") } - faultDomainCount = to.Int32Ptr(int32(count)) + faultDomainCount = pointer.Int32(int32(count)) asParams := compute.AvailabilitySet{ Sku: &compute.Sku{ - Name: to.StringPtr(string(compute.AvailabilitySetSkuTypesAligned)), + Name: pointer.String(string(compute.AvailabilitySetSkuTypesAligned)), }, AvailabilitySetProperties: &compute.AvailabilitySetProperties{ PlatformFaultDomainCount: faultDomainCount, @@ -88,11 +88,11 @@ func (s *AvailabilitySetSpec) Parameters(ctx context.Context, existing interface Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), - Role: to.StringPtr(infrav1.CommonRole), + Name: pointer.String(s.Name), + Role: pointer.String(infrav1.CommonRole), Additional: s.AdditionalTags, })), - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), } return asParams, nil diff --git a/azure/services/availabilitysets/spec_test.go b/azure/services/availabilitysets/spec_test.go index 648c29eb969e..fb0ec2a72927 100644 --- a/azure/services/availabilitysets/spec_test.go +++ b/azure/services/availabilitysets/spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus" ) @@ -69,7 +69,7 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.AvailabilitySet{})) - g.Expect(result.(compute.AvailabilitySet).PlatformFaultDomainCount).To(Equal(to.Int32Ptr(int32(fakeFaultDomainCount)))) + g.Expect(result.(compute.AvailabilitySet).PlatformFaultDomainCount).To(Equal(pointer.Int32(int32(fakeFaultDomainCount)))) }, expectedError: "", }, diff --git a/azure/services/bastionhosts/spec.go b/azure/services/bastionhosts/spec.go index 062edba45279..2d83a9f20c11 100644 --- a/azure/services/bastionhosts/spec.go +++ b/azure/services/bastionhosts/spec.go @@ -22,8 +22,8 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -73,19 +73,19 @@ func (s *AzureBastionSpec) Parameters(ctx context.Context, existing interface{}) bastionHostIPConfigName := fmt.Sprintf("%s-%s", s.Name, "bastionIP") return network.BastionHost{ - Name: to.StringPtr(s.Name), - Location: to.StringPtr(s.Location), + Name: pointer.String(s.Name), + Location: pointer.String(s.Location), Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), - Role: to.StringPtr("Bastion"), + Name: pointer.String(s.Name), + Role: pointer.String("Bastion"), })), BastionHostPropertiesFormat: &network.BastionHostPropertiesFormat{ - DNSName: to.StringPtr(fmt.Sprintf("%s-bastion", strings.ToLower(s.Name))), + DNSName: pointer.String(fmt.Sprintf("%s-bastion", strings.ToLower(s.Name))), IPConfigurations: &[]network.BastionHostIPConfiguration{ { - Name: to.StringPtr(bastionHostIPConfigName), + Name: pointer.String(bastionHostIPConfigName), BastionHostIPConfigurationPropertiesFormat: &network.BastionHostIPConfigurationPropertiesFormat{ Subnet: &network.SubResource{ ID: &s.SubnetID, diff --git a/azure/services/groups/groups_test.go b/azure/services/groups/groups_test.go index ceb496e69c18..511d70a86dd7 100644 --- a/azure/services/groups/groups_test.go +++ b/azure/services/groups/groups_test.go @@ -23,9 +23,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-05-01/resources" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" "sigs.k8s.io/cluster-api-provider-azure/azure/services/groups/mock_groups" @@ -42,16 +42,16 @@ var ( internalError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error") notFoundError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusNotFound}, "Not Found") sampleManagedGroup = resources.Group{ - Name: to.StringPtr("test-group"), - Location: to.StringPtr("test-location"), + Name: pointer.String("test-group"), + Location: pointer.String("test-location"), Properties: &resources.GroupProperties{}, - Tags: map[string]*string{"sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned")}, + Tags: map[string]*string{"sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned")}, } sampleBYOGroup = resources.Group{ - Name: to.StringPtr("test-group"), - Location: to.StringPtr("test-location"), + Name: pointer.String("test-group"), + Location: pointer.String("test-location"), Properties: &resources.GroupProperties{}, - Tags: map[string]*string{"foo": to.StringPtr("bar")}, + Tags: map[string]*string{"foo": pointer.String("bar")}, } ) diff --git a/azure/services/groups/spec.go b/azure/services/groups/spec.go index 7bfffe19b895..e39a665af03d 100644 --- a/azure/services/groups/spec.go +++ b/azure/services/groups/spec.go @@ -20,7 +20,7 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-05-01/resources" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -57,13 +57,13 @@ func (s *GroupSpec) Parameters(ctx context.Context, existing interface{}) (param return nil, nil } return resources.Group{ - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), // User defined additional tags are created with the resource group and updated using tags service. Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), - Role: to.StringPtr(infrav1.CommonRole), + Name: pointer.String(s.Name), + Role: pointer.String(infrav1.CommonRole), Additional: s.AdditionalTags, })), }, nil diff --git a/azure/services/inboundnatrules/inboundnatrules_test.go b/azure/services/inboundnatrules/inboundnatrules_test.go index a30138e3b8a6..e262c9df9653 100644 --- a/azure/services/inboundnatrules/inboundnatrules_test.go +++ b/azure/services/inboundnatrules/inboundnatrules_test.go @@ -23,7 +23,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "k8s.io/utils/pointer" @@ -44,14 +43,14 @@ var ( Name: pointer.StringPtr("other-machine-nat-rule"), ID: pointer.StringPtr("some-natrules-id"), InboundNatRulePropertiesFormat: &network.InboundNatRulePropertiesFormat{ - FrontendPort: to.Int32Ptr(22), + FrontendPort: pointer.Int32(22), }, }, { Name: pointer.StringPtr("other-machine-nat-rule-2"), ID: pointer.StringPtr("some-natrules-id-2"), InboundNatRulePropertiesFormat: &network.InboundNatRulePropertiesFormat{ - FrontendPort: to.Int32Ptr(2201), + FrontendPort: pointer.Int32(2201), }, }, } @@ -60,13 +59,13 @@ var ( Name: "my-machine-1", LoadBalancerName: "my-lb-1", ResourceGroup: fakeGroupName, - FrontendIPConfigurationID: to.StringPtr("frontend-ip-config-id-1"), + FrontendIPConfigurationID: pointer.String("frontend-ip-config-id-1"), } fakeNatSpec2 = InboundNatSpec{ Name: "my-machine-2", LoadBalancerName: "my-lb-1", ResourceGroup: fakeGroupName, - FrontendIPConfigurationID: to.StringPtr("frontend-ip-config-id-2"), + FrontendIPConfigurationID: pointer.String("frontend-ip-config-id-2"), } internalError = autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error") @@ -79,7 +78,7 @@ func getFakeNatSpecWithoutPort(spec InboundNatSpec) *InboundNatSpec { func getFakeNatSpecWithPort(spec InboundNatSpec, port int32) *InboundNatSpec { newSpec := spec - newSpec.SSHFrontendPort = to.Int32Ptr(port) + newSpec.SSHFrontendPort = pointer.Int32(port) return &newSpec } diff --git a/azure/services/inboundnatrules/spec.go b/azure/services/inboundnatrules/spec.go index 2e33c3772a21..83aab7ba7de4 100644 --- a/azure/services/inboundnatrules/spec.go +++ b/azure/services/inboundnatrules/spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" ) // InboundNatSpec defines the specification for an inbound NAT rule. @@ -63,11 +63,11 @@ func (s *InboundNatSpec) Parameters(ctx context.Context, existing interface{}) ( } rule := network.InboundNatRule{ - Name: to.StringPtr(s.ResourceName()), + Name: pointer.String(s.ResourceName()), InboundNatRulePropertiesFormat: &network.InboundNatRulePropertiesFormat{ - BackendPort: to.Int32Ptr(22), - EnableFloatingIP: to.BoolPtr(false), - IdleTimeoutInMinutes: to.Int32Ptr(4), + BackendPort: pointer.Int32(22), + EnableFloatingIP: pointer.Bool(false), + IdleTimeoutInMinutes: pointer.Int32(4), FrontendIPConfiguration: &network.SubResource{ ID: s.FrontendIPConfigurationID, }, diff --git a/azure/services/loadbalancers/loadbalancers_test.go b/azure/services/loadbalancers/loadbalancers_test.go index c0af4a9edede..f35193c96d03 100644 --- a/azure/services/loadbalancers/loadbalancers_test.go +++ b/azure/services/loadbalancers/loadbalancers_test.go @@ -22,9 +22,9 @@ import ( "testing" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -44,7 +44,7 @@ var ( SKU: infrav1.SKUStandard, SubnetName: "my-cp-subnet", BackendPoolName: "my-publiclb-backendPool", - IdleTimeoutInMinutes: to.Int32Ptr(4), + IdleTimeoutInMinutes: pointer.Int32(4), FrontendIPConfigs: []infrav1.FrontendIP{ { Name: "my-publiclb-frontEnd", @@ -68,7 +68,7 @@ var ( SKU: infrav1.SKUStandard, SubnetName: "my-cp-subnet", BackendPoolName: "my-private-lb-backendPool", - IdleTimeoutInMinutes: to.Int32Ptr(4), + IdleTimeoutInMinutes: pointer.Int32(4), FrontendIPConfigs: []infrav1.FrontendIP{ { Name: "my-private-lb-frontEnd", @@ -90,7 +90,7 @@ var ( Type: infrav1.Public, SKU: infrav1.SKUStandard, BackendPoolName: "my-cluster-outboundBackendPool", - IdleTimeoutInMinutes: to.Int32Ptr(30), + IdleTimeoutInMinutes: pointer.Int32(30), FrontendIPConfigs: []infrav1.FrontendIP{ { Name: "my-cluster-frontEnd", diff --git a/azure/services/loadbalancers/spec.go b/azure/services/loadbalancers/spec.go index 0bd1aa3cff9a..b3a391753ca6 100644 --- a/azure/services/loadbalancers/spec.go +++ b/azure/services/loadbalancers/spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -141,11 +141,11 @@ func (s *LBSpec) Parameters(ctx context.Context, existing interface{}) (paramete lb := network.LoadBalancer{ Etag: etag, Sku: &network.LoadBalancerSku{Name: converters.SKUtoSDK(s.SKU)}, - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Role: to.StringPtr(s.Role), + Role: pointer.String(s.Role), Additional: s.AdditionalTags, })), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ @@ -169,23 +169,23 @@ func getFrontendIPConfigs(lbSpec LBSpec) ([]network.FrontendIPConfiguration, []n properties = network.FrontendIPConfigurationPropertiesFormat{ PrivateIPAllocationMethod: network.IPAllocationMethodStatic, Subnet: &network.Subnet{ - ID: to.StringPtr(azure.SubnetID(lbSpec.SubscriptionID, lbSpec.VNetResourceGroup, lbSpec.VNetName, lbSpec.SubnetName)), + ID: pointer.String(azure.SubnetID(lbSpec.SubscriptionID, lbSpec.VNetResourceGroup, lbSpec.VNetName, lbSpec.SubnetName)), }, - PrivateIPAddress: to.StringPtr(ipConfig.PrivateIPAddress), + PrivateIPAddress: pointer.String(ipConfig.PrivateIPAddress), } } else { properties = network.FrontendIPConfigurationPropertiesFormat{ PublicIPAddress: &network.PublicIPAddress{ - ID: to.StringPtr(azure.PublicIPID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, ipConfig.PublicIP.Name)), + ID: pointer.String(azure.PublicIPID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, ipConfig.PublicIP.Name)), }, } } frontendIPConfigurations = append(frontendIPConfigurations, network.FrontendIPConfiguration{ FrontendIPConfigurationPropertiesFormat: &properties, - Name: to.StringPtr(ipConfig.Name), + Name: pointer.String(ipConfig.Name), }) frontendIDs = append(frontendIDs, network.SubResource{ - ID: to.StringPtr(azure.FrontendIPConfigID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, ipConfig.Name)), + ID: pointer.String(azure.FrontendIPConfigID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, ipConfig.Name)), }) } return frontendIPConfigurations, frontendIDs @@ -197,13 +197,13 @@ func getOutboundRules(lbSpec LBSpec, frontendIDs []network.SubResource) []networ } return []network.OutboundRule{ { - Name: to.StringPtr(outboundNAT), + Name: pointer.String(outboundNAT), OutboundRulePropertiesFormat: &network.OutboundRulePropertiesFormat{ Protocol: network.LoadBalancerOutboundRuleProtocolAll, IdleTimeoutInMinutes: lbSpec.IdleTimeoutInMinutes, FrontendIPConfigurations: &frontendIDs, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr(azure.AddressPoolID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, lbSpec.BackendPoolName)), + ID: pointer.String(azure.AddressPoolID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, lbSpec.BackendPoolName)), }, }, }, @@ -220,21 +220,21 @@ func getLoadBalancingRules(lbSpec LBSpec, frontendIDs []network.SubResource) []n } return []network.LoadBalancingRule{ { - Name: to.StringPtr(lbRuleHTTPS), + Name: pointer.String(lbRuleHTTPS), LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ - DisableOutboundSnat: to.BoolPtr(true), + DisableOutboundSnat: pointer.Bool(true), Protocol: network.TransportProtocolTCP, - FrontendPort: to.Int32Ptr(lbSpec.APIServerPort), - BackendPort: to.Int32Ptr(lbSpec.APIServerPort), + FrontendPort: pointer.Int32(lbSpec.APIServerPort), + BackendPort: pointer.Int32(lbSpec.APIServerPort), IdleTimeoutInMinutes: lbSpec.IdleTimeoutInMinutes, - EnableFloatingIP: to.BoolPtr(false), + EnableFloatingIP: pointer.Bool(false), LoadDistribution: network.LoadDistributionDefault, FrontendIPConfiguration: &frontendIPConfig, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr(azure.AddressPoolID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, lbSpec.BackendPoolName)), + ID: pointer.String(azure.AddressPoolID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, lbSpec.BackendPoolName)), }, Probe: &network.SubResource{ - ID: to.StringPtr(azure.ProbeID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, tcpProbe)), + ID: pointer.String(azure.ProbeID(lbSpec.SubscriptionID, lbSpec.ResourceGroup, lbSpec.Name, tcpProbe)), }, }, }, @@ -246,7 +246,7 @@ func getLoadBalancingRules(lbSpec LBSpec, frontendIDs []network.SubResource) []n func getBackendAddressPools(lbSpec LBSpec) []network.BackendAddressPool { return []network.BackendAddressPool{ { - Name: to.StringPtr(lbSpec.BackendPoolName), + Name: pointer.String(lbSpec.BackendPoolName), }, } } @@ -255,12 +255,12 @@ func getProbes(lbSpec LBSpec) []network.Probe { if lbSpec.Role == infrav1.APIServerRole { return []network.Probe{ { - Name: to.StringPtr(tcpProbe), + Name: pointer.String(tcpProbe), ProbePropertiesFormat: &network.ProbePropertiesFormat{ Protocol: network.ProbeProtocolTCP, - Port: to.Int32Ptr(lbSpec.APIServerPort), - IntervalInSeconds: to.Int32Ptr(15), - NumberOfProbes: to.Int32Ptr(4), + Port: pointer.Int32(lbSpec.APIServerPort), + IntervalInSeconds: pointer.Int32(15), + NumberOfProbes: pointer.Int32(4), }, }, } @@ -270,7 +270,7 @@ func getProbes(lbSpec LBSpec) []network.Probe { func probeExists(probes []network.Probe, probe network.Probe) bool { for _, p := range probes { - if to.String(p.Name) == to.String(probe.Name) { + if pointer.StringDeref(p.Name, "") == pointer.StringDeref(probe.Name, "") { return true } } @@ -279,7 +279,7 @@ func probeExists(probes []network.Probe, probe network.Probe) bool { func outboundRuleExists(rules []network.OutboundRule, rule network.OutboundRule) bool { for _, r := range rules { - if to.String(r.Name) == to.String(rule.Name) { + if pointer.StringDeref(r.Name, "") == pointer.StringDeref(rule.Name, "") { return true } } @@ -288,7 +288,7 @@ func outboundRuleExists(rules []network.OutboundRule, rule network.OutboundRule) func poolExists(pools []network.BackendAddressPool, pool network.BackendAddressPool) bool { for _, p := range pools { - if to.String(p.Name) == to.String(pool.Name) { + if pointer.StringDeref(p.Name, "") == pointer.StringDeref(pool.Name, "") { return true } } @@ -297,7 +297,7 @@ func poolExists(pools []network.BackendAddressPool, pool network.BackendAddressP func lbRuleExists(rules []network.LoadBalancingRule, rule network.LoadBalancingRule) bool { for _, r := range rules { - if to.String(r.Name) == to.String(rule.Name) { + if pointer.StringDeref(r.Name, "") == pointer.StringDeref(rule.Name, "") { return true } } @@ -306,7 +306,7 @@ func lbRuleExists(rules []network.LoadBalancingRule, rule network.LoadBalancingR func ipExists(configs []network.FrontendIPConfiguration, config network.FrontendIPConfiguration) bool { for _, ip := range configs { - if to.String(ip.Name) == to.String(config.Name) { + if pointer.StringDeref(ip.Name, "") == pointer.StringDeref(config.Name, "") { return true } } diff --git a/azure/services/loadbalancers/spec_test.go b/azure/services/loadbalancers/spec_test.go index be074c1f4eb4..14022ddf02bc 100644 --- a/azure/services/loadbalancers/spec_test.go +++ b/azure/services/loadbalancers/spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -168,39 +168,39 @@ func TestParameters(t *testing.T) { func newDefaultNodeOutboundLB() network.LoadBalancer { return network.LoadBalancer{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.NodeOutboundRole), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "sigs.k8s.io_cluster-api-provider-azure_role": pointer.String(infrav1.NodeOutboundRole), }, Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, - Location: to.StringPtr("my-location"), + Location: pointer.String("my-location"), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ { - Name: to.StringPtr("my-cluster-frontEnd"), + Name: pointer.String("my-cluster-frontEnd"), FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ - PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/outbound-publicip")}, + PublicIPAddress: &network.PublicIPAddress{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/outbound-publicip")}, }, }, }, BackendAddressPools: &[]network.BackendAddressPool{ { - Name: to.StringPtr("my-cluster-outboundBackendPool"), + Name: pointer.String("my-cluster-outboundBackendPool"), }, }, LoadBalancingRules: &[]network.LoadBalancingRule{}, Probes: &[]network.Probe{}, OutboundRules: &[]network.OutboundRule{ { - Name: to.StringPtr("OutboundNATAllProtocols"), + Name: pointer.String("OutboundNATAllProtocols"), OutboundRulePropertiesFormat: &network.OutboundRulePropertiesFormat{ FrontendIPConfigurations: &[]network.SubResource{ - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-cluster/frontendIPConfigurations/my-cluster-frontEnd")}, + {ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-cluster/frontendIPConfigurations/my-cluster-frontEnd")}, }, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-cluster/backendAddressPools/my-cluster-outboundBackendPool"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-cluster/backendAddressPools/my-cluster-outboundBackendPool"), }, Protocol: network.LoadBalancerOutboundRuleProtocolAll, - IdleTimeoutInMinutes: to.Int32Ptr(30), + IdleTimeoutInMinutes: pointer.Int32(30), }, }, }, @@ -211,96 +211,96 @@ func newDefaultNodeOutboundLB() network.LoadBalancer { func newSamplePublicAPIServerLB(verifyFrontendIP bool, verifyBackendAddressPools bool, verifyLBRules bool, verifyProbes bool, verifyOutboundRules bool) network.LoadBalancer { var subnet *network.Subnet var backendAddressPoolProps *network.BackendAddressPoolPropertiesFormat - enableFloatingIP := to.BoolPtr(false) - numProbes := to.Int32Ptr(4) - idleTimeout := to.Int32Ptr(4) + enableFloatingIP := pointer.Bool(false) + numProbes := pointer.Int32(4) + idleTimeout := pointer.Int32(4) if verifyFrontendIP { subnet = &network.Subnet{ - Name: to.StringPtr("fake-test-subnet"), + Name: pointer.String("fake-test-subnet"), } } if verifyBackendAddressPools { backendAddressPoolProps = &network.BackendAddressPoolPropertiesFormat{ - Location: to.StringPtr("fake-test-location"), + Location: pointer.String("fake-test-location"), } } if verifyLBRules { - enableFloatingIP = to.BoolPtr(true) + enableFloatingIP = pointer.Bool(true) } if verifyProbes { - numProbes = to.Int32Ptr(999) + numProbes = pointer.Int32(999) } if verifyOutboundRules { - idleTimeout = to.Int32Ptr(1000) + idleTimeout = pointer.Int32(1000) } return network.LoadBalancer{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.APIServerRole), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "sigs.k8s.io_cluster-api-provider-azure_role": pointer.String(infrav1.APIServerRole), }, Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, - Location: to.StringPtr("my-location"), + Location: pointer.String("my-location"), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ { - Name: to.StringPtr("my-publiclb-frontEnd"), + Name: pointer.String("my-publiclb-frontEnd"), FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ - PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/my-publicip")}, + PublicIPAddress: &network.PublicIPAddress{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/my-publicip")}, Subnet: subnet, // Add to verify that FrontendIPConfigurations aren't overwritten on update }, }, }, BackendAddressPools: &[]network.BackendAddressPool{ { - Name: to.StringPtr("my-publiclb-backendPool"), + Name: pointer.String("my-publiclb-backendPool"), BackendAddressPoolPropertiesFormat: backendAddressPoolProps, // Add to verify that BackendAddressPools aren't overwritten on update }, }, LoadBalancingRules: &[]network.LoadBalancingRule{ { - Name: to.StringPtr(lbRuleHTTPS), + Name: pointer.String(lbRuleHTTPS), LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ - DisableOutboundSnat: to.BoolPtr(true), + DisableOutboundSnat: pointer.Bool(true), Protocol: network.TransportProtocolTCP, - FrontendPort: to.Int32Ptr(6443), - BackendPort: to.Int32Ptr(6443), - IdleTimeoutInMinutes: to.Int32Ptr(4), + FrontendPort: pointer.Int32(6443), + BackendPort: pointer.Int32(6443), + IdleTimeoutInMinutes: pointer.Int32(4), EnableFloatingIP: enableFloatingIP, // Add to verify that LoadBalancingRules aren't overwritten on update LoadDistribution: network.LoadDistributionDefault, FrontendIPConfiguration: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/frontendIPConfigurations/my-publiclb-frontEnd"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/frontendIPConfigurations/my-publiclb-frontEnd"), }, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/backendAddressPools/my-publiclb-backendPool"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/backendAddressPools/my-publiclb-backendPool"), }, Probe: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/probes/TCPProbe"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/probes/TCPProbe"), }, }, }, }, Probes: &[]network.Probe{ { - Name: to.StringPtr(tcpProbe), + Name: pointer.String(tcpProbe), ProbePropertiesFormat: &network.ProbePropertiesFormat{ Protocol: network.ProbeProtocolTCP, - Port: to.Int32Ptr(6443), - IntervalInSeconds: to.Int32Ptr(15), + Port: pointer.Int32(6443), + IntervalInSeconds: pointer.Int32(15), NumberOfProbes: numProbes, // Add to verify that Probes aren't overwritten on update }, }, }, OutboundRules: &[]network.OutboundRule{ { - Name: to.StringPtr("OutboundNATAllProtocols"), + Name: pointer.String("OutboundNATAllProtocols"), OutboundRulePropertiesFormat: &network.OutboundRulePropertiesFormat{ FrontendIPConfigurations: &[]network.SubResource{ - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/frontendIPConfigurations/my-publiclb-frontEnd")}, + {ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/frontendIPConfigurations/my-publiclb-frontEnd")}, }, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/backendAddressPools/my-publiclb-backendPool"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-publiclb/backendAddressPools/my-publiclb-backendPool"), }, Protocol: network.LoadBalancerOutboundRuleProtocolAll, IdleTimeoutInMinutes: idleTimeout, // Add to verify that OutboundRules aren't overwritten on update @@ -314,48 +314,48 @@ func newSamplePublicAPIServerLB(verifyFrontendIP bool, verifyBackendAddressPools func newDefaultInternalAPIServerLB() network.LoadBalancer { return network.LoadBalancer{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.APIServerRole), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "sigs.k8s.io_cluster-api-provider-azure_role": pointer.String(infrav1.APIServerRole), }, Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, - Location: to.StringPtr("my-location"), + Location: pointer.String("my-location"), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ { - Name: to.StringPtr("my-private-lb-frontEnd"), + Name: pointer.String("my-private-lb-frontEnd"), FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ PrivateIPAllocationMethod: network.IPAllocationMethodStatic, Subnet: &network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-cp-subnet"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-cp-subnet"), }, - PrivateIPAddress: to.StringPtr("10.0.0.10"), + PrivateIPAddress: pointer.String("10.0.0.10"), }, }, }, BackendAddressPools: &[]network.BackendAddressPool{ { - Name: to.StringPtr("my-private-lb-backendPool"), + Name: pointer.String("my-private-lb-backendPool"), }, }, LoadBalancingRules: &[]network.LoadBalancingRule{ { - Name: to.StringPtr(lbRuleHTTPS), + Name: pointer.String(lbRuleHTTPS), LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ - DisableOutboundSnat: to.BoolPtr(true), + DisableOutboundSnat: pointer.Bool(true), Protocol: network.TransportProtocolTCP, - FrontendPort: to.Int32Ptr(6443), - BackendPort: to.Int32Ptr(6443), - IdleTimeoutInMinutes: to.Int32Ptr(4), - EnableFloatingIP: to.BoolPtr(false), + FrontendPort: pointer.Int32(6443), + BackendPort: pointer.Int32(6443), + IdleTimeoutInMinutes: pointer.Int32(4), + EnableFloatingIP: pointer.Bool(false), LoadDistribution: network.LoadDistributionDefault, FrontendIPConfiguration: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/frontendIPConfigurations/my-private-lb-frontEnd"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/frontendIPConfigurations/my-private-lb-frontEnd"), }, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/backendAddressPools/my-private-lb-backendPool"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/backendAddressPools/my-private-lb-backendPool"), }, Probe: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/probes/TCPProbe"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/probes/TCPProbe"), }, }, }, @@ -363,12 +363,12 @@ func newDefaultInternalAPIServerLB() network.LoadBalancer { OutboundRules: &[]network.OutboundRule{}, Probes: &[]network.Probe{ { - Name: to.StringPtr(tcpProbe), + Name: pointer.String(tcpProbe), ProbePropertiesFormat: &network.ProbePropertiesFormat{ Protocol: network.ProbeProtocolTCP, - Port: to.Int32Ptr(6443), - IntervalInSeconds: to.Int32Ptr(15), - NumberOfProbes: to.Int32Ptr(4), + Port: pointer.Int32(6443), + IntervalInSeconds: pointer.Int32(15), + NumberOfProbes: pointer.Int32(4), }, }, }, diff --git a/azure/services/managedclusters/managedclusters.go b/azure/services/managedclusters/managedclusters.go index 6f199238b7fc..f6b1979e16a6 100644 --- a/azure/services/managedclusters/managedclusters.go +++ b/azure/services/managedclusters/managedclusters.go @@ -20,9 +20,9 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async" @@ -87,7 +87,7 @@ func (s *Service) Reconcile(ctx context.Context) error { } // Update control plane endpoint. endpoint := clusterv1.APIEndpoint{ - Host: to.String(managedCluster.ManagedClusterProperties.Fqdn), + Host: pointer.StringDeref(managedCluster.ManagedClusterProperties.Fqdn, ""), Port: 443, } s.Scope.SetControlPlaneEndpoint(endpoint) diff --git a/azure/services/managedclusters/spec.go b/azure/services/managedclusters/spec.go index a88c55d5cba3..a41f6086a0b7 100644 --- a/azure/services/managedclusters/spec.go +++ b/azure/services/managedclusters/spec.go @@ -24,9 +24,9 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -267,24 +267,24 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing interface{ Type: containerservice.ResourceIdentityTypeSystemAssigned, }, Location: &s.Location, - Tags: *to.StringMapPtr(s.Tags), + Tags: *azure.StringMapPtr(s.Tags), ManagedClusterProperties: &containerservice.ManagedClusterProperties{ NodeResourceGroup: &s.NodeResourceGroup, - EnableRBAC: to.BoolPtr(true), + EnableRBAC: pointer.Bool(true), DNSPrefix: &s.Name, KubernetesVersion: &s.Version, LinuxProfile: &containerservice.LinuxProfile{ - AdminUsername: to.StringPtr(azure.DefaultAKSUserName), + AdminUsername: pointer.String(azure.DefaultAKSUserName), SSH: &containerservice.SSHConfiguration{ PublicKeys: &[]containerservice.SSHPublicKey{ { - KeyData: to.StringPtr(string(decodedSSHPublicKey)), + KeyData: pointer.String(string(decodedSSHPublicKey)), }, }, }, }, ServicePrincipalProfile: &containerservice.ManagedClusterServicePrincipalProfile{ - ClientID: to.StringPtr("msi"), + ClientID: pointer.String("msi"), }, AgentPoolProfiles: &[]containerservice.ManagedClusterAgentPoolProfile{}, NetworkProfile: &containerservice.NetworkProfile{ @@ -335,7 +335,7 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing interface{ Enabled: &item.Enabled, } if item.Config != nil { - addonProfile.Config = *to.StringMapPtr(item.Config) + addonProfile.Config = *azure.StringMapPtr(item.Config) } managedCluster.AddonProfiles[item.Name] = addonProfile } @@ -431,7 +431,7 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing interface{ if !ok { return nil, fmt.Errorf("%T is not a containerservice.AgentPool", agentPool) } - agentPool.Name = to.StringPtr(spec.ResourceName()) + agentPool.Name = pointer.String(spec.ResourceName()) profile := converters.AgentPoolToManagedClusterAgentPoolProfile(agentPool) *managedCluster.AgentPoolProfiles = append(*managedCluster.AgentPoolProfiles, profile) } diff --git a/azure/services/managedclusters/spec_test.go b/azure/services/managedclusters/spec_test.go index efbe9dbb3f24..745ffc269347 100644 --- a/azure/services/managedclusters/spec_test.go +++ b/azure/services/managedclusters/spec_test.go @@ -21,9 +21,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" @@ -42,7 +42,7 @@ func TestParameters(t *testing.T) { name: "managedcluster in non-terminal provisioning state", existing: containerservice.ManagedCluster{ ManagedClusterProperties: &containerservice.ManagedClusterProperties{ - ProvisioningState: to.StringPtr("Deleting"), + ProvisioningState: pointer.String("Deleting"), }, }, spec: &ManagedClusterSpec{ @@ -84,9 +84,9 @@ func TestParameters(t *testing.T) { Replicas: int32(4), Cluster: "test-managedcluster", SKU: "test_SKU", - Version: to.StringPtr("v1.22.0"), + Version: pointer.String("v1.22.0"), VnetSubnetID: "fake/subnet/id", - MaxPods: to.Int32Ptr(int32(32)), + MaxPods: pointer.Int32(int32(32)), AvailabilityZones: []string{"1", "2"}, AdditionalTags: map[string]string{ "test-tag": "test-value", @@ -132,7 +132,7 @@ func TestParameters(t *testing.T) { }, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(containerservice.ManagedCluster{})) - g.Expect(result.(containerservice.ManagedCluster).KubernetesVersion).To(Equal(to.StringPtr("v1.22.99"))) + g.Expect(result.(containerservice.ManagedCluster).KubernetesVersion).To(Equal(pointer.String("v1.22.99"))) }, }, { @@ -169,56 +169,56 @@ func TestParameters(t *testing.T) { func getExistingCluster() containerservice.ManagedCluster { mc := getSampleManagedCluster() - mc.ProvisioningState = to.StringPtr("Succeeded") - mc.ID = to.StringPtr("test-id") + mc.ProvisioningState = pointer.String("Succeeded") + mc.ID = pointer.String("test-id") return mc } func getSampleManagedCluster() containerservice.ManagedCluster { return containerservice.ManagedCluster{ ManagedClusterProperties: &containerservice.ManagedClusterProperties{ - KubernetesVersion: to.StringPtr("v1.22.0"), - DNSPrefix: to.StringPtr("test-managedcluster"), + KubernetesVersion: pointer.String("v1.22.0"), + DNSPrefix: pointer.String("test-managedcluster"), AgentPoolProfiles: &[]containerservice.ManagedClusterAgentPoolProfile{ { - Name: to.StringPtr("test-agentpool-0"), + Name: pointer.String("test-agentpool-0"), Mode: containerservice.AgentPoolMode(infrav1exp.NodePoolModeSystem), - Count: to.Int32Ptr(2), + Count: pointer.Int32(2), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - OsDiskSizeGB: to.Int32Ptr(0), + OsDiskSizeGB: pointer.Int32(0), Tags: map[string]*string{ - "test-tag": to.StringPtr("test-value"), + "test-tag": pointer.String("test-value"), }, }, { - Name: to.StringPtr("test-agentpool-1"), + Name: pointer.String("test-agentpool-1"), Mode: containerservice.AgentPoolMode(infrav1exp.NodePoolModeUser), - Count: to.Int32Ptr(4), + Count: pointer.Int32(4), Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, - OsDiskSizeGB: to.Int32Ptr(0), - VMSize: to.StringPtr("test_SKU"), - OrchestratorVersion: to.StringPtr("v1.22.0"), - VnetSubnetID: to.StringPtr("fake/subnet/id"), - MaxPods: to.Int32Ptr(int32(32)), + OsDiskSizeGB: pointer.Int32(0), + VMSize: pointer.String("test_SKU"), + OrchestratorVersion: pointer.String("v1.22.0"), + VnetSubnetID: pointer.String("fake/subnet/id"), + MaxPods: pointer.Int32(int32(32)), AvailabilityZones: &[]string{"1", "2"}, Tags: map[string]*string{ - "test-tag": to.StringPtr("test-value"), + "test-tag": pointer.String("test-value"), }, }, }, LinuxProfile: &containerservice.LinuxProfile{ - AdminUsername: to.StringPtr(azure.DefaultAKSUserName), + AdminUsername: pointer.String(azure.DefaultAKSUserName), SSH: &containerservice.SSHConfiguration{ PublicKeys: &[]containerservice.SSHPublicKey{ { - KeyData: to.StringPtr(""), + KeyData: pointer.String(""), }, }, }, }, - ServicePrincipalProfile: &containerservice.ManagedClusterServicePrincipalProfile{ClientID: to.StringPtr("msi")}, - NodeResourceGroup: to.StringPtr("test-node-rg"), - EnableRBAC: to.BoolPtr(true), + ServicePrincipalProfile: &containerservice.ManagedClusterServicePrincipalProfile{ClientID: pointer.String("msi")}, + NodeResourceGroup: pointer.String("test-node-rg"), + EnableRBAC: pointer.Bool(true), NetworkProfile: &containerservice.NetworkProfile{ LoadBalancerSku: containerservice.LoadBalancerSku("Standard"), }, @@ -226,9 +226,9 @@ func getSampleManagedCluster() containerservice.ManagedCluster { Identity: &containerservice.ManagedClusterIdentity{ Type: containerservice.ResourceIdentityTypeSystemAssigned, }, - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Tags: map[string]*string{ - "test-tag": to.StringPtr("test-value"), + "test-tag": pointer.String("test-value"), }, } } diff --git a/azure/services/natgateways/natgateways_test.go b/azure/services/natgateways/natgateways_test.go index 29cb01777cba..abe0cfcbd1be 100644 --- a/azure/services/natgateways/natgateways_test.go +++ b/azure/services/natgateways/natgateways_test.go @@ -23,10 +23,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -49,7 +49,7 @@ var ( NatGatewayIP: infrav1.PublicIPSpec{Name: "pip-node-subnet"}, } natGateway1 = network.NatGateway{ - ID: to.StringPtr("/subscriptions/my-sub/resourceGroups/my-rg/providers/Microsoft.Network/natGateways/my-node-natgateway-1"), + ID: pointer.String("/subscriptions/my-sub/resourceGroups/my-rg/providers/Microsoft.Network/natGateways/my-node-natgateway-1"), } customVNetTags = infrav1.Tags{ "Name": "my-vnet", diff --git a/azure/services/natgateways/spec.go b/azure/services/natgateways/spec.go index 05c155c9bad5..9009be1c033f 100644 --- a/azure/services/natgateways/spec.go +++ b/azure/services/natgateways/spec.go @@ -21,8 +21,8 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -69,20 +69,20 @@ func (s *NatGatewaySpec) Parameters(ctx context.Context, existing interface{}) ( } natGatewayToCreate := network.NatGateway{ - Name: to.StringPtr(s.Name), - Location: to.StringPtr(s.Location), + Name: pointer.String(s.Name), + Location: pointer.String(s.Location), Sku: &network.NatGatewaySku{Name: network.NatGatewaySkuNameStandard}, NatGatewayPropertiesFormat: &network.NatGatewayPropertiesFormat{ PublicIPAddresses: &[]network.SubResource{ { - ID: to.StringPtr(azure.PublicIPID(s.SubscriptionID, s.ResourceGroupName(), s.NatGatewayIP.Name)), + ID: pointer.String(azure.PublicIPID(s.SubscriptionID, s.ResourceGroupName(), s.NatGatewayIP.Name)), }, }, }, Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), + Name: pointer.String(s.Name), Additional: s.AdditionalTags, })), } diff --git a/azure/services/networkinterfaces/spec.go b/azure/services/networkinterfaces/spec.go index 5f287fd60348..7b79e3734b61 100644 --- a/azure/services/networkinterfaces/spec.go +++ b/azure/services/networkinterfaces/spec.go @@ -21,8 +21,8 @@ import ( "strconv" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -88,18 +88,18 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet } primaryIPConfig := &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), + Primary: pointer.Bool(true), } subnet := &network.Subnet{ - ID: to.StringPtr(azure.SubnetID(s.SubscriptionID, s.VNetResourceGroup, s.VNetName, s.SubnetName)), + ID: pointer.String(azure.SubnetID(s.SubscriptionID, s.VNetResourceGroup, s.VNetName, s.SubnetName)), } primaryIPConfig.Subnet = subnet primaryIPConfig.PrivateIPAllocationMethod = network.IPAllocationMethodDynamic if s.StaticIPAddress != "" { primaryIPConfig.PrivateIPAllocationMethod = network.IPAllocationMethodStatic - primaryIPConfig.PrivateIPAddress = to.StringPtr(s.StaticIPAddress) + primaryIPConfig.PrivateIPAddress = pointer.String(s.StaticIPAddress) } backendAddressPools := []network.BackendAddressPool{} @@ -107,13 +107,13 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet if s.PublicLBAddressPoolName != "" { backendAddressPools = append(backendAddressPools, network.BackendAddressPool{ - ID: to.StringPtr(azure.AddressPoolID(s.SubscriptionID, s.ResourceGroup, s.PublicLBName, s.PublicLBAddressPoolName)), + ID: pointer.String(azure.AddressPoolID(s.SubscriptionID, s.ResourceGroup, s.PublicLBName, s.PublicLBAddressPoolName)), }) } if s.PublicLBNATRuleName != "" { primaryIPConfig.LoadBalancerInboundNatRules = &[]network.InboundNatRule{ { - ID: to.StringPtr(azure.NATRuleID(s.SubscriptionID, s.ResourceGroup, s.PublicLBName, s.PublicLBNATRuleName)), + ID: pointer.String(azure.NATRuleID(s.SubscriptionID, s.ResourceGroup, s.PublicLBName, s.PublicLBNATRuleName)), }, } } @@ -121,14 +121,14 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet if s.InternalLBName != "" && s.InternalLBAddressPoolName != "" { backendAddressPools = append(backendAddressPools, network.BackendAddressPool{ - ID: to.StringPtr(azure.AddressPoolID(s.SubscriptionID, s.ResourceGroup, s.InternalLBName, s.InternalLBAddressPoolName)), + ID: pointer.String(azure.AddressPoolID(s.SubscriptionID, s.ResourceGroup, s.InternalLBName, s.InternalLBAddressPoolName)), }) } primaryIPConfig.LoadBalancerBackendAddressPools = &backendAddressPools if s.PublicIPName != "" { primaryIPConfig.PublicIPAddress = &network.PublicIPAddress{ - ID: to.StringPtr(azure.PublicIPID(s.SubscriptionID, s.ResourceGroup, s.PublicIPName)), + ID: pointer.String(azure.PublicIPID(s.SubscriptionID, s.ResourceGroup, s.PublicIPName)), } } @@ -149,7 +149,7 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet ipConfigurations := []network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: primaryIPConfig, }, } @@ -160,7 +160,7 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet newIPConfigPropertiesFormat := &network.InterfaceIPConfigurationPropertiesFormat{} newIPConfigPropertiesFormat.Subnet = subnet config := network.InterfaceIPConfiguration{ - Name: to.StringPtr(s.Name + "-" + strconv.Itoa(i)), + Name: pointer.String(s.Name + "-" + strconv.Itoa(i)), InterfaceIPConfigurationPropertiesFormat: newIPConfigPropertiesFormat, } if c.PrivateIP != nil && *c.PrivateIP != "" { @@ -184,15 +184,15 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet }, } } - config.InterfaceIPConfigurationPropertiesFormat.Primary = to.BoolPtr(false) + config.InterfaceIPConfigurationPropertiesFormat.Primary = pointer.Bool(false) ipConfigurations = append(ipConfigurations, config) } if s.IPv6Enabled { ipv6Config := network.InterfaceIPConfiguration{ - Name: to.StringPtr("ipConfigv6"), + Name: pointer.String("ipConfigv6"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ PrivateIPAddressVersion: "IPv6", - Primary: to.BoolPtr(false), + Primary: pointer.Bool(false), Subnet: &network.Subnet{ID: subnet.ID}, }, } @@ -201,17 +201,17 @@ func (s *NICSpec) Parameters(ctx context.Context, existing interface{}) (paramet } return network.Interface{ - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ EnableAcceleratedNetworking: s.AcceleratedNetworking, IPConfigurations: &ipConfigurations, DNSSettings: &dnsSettings, - EnableIPForwarding: to.BoolPtr(s.EnableIPForwarding), + EnableIPForwarding: pointer.Bool(s.EnableIPForwarding), }, Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), + Name: pointer.String(s.Name), Additional: s.AdditionalTags, })), }, nil diff --git a/azure/services/networkinterfaces/spec_test.go b/azure/services/networkinterfaces/spec_test.go index 466aa1107ccd..e3e51ef0fc72 100644 --- a/azure/services/networkinterfaces/spec_test.go +++ b/azure/services/networkinterfaces/spec_test.go @@ -22,9 +22,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" "github.com/onsi/gomega/format" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus" ) @@ -43,21 +43,21 @@ var ( ClusterName: "my-cluster", } fakeSku = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v2"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v2"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "fake-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), Zones: &[]string{"1"}, }, }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilitySupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilitySupported)), }, }, } @@ -141,7 +141,7 @@ var ( VNetName: "my-vnet", VNetResourceGroup: "my-rg", PublicLBName: "my-public-lb", - AcceleratedNetworking: to.BoolPtr(false), + AcceleratedNetworking: pointer.Bool(false), ClusterName: "my-cluster", } @@ -276,24 +276,24 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(false), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(false), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool")}}, + Primary: pointer.Bool(true), + LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool")}}, PrivateIPAllocationMethod: network.IPAllocationMethodStatic, - PrivateIPAddress: to.StringPtr("fake.static.ip"), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + PrivateIPAddress: pointer.String("fake.static.ip"), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, }, }, }, @@ -310,23 +310,23 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(false), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(false), DNSSettings: &network.InterfaceDNSSettings{}, Primary: nil, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool")}}, + Primary: pointer.Bool(true), + LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool")}}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, }, }, }, @@ -343,26 +343,26 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(false), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(false), DNSSettings: &network.InterfaceDNSSettings{}, Primary: nil, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, - LoadBalancerInboundNatRules: &[]network.InboundNatRule{{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/inboundNatRules/azure-test1")}}, + LoadBalancerInboundNatRules: &[]network.InboundNatRule{{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/inboundNatRules/azure-test1")}}, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{ - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/my-public-lb-backendPool")}, - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-internal-lb/backendAddressPools/my-internal-lb-backendPool")}}, + {ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/my-public-lb-backendPool")}, + {ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-internal-lb/backendAddressPools/my-internal-lb-backendPool")}}, }, }, }, @@ -379,21 +379,21 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(false), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(false), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, @@ -412,21 +412,21 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(false), - EnableIPForwarding: to.BoolPtr(false), + EnableAcceleratedNetworking: pointer.Bool(false), + EnableIPForwarding: pointer.Bool(false), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, @@ -445,30 +445,30 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, }, { - Name: to.StringPtr("ipConfigv6"), + Name: pointer.String("ipConfigv6"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, - Primary: to.BoolPtr(false), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(false), PrivateIPAddressVersion: "IPv6", }, }, @@ -486,21 +486,21 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, @@ -519,21 +519,21 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, @@ -552,30 +552,30 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, }, { - Name: to.StringPtr("my-net-interface-1"), + Name: pointer.String("my-net-interface-1"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(false), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(false), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: nil, }, @@ -594,33 +594,33 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ Primary: nil, - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), DNSSettings: &network.InterfaceDNSSettings{}, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(true), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, PublicIPAddress: &network.PublicIPAddress{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/pip-azure-test1"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/pip-azure-test1"), }, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{}, }, }, { - Name: to.StringPtr("my-net-interface-1"), + Name: pointer.String("my-net-interface-1"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Primary: to.BoolPtr(false), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(false), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, LoadBalancerBackendAddressPools: nil, }, @@ -639,27 +639,27 @@ func TestParameters(t *testing.T) { g.Expect(result).To(BeAssignableToTypeOf(network.Interface{})) g.Expect(result.(network.Interface)).To(Equal(network.Interface{ Tags: map[string]*string{ - "Name": to.StringPtr("my-net-interface"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "Name": pointer.String("my-net-interface"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, - Location: to.StringPtr("fake-location"), + Location: pointer.String("fake-location"), InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ - EnableAcceleratedNetworking: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(false), + EnableAcceleratedNetworking: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(false), DNSSettings: &network.InterfaceDNSSettings{ - DNSServers: to.StringSlicePtr([]string{"123.123.123.123", "124.124.124.124"}), + DNSServers: &[]string{"123.123.123.123", "124.124.124.124"}, }, IPConfigurations: &[]network.InterfaceIPConfiguration{ { - Name: to.StringPtr("pipConfig"), + Name: pointer.String("pipConfig"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, - Primary: to.BoolPtr(true), + Subnet: &network.Subnet{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, + Primary: pointer.Bool(true), PrivateIPAllocationMethod: network.IPAllocationMethodDynamic, - LoadBalancerInboundNatRules: &[]network.InboundNatRule{{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/inboundNatRules/azure-test1")}}, + LoadBalancerInboundNatRules: &[]network.InboundNatRule{{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/inboundNatRules/azure-test1")}}, LoadBalancerBackendAddressPools: &[]network.BackendAddressPool{ - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/my-public-lb-backendPool")}, - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-internal-lb/backendAddressPools/my-internal-lb-backendPool")}}, + {ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/my-public-lb-backendPool")}, + {ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-internal-lb/backendAddressPools/my-internal-lb-backendPool")}}, }, }, }, diff --git a/azure/services/privatedns/link_spec.go b/azure/services/privatedns/link_spec.go index 7b1f8e5190d5..2e8d22cade4a 100644 --- a/azure/services/privatedns/link_spec.go +++ b/azure/services/privatedns/link_spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -67,11 +67,11 @@ func (s LinkSpec) Parameters(ctx context.Context, existing interface{}) (params return privatedns.VirtualNetworkLink{ VirtualNetworkLinkProperties: &privatedns.VirtualNetworkLinkProperties{ VirtualNetwork: &privatedns.SubResource{ - ID: to.StringPtr(azure.VNetID(s.SubscriptionID, s.VNetResourceGroup, s.VNetName)), + ID: pointer.String(azure.VNetID(s.SubscriptionID, s.VNetResourceGroup, s.VNetName)), }, - RegistrationEnabled: to.BoolPtr(false), + RegistrationEnabled: pointer.Bool(false), }, - Location: to.StringPtr(azure.Global), + Location: pointer.String(azure.Global), Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, diff --git a/azure/services/privatedns/link_spec_test.go b/azure/services/privatedns/link_spec_test.go index 2d63fd717a68..d8fda0bf22f9 100644 --- a/azure/services/privatedns/link_spec_test.go +++ b/azure/services/privatedns/link_spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -70,13 +70,13 @@ func TestLinkSpec_Parameters(t *testing.T) { g.Expect(result).To(Equal(privatedns.VirtualNetworkLink{ VirtualNetworkLinkProperties: &privatedns.VirtualNetworkLinkProperties{ VirtualNetwork: &privatedns.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-vnet-rg/providers/Microsoft.Network/virtualNetworks/my-vnet"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-vnet-rg/providers/Microsoft.Network/virtualNetworks/my-vnet"), }, - RegistrationEnabled: to.BoolPtr(false), + RegistrationEnabled: pointer.Bool(false), }, - Location: to.StringPtr(azure.Global), + Location: pointer.String(azure.Global), Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, })) }, @@ -86,7 +86,7 @@ func TestLinkSpec_Parameters(t *testing.T) { expectedError: "", spec: linkSpec, existing: privatedns.VirtualNetworkLink{Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }}, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeNil()) diff --git a/azure/services/privatedns/privatedns_test.go b/azure/services/privatedns/privatedns_test.go index 09628ab52091..9f3d9fe8fff6 100644 --- a/azure/services/privatedns/privatedns_test.go +++ b/azure/services/privatedns/privatedns_test.go @@ -22,10 +22,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-10-01/resources" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -83,8 +83,8 @@ var ( managedTags = resources.TagsResource{ Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_" + clusterName: to.StringPtr("owned"), + "foo": pointer.String("bar"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_" + clusterName: pointer.String("owned"), }, }, } @@ -92,8 +92,8 @@ var ( unmanagedTags = resources.TagsResource{ Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "something": to.StringPtr("else"), + "foo": pointer.String("bar"), + "something": pointer.String("else"), }, }, } diff --git a/azure/services/privatedns/record_spec.go b/azure/services/privatedns/record_spec.go index c6dbc6cb95f9..aec44b4921ee 100644 --- a/azure/services/privatedns/record_spec.go +++ b/azure/services/privatedns/record_spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -57,7 +57,7 @@ func (s RecordSpec) Parameters(ctx context.Context, existing interface{}) (param } set := privatedns.RecordSet{ RecordSetProperties: &privatedns.RecordSetProperties{ - TTL: to.Int64Ptr(300), + TTL: pointer.Int64(300), }, } recordType := converters.GetRecordType(s.Record.IP) diff --git a/azure/services/privatedns/record_spec_test.go b/azure/services/privatedns/record_spec_test.go index cda9e17340fa..480aefbcc971 100644 --- a/azure/services/privatedns/record_spec_test.go +++ b/azure/services/privatedns/record_spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -70,10 +70,10 @@ func TestRecordSpec_Parameters(t *testing.T) { expect: func(g *WithT, result interface{}) { g.Expect(result).To(Equal(privatedns.RecordSet{ RecordSetProperties: &privatedns.RecordSetProperties{ - TTL: to.Int64Ptr(300), + TTL: pointer.Int64(300), ARecords: &[]privatedns.ARecord{ { - Ipv4Address: to.StringPtr("10.0.0.8"), + Ipv4Address: pointer.String("10.0.0.8"), }, }, }, @@ -87,10 +87,10 @@ func TestRecordSpec_Parameters(t *testing.T) { expect: func(g *WithT, result interface{}) { g.Expect(result).To(Equal(privatedns.RecordSet{ RecordSetProperties: &privatedns.RecordSetProperties{ - TTL: to.Int64Ptr(300), + TTL: pointer.Int64(300), AaaaRecords: &[]privatedns.AaaaRecord{ { - Ipv6Address: to.StringPtr("2603:1030:805:2::b"), + Ipv6Address: pointer.String("2603:1030:805:2::b"), }, }, }, diff --git a/azure/services/privatedns/zone_spec.go b/azure/services/privatedns/zone_spec.go index 7b0c7bc348eb..124b78c27be9 100644 --- a/azure/services/privatedns/zone_spec.go +++ b/azure/services/privatedns/zone_spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -61,7 +61,7 @@ func (s ZoneSpec) Parameters(ctx context.Context, existing interface{}) (params } return privatedns.PrivateZone{ - Location: to.StringPtr(azure.Global), + Location: pointer.String(azure.Global), Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, diff --git a/azure/services/privatedns/zone_spec_test.go b/azure/services/privatedns/zone_spec_test.go index 76ce1f7454ff..f91235f8391f 100644 --- a/azure/services/privatedns/zone_spec_test.go +++ b/azure/services/privatedns/zone_spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -64,9 +64,9 @@ func TestZoneSpec_Parameters(t *testing.T) { spec: zoneSpec, expect: func(g *WithT, result interface{}) { g.Expect(result).To(Equal(privatedns.PrivateZone{ - Location: to.StringPtr(azure.Global), + Location: pointer.String(azure.Global), Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, })) }, @@ -76,7 +76,7 @@ func TestZoneSpec_Parameters(t *testing.T) { expectedError: "", spec: zoneSpec, existing: privatedns.PrivateZone{Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }}, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeNil()) diff --git a/azure/services/publicips/publicips_test.go b/azure/services/publicips/publicips_test.go index b74d87b51486..8efbd95141f2 100644 --- a/azure/services/publicips/publicips_test.go +++ b/azure/services/publicips/publicips_test.go @@ -23,10 +23,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-10-01/resources" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -97,8 +97,8 @@ var ( managedTags = resources.TagsResource{ Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "foo": pointer.String("bar"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), }, }, } @@ -106,8 +106,8 @@ var ( unmanagedTags = resources.TagsResource{ Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "something": to.StringPtr("else"), + "foo": pointer.String("bar"), + "something": pointer.String("else"), }, }, } diff --git a/azure/services/publicips/spec.go b/azure/services/publicips/spec.go index 7c898a9a84c3..8f48f6c9fb49 100644 --- a/azure/services/publicips/spec.go +++ b/azure/services/publicips/spec.go @@ -21,8 +21,8 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -74,8 +74,8 @@ func (s *PublicIPSpec) Parameters(ctx context.Context, existing interface{}) (pa var dnsSettings *network.PublicIPAddressDNSSettings if s.DNSName != "" { dnsSettings = &network.PublicIPAddressDNSSettings{ - DomainNameLabel: to.StringPtr(strings.Split(s.DNSName, ".")[0]), - Fqdn: to.StringPtr(s.DNSName), + DomainNameLabel: pointer.String(strings.Split(s.DNSName, ".")[0]), + Fqdn: pointer.String(s.DNSName), } } @@ -83,18 +83,18 @@ func (s *PublicIPSpec) Parameters(ctx context.Context, existing interface{}) (pa Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), + Name: pointer.String(s.Name), Additional: s.AdditionalTags, })), Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard}, - Name: to.StringPtr(s.Name), - Location: to.StringPtr(s.Location), + Name: pointer.String(s.Name), + Location: pointer.String(s.Location), PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ PublicIPAddressVersion: addressVersion, PublicIPAllocationMethod: network.IPAllocationMethodStatic, DNSSettings: dnsSettings, IPTags: converters.IPTagsToSDK(s.IPTags), }, - Zones: to.StringSlicePtr(s.FailureDomains), + Zones: &s.FailureDomains, }, nil } diff --git a/azure/services/publicips/spec_test.go b/azure/services/publicips/spec_test.go index de0c41864bd9..0efb84b459c5 100644 --- a/azure/services/publicips/spec_test.go +++ b/azure/services/publicips/spec_test.go @@ -22,9 +22,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -51,59 +51,59 @@ var ( } fakePublicIPWithDNS = network.PublicIPAddress{ - Name: to.StringPtr("my-publicip"), + Name: pointer.String("my-publicip"), Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard}, - Location: to.StringPtr("centralIndia"), + Location: pointer.String("centralIndia"), Tags: map[string]*string{ - "Name": to.StringPtr("my-publicip"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "foo": to.StringPtr("bar"), + "Name": pointer.String("my-publicip"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "foo": pointer.String("bar"), }, PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ PublicIPAddressVersion: network.IPVersionIPv4, PublicIPAllocationMethod: network.IPAllocationMethodStatic, DNSSettings: &network.PublicIPAddressDNSSettings{ - DomainNameLabel: to.StringPtr("fakedns"), - Fqdn: to.StringPtr("fakedns.mydomain.io"), + DomainNameLabel: pointer.String("fakedns"), + Fqdn: pointer.String("fakedns.mydomain.io"), }, }, - Zones: to.StringSlicePtr([]string{"failure-domain-id-1", "failure-domain-id-2", "failure-domain-id-3"}), + Zones: &[]string{"failure-domain-id-1", "failure-domain-id-2", "failure-domain-id-3"}, } fakePublicIPWithoutDNS = network.PublicIPAddress{ - Name: to.StringPtr("my-publicip-2"), + Name: pointer.String("my-publicip-2"), Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard}, - Location: to.StringPtr("centralIndia"), + Location: pointer.String("centralIndia"), Tags: map[string]*string{ - "Name": to.StringPtr("my-publicip-2"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "foo": to.StringPtr("bar"), + "Name": pointer.String("my-publicip-2"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "foo": pointer.String("bar"), }, PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ PublicIPAddressVersion: network.IPVersionIPv4, PublicIPAllocationMethod: network.IPAllocationMethodStatic, }, - Zones: to.StringSlicePtr([]string{"failure-domain-id-1", "failure-domain-id-2", "failure-domain-id-3"}), + Zones: &[]string{"failure-domain-id-1", "failure-domain-id-2", "failure-domain-id-3"}, } fakePublicIPIpv6 = network.PublicIPAddress{ - Name: to.StringPtr("my-publicip-ipv6"), + Name: pointer.String("my-publicip-ipv6"), Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard}, - Location: to.StringPtr("centralIndia"), + Location: pointer.String("centralIndia"), Tags: map[string]*string{ - "Name": to.StringPtr("my-publicip-ipv6"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "foo": to.StringPtr("bar"), + "Name": pointer.String("my-publicip-ipv6"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "foo": pointer.String("bar"), }, PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ PublicIPAddressVersion: network.IPVersionIPv6, PublicIPAllocationMethod: network.IPAllocationMethodStatic, DNSSettings: &network.PublicIPAddressDNSSettings{ - DomainNameLabel: to.StringPtr("fakename"), - Fqdn: to.StringPtr("fakename.mydomain.io"), + DomainNameLabel: pointer.String("fakename"), + Fqdn: pointer.String("fakename.mydomain.io"), }, }, - Zones: to.StringSlicePtr([]string{"failure-domain-id-1", "failure-domain-id-2", "failure-domain-id-3"}), + Zones: &[]string{"failure-domain-id-1", "failure-domain-id-2", "failure-domain-id-3"}, } ) diff --git a/azure/services/resourcehealth/resourcehealth_test.go b/azure/services/resourcehealth/resourcehealth_test.go index 1dbcd21b1840..887355c2d246 100644 --- a/azure/services/resourcehealth/resourcehealth_test.go +++ b/azure/services/resourcehealth/resourcehealth_test.go @@ -21,11 +21,11 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/resourcehealth/mgmt/2020-05-01/resourcehealth" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" utilfeature "k8s.io/component-base/featuregate/testing" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/services/resourcehealth/mock_resourcehealth" "sigs.k8s.io/cluster-api-provider-azure/feature" @@ -62,7 +62,7 @@ func TestReconcileResourceHealth(t *testing.T) { m.GetByResource(gomockinternal.AContext(), gomock.Any()).Times(1).Return(resourcehealth.AvailabilityStatus{ Properties: &resourcehealth.AvailabilityStatusProperties{ AvailabilityState: resourcehealth.AvailabilityStateValuesUnavailable, - Summary: to.StringPtr("summary"), + Summary: pointer.String("summary"), }, }, nil) }, @@ -85,7 +85,7 @@ func TestReconcileResourceHealth(t *testing.T) { m.GetByResource(gomockinternal.AContext(), gomock.Any()).Times(1).Return(resourcehealth.AvailabilityStatus{ Properties: &resourcehealth.AvailabilityStatusProperties{ AvailabilityState: resourcehealth.AvailabilityStateValuesUnavailable, - Summary: to.StringPtr("summary"), + Summary: pointer.String("summary"), }, }, nil) // ignore the above status diff --git a/azure/services/resourceskus/cache_test.go b/azure/services/resourceskus/cache_test.go index a224891fae93..28dfef7f23a1 100644 --- a/azure/services/resourceskus/cache_test.go +++ b/azure/services/resourceskus/cache_test.go @@ -21,9 +21,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "k8s.io/utils/pointer" ) func TestCacheGet(t *testing.T) { @@ -40,12 +40,12 @@ func TestCacheGet(t *testing.T) { resourceType: "bar", have: []compute.ResourceSku{ { - Name: to.StringPtr("other"), - ResourceType: to.StringPtr("baz"), + Name: pointer.String("other"), + ResourceType: pointer.String("baz"), }, { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr("bar"), + Name: pointer.String("foo"), + ResourceType: pointer.String("bar"), }, }, }, @@ -55,7 +55,7 @@ func TestCacheGet(t *testing.T) { resourceType: "bar", have: []compute.ResourceSku{ { - Name: to.StringPtr("other"), + Name: pointer.String("other"), }, }, err: "reconcile error that cannot be recovered occurred: resource sku with name 'foo' and category 'bar' not found in location 'test'. Object will not be requeued", @@ -110,14 +110,14 @@ func TestCacheGetZones(t *testing.T) { "should find 1 result": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, @@ -128,27 +128,27 @@ func TestCacheGetZones(t *testing.T) { "should find 2 results": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, }, { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"2"}, }, }, @@ -159,14 +159,14 @@ func TestCacheGetZones(t *testing.T) { "should not find due to location mismatch": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "foobar", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("foobar"), + Location: pointer.String("foobar"), Zones: &[]string{"1"}, }, }, @@ -177,14 +177,14 @@ func TestCacheGetZones(t *testing.T) { "should not find due to location restriction": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, @@ -201,14 +201,14 @@ func TestCacheGetZones(t *testing.T) { "should not find due to zone restriction": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, @@ -254,14 +254,14 @@ func TestCacheGetZonesWithVMSize(t *testing.T) { "should find 1 result": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, @@ -272,14 +272,14 @@ func TestCacheGetZonesWithVMSize(t *testing.T) { "should find 2 results": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1", "2"}, }, }, @@ -290,14 +290,14 @@ func TestCacheGetZonesWithVMSize(t *testing.T) { "should not find due to size mismatch": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foobar"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foobar"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, @@ -308,14 +308,14 @@ func TestCacheGetZonesWithVMSize(t *testing.T) { "should not find due to location mismatch": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "foobar", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("foobar"), + Location: pointer.String("foobar"), Zones: &[]string{"1"}, }, }, @@ -326,14 +326,14 @@ func TestCacheGetZonesWithVMSize(t *testing.T) { "should not find due to location restriction": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, @@ -350,14 +350,14 @@ func TestCacheGetZonesWithVMSize(t *testing.T) { "should not find due to zone restriction": { have: []compute.ResourceSku{ { - Name: to.StringPtr("foo"), - ResourceType: to.StringPtr(string(VirtualMachines)), + Name: pointer.String("foo"), + ResourceType: pointer.String(string(VirtualMachines)), Locations: &[]string{ "baz", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("baz"), + Location: pointer.String("baz"), Zones: &[]string{"1"}, }, }, diff --git a/azure/services/roleassignments/roleassignments_test.go b/azure/services/roleassignments/roleassignments_test.go index 6a44a4538057..ca542f2ecb4a 100644 --- a/azure/services/roleassignments/roleassignments_test.go +++ b/azure/services/roleassignments/roleassignments_test.go @@ -24,9 +24,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" "sigs.k8s.io/cluster-api-provider-azure/azure/services/roleassignments/mock_roleassignments" @@ -45,7 +45,7 @@ var ( MachineName: "test-vm", ResourceGroup: "my-rg", ResourceType: azure.VirtualMachine, - PrincipalID: to.StringPtr("fake-principal-id"), + PrincipalID: pointer.String("fake-principal-id"), } fakeRoleAssignment2 = RoleAssignmentSpec{ MachineName: "test-vmss", diff --git a/azure/services/roleassignments/spec.go b/azure/services/roleassignments/spec.go index d77225e3d612..7ffd289d49fa 100644 --- a/azure/services/roleassignments/spec.go +++ b/azure/services/roleassignments/spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/authorization/mgmt/authorization" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" ) // RoleAssignmentSpec defines the specification for a role assignment. @@ -63,7 +63,7 @@ func (s *RoleAssignmentSpec) Parameters(ctx context.Context, existing interface{ return authorization.RoleAssignmentCreateParameters{ Properties: &authorization.RoleAssignmentProperties{ PrincipalID: s.PrincipalID, - RoleDefinitionID: to.StringPtr(s.RoleDefinitionID), + RoleDefinitionID: pointer.String(s.RoleDefinitionID), }, }, nil } diff --git a/azure/services/routetables/spec.go b/azure/services/routetables/spec.go index f6f4657da607..3f2bb802eb32 100644 --- a/azure/services/routetables/spec.go +++ b/azure/services/routetables/spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -61,12 +61,12 @@ func (s *RouteTableSpec) Parameters(ctx context.Context, existing interface{}) ( return nil, nil } return network.RouteTable{ - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{}, Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), + Name: pointer.String(s.Name), Additional: s.AdditionalTags, })), }, nil diff --git a/azure/services/scalesets/client.go b/azure/services/scalesets/client.go index dcda7ec6783b..b74dbe8fb5b3 100644 --- a/azure/services/scalesets/client.go +++ b/azure/services/scalesets/client.go @@ -26,8 +26,8 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -295,7 +295,7 @@ func (ac *AzureClient) DeleteAsync(ctx context.Context, resourceGroupName, vmssN ctx, _, done := tele.StartSpanWithLogger(ctx, "scalesets.AzureClient.DeleteAsync") defer done() - future, err := ac.scalesets.Delete(ctx, resourceGroupName, vmssName, to.BoolPtr(false)) + future, err := ac.scalesets.Delete(ctx, resourceGroupName, vmssName, pointer.Bool(false)) if err != nil { return nil, errors.Wrapf(err, "failed deleting vmss named %q", vmssName) } diff --git a/azure/services/scalesets/scalesets.go b/azure/services/scalesets/scalesets.go index b0ce282c5e2b..5cc35d59a3c5 100644 --- a/azure/services/scalesets/scalesets.go +++ b/azure/services/scalesets/scalesets.go @@ -24,8 +24,8 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" azprovider "sigs.k8s.io/cloud-provider-azure/pkg/provider" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" @@ -292,7 +292,7 @@ func (s *Service) patchVMSSIfNeeded(ctx context.Context, infraVMSS *azure.VMSS) // surge capacity with the intention of lowering during instance reconciliation surge := spec.Capacity + int64(maxSurge) log.V(4).Info("surging...", "surge", surge, "hasModelChanges", hasModelChanges, "updated", updated) - patch.Sku.Capacity = to.Int64Ptr(surge) + patch.Sku.Capacity = pointer.Int64(surge) } // If there are no model changes and no increase in the replica count, do not update the VMSS. @@ -469,7 +469,7 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet if vmssSpec.PublicLBAddressPoolName != "" { backendAddressPools = append(backendAddressPools, compute.SubResource{ - ID: to.StringPtr(azure.AddressPoolID(s.Scope.SubscriptionID(), s.Scope.ResourceGroup(), vmssSpec.PublicLBName, vmssSpec.PublicLBAddressPoolName)), + ID: pointer.String(azure.AddressPoolID(s.Scope.SubscriptionID(), s.Scope.ResourceGroup(), vmssSpec.PublicLBName, vmssSpec.PublicLBAddressPoolName)), }) } } @@ -481,17 +481,17 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet orchestrationMode := converters.GetOrchestrationMode(s.Scope.ScaleSetSpec().OrchestrationMode) vmss := compute.VirtualMachineScaleSet{ - Location: to.StringPtr(s.Scope.Location()), + Location: pointer.String(s.Scope.Location()), Sku: &compute.Sku{ - Name: to.StringPtr(vmssSpec.Size), - Tier: to.StringPtr("Standard"), - Capacity: to.Int64Ptr(vmssSpec.Capacity), + Name: pointer.String(vmssSpec.Size), + Tier: pointer.String("Standard"), + Capacity: pointer.Int64(vmssSpec.Capacity), }, - Zones: to.StringSlicePtr(vmssSpec.FailureDomains), + Zones: &vmssSpec.FailureDomains, Plan: s.generateImagePlan(ctx), VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{ OrchestrationMode: orchestrationMode, - SinglePlacementGroup: to.BoolPtr(false), + SinglePlacementGroup: pointer.Bool(false), VirtualMachineProfile: &compute.VirtualMachineScaleSetVMProfile{ OsProfile: osProfile, StorageProfile: storageProfile, @@ -500,18 +500,18 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet NetworkProfile: &compute.VirtualMachineScaleSetNetworkProfile{ NetworkInterfaceConfigurations: &[]compute.VirtualMachineScaleSetNetworkConfiguration{ { - Name: to.StringPtr(vmssSpec.Name), + Name: pointer.String(vmssSpec.Name), VirtualMachineScaleSetNetworkConfigurationProperties: &compute.VirtualMachineScaleSetNetworkConfigurationProperties{ - Primary: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + Primary: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), IPConfigurations: &[]compute.VirtualMachineScaleSetIPConfiguration{ { - Name: to.StringPtr(vmssSpec.Name), + Name: pointer.String(vmssSpec.Name), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ Subnet: &compute.APIEntityReference{ - ID: to.StringPtr(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, vmssSpec.SubnetName)), + ID: pointer.String(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, vmssSpec.SubnetName)), }, - Primary: to.BoolPtr(true), + Primary: pointer.Bool(true), PrivateIPAddressVersion: compute.IPVersionIPv4, LoadBalancerBackendAddressPools: &backendAddressPools, }, @@ -535,14 +535,14 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet // Set properties specific to VMSS orchestration mode switch orchestrationMode { case compute.OrchestrationModeUniform: - vmss.VirtualMachineScaleSetProperties.Overprovision = to.BoolPtr(false) + vmss.VirtualMachineScaleSetProperties.Overprovision = pointer.Bool(false) vmss.VirtualMachineScaleSetProperties.UpgradePolicy = &compute.UpgradePolicy{Mode: compute.UpgradeModeManual} case compute.OrchestrationModeFlexible: vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.NetworkProfile.NetworkAPIVersion = compute.NetworkAPIVersionTwoZeroTwoZeroHyphenMinusOneOneHyphenMinusZeroOne - vmss.VirtualMachineScaleSetProperties.PlatformFaultDomainCount = to.Int32Ptr(1) + vmss.VirtualMachineScaleSetProperties.PlatformFaultDomainCount = pointer.Int32(1) if len(vmssSpec.FailureDomains) > 1 { - vmss.VirtualMachineScaleSetProperties.PlatformFaultDomainCount = to.Int32Ptr(int32(len(vmssSpec.FailureDomains))) + vmss.VirtualMachineScaleSetProperties.PlatformFaultDomainCount = pointer.Int32(int32(len(vmssSpec.FailureDomains))) } } @@ -552,21 +552,21 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet for i, n := range vmssSpec.NetworkInterfaces { nicConfig := compute.VirtualMachineScaleSetNetworkConfiguration{} nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties = &compute.VirtualMachineScaleSetNetworkConfigurationProperties{} - nicConfig.Name = to.StringPtr(vmssSpec.Name + "-" + strconv.Itoa(i)) - if to.Bool(n.AcceleratedNetworking) { - nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties.EnableAcceleratedNetworking = to.BoolPtr(true) + nicConfig.Name = pointer.String(vmssSpec.Name + "-" + strconv.Itoa(i)) + if pointer.BoolDeref(n.AcceleratedNetworking, false) { + nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties.EnableAcceleratedNetworking = pointer.Bool(true) } else { - nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties.EnableAcceleratedNetworking = to.BoolPtr(false) + nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties.EnableAcceleratedNetworking = pointer.Bool(false) } if n.PrivateIPConfigs == 0 { nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations = &[]compute.VirtualMachineScaleSetIPConfiguration{ { - Name: to.StringPtr(vmssSpec.Name + "-" + strconv.Itoa(i)), + Name: pointer.String(vmssSpec.Name + "-" + strconv.Itoa(i)), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ Subnet: &compute.APIEntityReference{ - ID: to.StringPtr(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, n.SubnetName)), + ID: pointer.String(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, n.SubnetName)), }, - Primary: to.BoolPtr(true), + Primary: pointer.Bool(true), PrivateIPAddressVersion: compute.IPVersionIPv4, LoadBalancerBackendAddressPools: &backendAddressPools, }, @@ -578,17 +578,17 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet // Create IPConfigs for j := 0; j < n.PrivateIPConfigs; j++ { ipconfig := compute.VirtualMachineScaleSetIPConfiguration{ - Name: to.StringPtr(fmt.Sprintf("private-ipConfig-%v", j)), + Name: pointer.String(fmt.Sprintf("private-ipConfig-%v", j)), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ PrivateIPAddressVersion: compute.IPVersionIPv4, Subnet: &compute.APIEntityReference{ - ID: to.StringPtr(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, n.SubnetName)), + ID: pointer.String(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, n.SubnetName)), }, }, } ipconfig.Subnet = &compute.APIEntityReference{ - ID: to.StringPtr(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, n.SubnetName)), + ID: pointer.String(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, n.SubnetName)), } ipconfigs = append(ipconfigs, ipconfig) } @@ -596,12 +596,12 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet ipconfigs[0].LoadBalancerBackendAddressPools = &backendAddressPools } // Always use the first IPConfig as the Primary - ipconfigs[0].Primary = to.BoolPtr(true) + ipconfigs[0].Primary = pointer.Bool(true) nicConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations = &ipconfigs } nicConfigs = append(nicConfigs, nicConfig) } - nicConfigs[0].VirtualMachineScaleSetNetworkConfigurationProperties.Primary = to.BoolPtr(true) + nicConfigs[0].VirtualMachineScaleSetNetworkConfigurationProperties.Primary = pointer.Bool(true) vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations = &nicConfigs } else { // Set default interface configuration if no custom ones are specified @@ -629,7 +629,7 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet for _, dataDisk := range vmssSpec.DataDisks { if dataDisk.ManagedDisk != nil && dataDisk.ManagedDisk.StorageAccountType == string(compute.StorageAccountTypesUltraSSDLRS) { vmss.VirtualMachineScaleSetProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(true), + UltraSSDEnabled: pointer.Bool(true), } } } @@ -645,8 +645,8 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet if vmssSpec.TerminateNotificationTimeout != nil { vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.ScheduledEventsProfile = &compute.ScheduledEventsProfile{ TerminateNotificationProfile: &compute.TerminateNotificationProfile{ - NotBeforeTimeout: to.StringPtr(fmt.Sprintf("PT%dM", *vmssSpec.TerminateNotificationTimeout)), - Enable: to.BoolPtr(true), + NotBeforeTimeout: pointer.String(fmt.Sprintf("PT%dM", *vmssSpec.TerminateNotificationTimeout)), + Enable: pointer.Bool(true), }, } } @@ -654,8 +654,8 @@ func (s *Service) buildVMSSFromSpec(ctx context.Context, vmssSpec azure.ScaleSet tags := infrav1.Build(infrav1.BuildParams{ ClusterName: s.Scope.ClusterName(), Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(vmssSpec.Name), - Role: to.StringPtr(infrav1.Node), + Name: pointer.String(vmssSpec.Name), + Role: pointer.String(infrav1.Node), Additional: s.Scope.AdditionalTags(), }) @@ -669,23 +669,23 @@ func (s *Service) getVirtualMachineScaleSetDefaultNetworkConfiguration(vmssSpec if vmssSpec.PublicLBAddressPoolName != "" { backendAddressPools = append(backendAddressPools, compute.SubResource{ - ID: to.StringPtr(azure.AddressPoolID(s.Scope.SubscriptionID(), s.Scope.ResourceGroup(), vmssSpec.PublicLBName, vmssSpec.PublicLBAddressPoolName)), + ID: pointer.String(azure.AddressPoolID(s.Scope.SubscriptionID(), s.Scope.ResourceGroup(), vmssSpec.PublicLBName, vmssSpec.PublicLBAddressPoolName)), }) } } return &[]compute.VirtualMachineScaleSetNetworkConfiguration{{ - Name: to.StringPtr(vmssSpec.Name), + Name: pointer.String(vmssSpec.Name), VirtualMachineScaleSetNetworkConfigurationProperties: &compute.VirtualMachineScaleSetNetworkConfigurationProperties{ - Primary: to.BoolPtr(true), - EnableIPForwarding: to.BoolPtr(true), + Primary: pointer.Bool(true), + EnableIPForwarding: pointer.Bool(true), IPConfigurations: &[]compute.VirtualMachineScaleSetIPConfiguration{ { - Name: to.StringPtr(vmssSpec.Name), + Name: pointer.String(vmssSpec.Name), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ Subnet: &compute.APIEntityReference{ - ID: to.StringPtr(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, vmssSpec.SubnetName)), + ID: pointer.String(azure.SubnetID(s.Scope.SubscriptionID(), vmssSpec.VNetResourceGroup, vmssSpec.VNetName, vmssSpec.SubnetName)), }, - Primary: to.BoolPtr(true), + Primary: pointer.Bool(true), PrivateIPAddressVersion: compute.IPVersionIPv4, LoadBalancerBackendAddressPools: &backendAddressPools, }, @@ -780,7 +780,7 @@ func (s *Service) generateStorageProfile(ctx context.Context, vmssSpec azure.Sca storageProfile.OsDisk.ManagedDisk.StorageAccountType = compute.StorageAccountTypes(vmssSpec.OSDisk.ManagedDisk.StorageAccountType) } if vmssSpec.OSDisk.ManagedDisk.DiskEncryptionSet != nil { - storageProfile.OsDisk.ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: to.StringPtr(vmssSpec.OSDisk.ManagedDisk.DiskEncryptionSet.ID)} + storageProfile.OsDisk.ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: pointer.String(vmssSpec.OSDisk.ManagedDisk.DiskEncryptionSet.ID)} } } @@ -792,9 +792,9 @@ func (s *Service) generateStorageProfile(ctx context.Context, vmssSpec azure.Sca for i, disk := range vmssSpec.DataDisks { dataDisks[i] = compute.VirtualMachineScaleSetDataDisk{ CreateOption: compute.DiskCreateOptionTypesEmpty, - DiskSizeGB: to.Int32Ptr(disk.DiskSizeGB), + DiskSizeGB: pointer.Int32(disk.DiskSizeGB), Lun: disk.Lun, - Name: to.StringPtr(azure.GenerateDataDiskName(vmssSpec.Name, disk.NameSuffix)), + Name: pointer.String(azure.GenerateDataDiskName(vmssSpec.Name, disk.NameSuffix)), } if disk.ManagedDisk != nil { @@ -803,7 +803,7 @@ func (s *Service) generateStorageProfile(ctx context.Context, vmssSpec azure.Sca } if disk.ManagedDisk.DiskEncryptionSet != nil { - dataDisks[i].ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: to.StringPtr(disk.ManagedDisk.DiskEncryptionSet.ID)} + dataDisks[i].ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: pointer.String(disk.ManagedDisk.DiskEncryptionSet.ID)} } } } @@ -837,9 +837,9 @@ func (s *Service) generateOSProfile(ctx context.Context, vmssSpec azure.ScaleSet } osProfile := &compute.VirtualMachineScaleSetOSProfile{ - ComputerNamePrefix: to.StringPtr(vmssSpec.Name), - AdminUsername: to.StringPtr(azure.DefaultUserName), - CustomData: to.StringPtr(bootstrapData), + ComputerNamePrefix: pointer.String(vmssSpec.Name), + AdminUsername: pointer.String(azure.DefaultUserName), + CustomData: pointer.String(bootstrapData), } switch vmssSpec.OSDisk.OSType { @@ -851,18 +851,18 @@ func (s *Service) generateOSProfile(ctx context.Context, vmssSpec azure.ScaleSet // but the password on the VM will NOT be the same as created here. // Access is provided via SSH public key that is set during deployment // Azure also provides a way to reset user passwords in the case of need. - osProfile.AdminPassword = to.StringPtr(generators.SudoRandomPassword(123)) + osProfile.AdminPassword = pointer.String(generators.SudoRandomPassword(123)) osProfile.WindowsConfiguration = &compute.WindowsConfiguration{ - EnableAutomaticUpdates: to.BoolPtr(false), + EnableAutomaticUpdates: pointer.Bool(false), } default: osProfile.LinuxConfiguration = &compute.LinuxConfiguration{ - DisablePasswordAuthentication: to.BoolPtr(true), + DisablePasswordAuthentication: pointer.Bool(true), SSH: &compute.SSHConfiguration{ PublicKeys: &[]compute.SSHPublicKey{ { - Path: to.StringPtr(fmt.Sprintf("/home/%s/.ssh/authorized_keys", azure.DefaultUserName)), - KeyData: to.StringPtr(string(sshKey)), + Path: pointer.String(fmt.Sprintf("/home/%s/.ssh/authorized_keys", azure.DefaultUserName)), + KeyData: pointer.String(string(sshKey)), }, }, }, @@ -899,9 +899,9 @@ func (s *Service) generateImagePlan(ctx context.Context) *compute.Plan { } return &compute.Plan{ - Publisher: to.StringPtr(image.Marketplace.Publisher), - Name: to.StringPtr(image.Marketplace.SKU), - Product: to.StringPtr(image.Marketplace.Offer), + Publisher: pointer.String(image.Marketplace.Publisher), + Name: pointer.String(image.Marketplace.SKU), + Product: pointer.String(image.Marketplace.Offer), } } @@ -931,7 +931,7 @@ func getSecurityProfile(vmssSpec azure.ScaleSetSpec, sku resourceskus.SKU) (*com } return &compute.SecurityProfile{ - EncryptionAtHost: to.BoolPtr(*vmssSpec.SecurityProfile.EncryptionAtHost), + EncryptionAtHost: pointer.Bool(*vmssSpec.SecurityProfile.EncryptionAtHost), }, nil } diff --git a/azure/services/scalesets/scalesets_test.go b/azure/services/scalesets/scalesets_test.go index 5ca9b2497ee0..70a0b25ff4c8 100644 --- a/azure/services/scalesets/scalesets_test.go +++ b/azure/services/scalesets/scalesets_test.go @@ -23,7 +23,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/api/resource" @@ -91,27 +90,27 @@ func TestGetExistingVMSS(t *testing.T) { expect: func(s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder) { s.ResourceGroup().AnyTimes().Return("my-rg") m.Get(gomockinternal.AContext(), "my-rg", "my-vmss").Return(compute.VirtualMachineScaleSet{ - ID: to.StringPtr("my-id"), - Name: to.StringPtr("my-vmss"), + ID: pointer.String("my-id"), + Name: pointer.String("my-vmss"), Sku: &compute.Sku{ - Capacity: to.Int64Ptr(1), - Name: to.StringPtr("Standard_D2"), + Capacity: pointer.Int64(1), + Name: pointer.String("Standard_D2"), }, VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{ - SinglePlacementGroup: to.BoolPtr(false), - ProvisioningState: to.StringPtr("Succeeded"), + SinglePlacementGroup: pointer.Bool(false), + ProvisioningState: pointer.String("Succeeded"), }, Zones: &[]string{"1", "3"}, }, nil) m.ListInstances(gomock.Any(), "my-rg", "my-vmss").Return([]compute.VirtualMachineScaleSetVM{ { - ID: to.StringPtr("my-vm-id"), - InstanceID: to.StringPtr("my-vm-1"), - Name: to.StringPtr("my-vm"), + ID: pointer.String("my-vm-id"), + InstanceID: pointer.String("my-vm-1"), + Name: pointer.String("my-vm"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("instance-000001"), + ComputerName: pointer.String("instance-000001"), }, }, }, @@ -126,11 +125,11 @@ func TestGetExistingVMSS(t *testing.T) { expect: func(s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder) { s.ResourceGroup().AnyTimes().Return("my-rg") m.Get(gomockinternal.AContext(), "my-rg", "my-vmss").Return(compute.VirtualMachineScaleSet{ - ID: to.StringPtr("my-id"), - Name: to.StringPtr("my-vmss"), + ID: pointer.String("my-id"), + Name: pointer.String("my-vmss"), VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{ - SinglePlacementGroup: to.BoolPtr(false), - ProvisioningState: to.StringPtr("Succeeded"), + SinglePlacementGroup: pointer.Bool(false), + ProvisioningState: pointer.String("Succeeded"), }, }, nil) m.ListInstances(gomockinternal.AContext(), "my-rg", "my-vmss").Return([]compute.VirtualMachineScaleSetVM{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusNotFound}, "Not found")) @@ -197,7 +196,7 @@ func TestReconcileVMSS(t *testing.T) { defaultSpec.DataDisks = append(defaultSpec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -251,8 +250,8 @@ func TestReconcileVMSS(t *testing.T) { setupDefaultVMSSStartCreatingExpectations(s, m) vmss := newDefaultVMSS("VM_SIZE_AN") netConfigs := vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations - (*netConfigs)[0].EnableAcceleratedNetworking = to.BoolPtr(true) - vmss.Sku.Name = to.StringPtr(spec.Size) + (*netConfigs)[0].EnableAcceleratedNetworking = pointer.Bool(true) + vmss.Sku.Name = pointer.String(spec.Size) m.CreateOrUpdateAsync(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName, gomockinternal.DiffEq(vmss)). Return(putFuture, nil) setupCreatingSucceededExpectations(s, m, newDefaultExistingVMSS("VM_SIZE_AN"), putFuture) @@ -266,7 +265,7 @@ func TestReconcileVMSS(t *testing.T) { spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -288,38 +287,38 @@ func TestReconcileVMSS(t *testing.T) { vmss := newDefaultVMSS("VM_SIZE") vmss.VirtualMachineScaleSetProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{UltraSSDEnabled: pointer.Bool(true)} netConfigs := vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations - (*netConfigs)[0].Name = to.StringPtr("my-vmss-0") + (*netConfigs)[0].Name = pointer.String("my-vmss-0") (*netConfigs)[0].EnableIPForwarding = nil nic1IPConfigs := (*netConfigs)[0].IPConfigurations - (*nic1IPConfigs)[0].Name = to.StringPtr("private-ipConfig-0") + (*nic1IPConfigs)[0].Name = pointer.String("private-ipConfig-0") (*nic1IPConfigs)[0].PrivateIPAddressVersion = compute.IPVersionIPv4 - (*netConfigs)[0].EnableAcceleratedNetworking = to.BoolPtr(true) - (*netConfigs)[0].Primary = to.BoolPtr(true) + (*netConfigs)[0].EnableAcceleratedNetworking = pointer.Bool(true) + (*netConfigs)[0].Primary = pointer.Bool(true) vmssIPConfigs := []compute.VirtualMachineScaleSetIPConfiguration{ { - Name: to.StringPtr("private-ipConfig-0"), + Name: pointer.String("private-ipConfig-0"), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ - Primary: to.BoolPtr(true), + Primary: pointer.Bool(true), PrivateIPAddressVersion: compute.IPVersionIPv4, Subnet: &compute.APIEntityReference{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/subnet2"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/subnet2"), }, }, }, { - Name: to.StringPtr("private-ipConfig-1"), + Name: pointer.String("private-ipConfig-1"), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ PrivateIPAddressVersion: compute.IPVersionIPv4, Subnet: &compute.APIEntityReference{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/subnet2"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/subnet2"), }, }, }, } *netConfigs = append(*netConfigs, compute.VirtualMachineScaleSetNetworkConfiguration{ - Name: to.StringPtr("my-vmss-1"), + Name: pointer.String("my-vmss-1"), VirtualMachineScaleSetNetworkConfigurationProperties: &compute.VirtualMachineScaleSetNetworkConfigurationProperties{ - EnableAcceleratedNetworking: to.BoolPtr(true), + EnableAcceleratedNetworking: pointer.Bool(true), IPConfigurations: &vmssIPConfigs, }, }) @@ -337,7 +336,7 @@ func TestReconcileVMSS(t *testing.T) { spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -404,7 +403,7 @@ func TestReconcileVMSS(t *testing.T) { spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -414,7 +413,7 @@ func TestReconcileVMSS(t *testing.T) { vmss := newDefaultVMSS("VM_SIZE") vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.Priority = compute.VirtualMachinePriorityTypesSpot vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.BillingProfile = &compute.BillingProfile{ - MaxPrice: to.Float64Ptr(0.001), + MaxPrice: pointer.Float64(0.001), } vmss.VirtualMachineScaleSetProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{UltraSSDEnabled: pointer.Bool(true)} m.CreateOrUpdateAsync(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName, gomockinternal.DiffEq(vmss)). @@ -433,7 +432,7 @@ func TestReconcileVMSS(t *testing.T) { spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -446,7 +445,7 @@ func TestReconcileVMSS(t *testing.T) { osdisk.ManagedDisk = &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "Premium_LRS", DiskEncryptionSet: &compute.DiskEncryptionSetParameters{ - ID: to.StringPtr("my-diskencryptionset-id"), + ID: pointer.String("my-diskencryptionset-id"), }, } m.CreateOrUpdateAsync(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName, gomockinternal.DiffEq(vmss)). @@ -462,7 +461,7 @@ func TestReconcileVMSS(t *testing.T) { spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -494,14 +493,14 @@ func TestReconcileVMSS(t *testing.T) { expect: func(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder) { spec := newDefaultVMSSSpec() spec.Size = "VM_SIZE_EAH" - spec.SecurityProfile = &infrav1.SecurityProfile{EncryptionAtHost: to.BoolPtr(true)} + spec.SecurityProfile = &infrav1.SecurityProfile{EncryptionAtHost: pointer.Bool(true)} s.ScaleSetSpec().Return(spec).AnyTimes() setupDefaultVMSSStartCreatingExpectations(s, m) vmss := newDefaultVMSS("VM_SIZE_EAH") vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.SecurityProfile = &compute.SecurityProfile{ - EncryptionAtHost: to.BoolPtr(true), + EncryptionAtHost: pointer.Bool(true), } - vmss.Sku.Name = to.StringPtr(spec.Size) + vmss.Sku.Name = pointer.String(spec.Size) m.CreateOrUpdateAsync(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName, gomockinternal.DiffEq(vmss)). Return(putFuture, nil) setupCreatingSucceededExpectations(s, m, newDefaultExistingVMSS("VM_SIZE_EAH"), putFuture) @@ -516,7 +515,7 @@ func TestReconcileVMSS(t *testing.T) { Size: "VM_SIZE", Capacity: 2, SSHKeyData: "ZmFrZXNzaGtleQo=", - SecurityProfile: &infrav1.SecurityProfile{EncryptionAtHost: to.BoolPtr(true)}, + SecurityProfile: &infrav1.SecurityProfile{EncryptionAtHost: pointer.Bool(true)}, }) }, }, @@ -553,7 +552,7 @@ func TestReconcileVMSS(t *testing.T) { spec.DataDisks = append(spec.DataDisks, infrav1.DataDisk{ NameSuffix: "my_disk_with_ultra_disks", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -563,19 +562,19 @@ func TestReconcileVMSS(t *testing.T) { setupDefaultVMSSUpdateExpectations(s) existingVMSS := newDefaultExistingVMSS("VM_SIZE") existingVMSS.VirtualMachineScaleSetProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{UltraSSDEnabled: pointer.Bool(true)} - existingVMSS.Sku.Capacity = to.Int64Ptr(2) + existingVMSS.Sku.Capacity = pointer.Int64(2) existingVMSS.VirtualMachineScaleSetProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{UltraSSDEnabled: pointer.Bool(true)} instances := newDefaultInstances() m.Get(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName).Return(existingVMSS, nil) m.ListInstances(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName).Return(instances, nil) clone := newDefaultExistingVMSS("VM_SIZE") - clone.Sku.Capacity = to.Int64Ptr(3) + clone.Sku.Capacity = pointer.Int64(3) clone.VirtualMachineScaleSetProperties.AdditionalCapabilities = &compute.AdditionalCapabilities{UltraSSDEnabled: pointer.Bool(true)} patchVMSS, err := getVMSSUpdateFromVMSS(clone) g.Expect(err).NotTo(HaveOccurred()) - patchVMSS.VirtualMachineProfile.StorageProfile.ImageReference.Version = to.StringPtr("2.0") + patchVMSS.VirtualMachineProfile.StorageProfile.ImageReference.Version = pointer.String("2.0") patchVMSS.VirtualMachineProfile.NetworkProfile = nil m.UpdateAsync(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName, gomockinternal.DiffEq(patchVMSS)). Return(patchFuture, nil) @@ -664,7 +663,7 @@ func TestReconcileVMSS(t *testing.T) { Capacity: 2, SSHKeyData: "ZmFrZXNzaGtleQo=", AdditionalCapabilities: &infrav1.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(true), + UltraSSDEnabled: pointer.Bool(true), }, }) s.Location().AnyTimes().Return("test-location") @@ -687,7 +686,7 @@ func TestReconcileVMSS(t *testing.T) { }, }, AdditionalCapabilities: &infrav1.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(false), + UltraSSDEnabled: pointer.Bool(false), }, }) s.Location().AnyTimes().Return("test-location") @@ -731,7 +730,7 @@ func TestReconcileVMSS(t *testing.T) { vmss := newDefaultVMSS("VM_SIZE") vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.DiagnosticsProfile = &compute.DiagnosticsProfile{BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), + Enabled: pointer.Bool(true), StorageURI: &storageURI, }} @@ -758,7 +757,7 @@ func TestReconcileVMSS(t *testing.T) { s.ScaleSetSpec().Return(spec).AnyTimes() vmss := newDefaultVMSS("VM_SIZE") vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.DiagnosticsProfile = &compute.DiagnosticsProfile{BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), + Enabled: pointer.Bool(true), }} instances := newDefaultInstances() @@ -784,7 +783,7 @@ func TestReconcileVMSS(t *testing.T) { vmss := newDefaultVMSS("VM_SIZE") vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.DiagnosticsProfile = &compute.DiagnosticsProfile{BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(false), + Enabled: pointer.Bool(false), }} instances := newDefaultInstances() @@ -926,15 +925,15 @@ func TestDeleteVMSS(t *testing.T) { func getFakeSkus() []compute.ResourceSku { return []compute.ResourceSku{ { - Name: to.StringPtr("VM_SIZE"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, ZoneDetails: &[]compute.ResourceSkuZoneDetails{ { @@ -951,29 +950,29 @@ func getFakeSkus() []compute.ResourceSku { }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilityUnsupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilityUnsupported)), }, { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, }, }, { - Name: to.StringPtr("VM_SIZE_AN"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE_AN"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, // ZoneDetails: &[]compute.ResourceSkuZoneDetails{ // { @@ -989,85 +988,85 @@ func getFakeSkus() []compute.ResourceSku { }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilitySupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilitySupported)), }, { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("6"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("6"), }, }, }, { - Name: to.StringPtr("VM_SIZE_1_CPU"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE_1_CPU"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, }, }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilityUnsupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilityUnsupported)), }, { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("1"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("1"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, }, }, { - Name: to.StringPtr("VM_SIZE_1_MEM"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE_1_MEM"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, }, }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilityUnsupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilityUnsupported)), }, { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("2"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("2"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("1"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("1"), }, }, }, { - Name: to.StringPtr("VM_SIZE_EAH"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE_EAH"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, // ZoneDetails: &[]compute.ResourceSkuZoneDetails{ // { @@ -1083,57 +1082,57 @@ func getFakeSkus() []compute.ResourceSku { }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("8"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("8"), }, { - Name: to.StringPtr(resourceskus.EncryptionAtHost), - Value: to.StringPtr(string(resourceskus.CapabilitySupported)), + Name: pointer.String(resourceskus.EncryptionAtHost), + Value: pointer.String(string(resourceskus.CapabilitySupported)), }, }, }, { - Name: to.StringPtr("VM_SIZE_USSD"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE_USSD"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, }, }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilitySupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilitySupported)), }, { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("6"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("6"), }, }, }, { - Name: to.StringPtr("VM_SIZE_EPH"), - ResourceType: to.StringPtr(string(resourceskus.VirtualMachines)), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("VM_SIZE_EPH"), + ResourceType: pointer.String(string(resourceskus.VirtualMachines)), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1", "3"}, ZoneDetails: &[]compute.ResourceSkuZoneDetails{ { @@ -1150,20 +1149,20 @@ func getFakeSkus() []compute.ResourceSku { }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.AcceleratedNetworking), - Value: to.StringPtr(string(resourceskus.CapabilityUnsupported)), + Name: pointer.String(resourceskus.AcceleratedNetworking), + Value: pointer.String(string(resourceskus.CapabilityUnsupported)), }, { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.EphemeralOSDisk), - Value: to.StringPtr("True"), + Name: pointer.String(resourceskus.EphemeralOSDisk), + Value: pointer.String("True"), }, }, }, @@ -1178,7 +1177,7 @@ func newDefaultVMSSSpec() azure.ScaleSetSpec { SSHKeyData: "ZmFrZXNzaGtleQo=", OSDisk: infrav1.OSDisk{ OSType: "Linux", - DiskSizeGB: to.Int32Ptr(120), + DiskSizeGB: pointer.Int32(120), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, @@ -1187,12 +1186,12 @@ func newDefaultVMSSSpec() azure.ScaleSetSpec { { NameSuffix: "my_disk", DiskSizeGB: 128, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), }, { NameSuffix: "my_disk_with_managed_disk", DiskSizeGB: 128, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, @@ -1200,7 +1199,7 @@ func newDefaultVMSSSpec() azure.ScaleSetSpec { { NameSuffix: "managed_disk_with_encryption", DiskSizeGB: 128, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Standard_LRS", DiskEncryptionSet: &infrav1.DiskEncryptionSetParameters{ @@ -1220,7 +1219,7 @@ func newDefaultVMSSSpec() azure.ScaleSetSpec { PublicLBName: "capz-lb", PublicLBAddressPoolName: "backendPool", AcceleratedNetworking: nil, - TerminateNotificationTimeout: to.IntPtr(7), + TerminateNotificationTimeout: pointer.Int(7), FailureDomains: []string{"1", "3"}, } } @@ -1233,7 +1232,7 @@ func newWindowsVMSSSpec() azure.ScaleSetSpec { func newDefaultExistingVMSS(vmSize string) compute.VirtualMachineScaleSet { vmss := newDefaultVMSS(vmSize) - vmss.ID = to.StringPtr("subscriptions/1234/resourceGroups/my_resource_group/providers/Microsoft.Compute/virtualMachines/my-vm") + vmss.ID = pointer.String("subscriptions/1234/resourceGroups/my_resource_group/providers/Microsoft.Compute/virtualMachines/my-vm") return vmss } @@ -1242,7 +1241,7 @@ func newDefaultWindowsVMSS() compute.VirtualMachineScaleSet { vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile.OsDisk.OsType = compute.OperatingSystemTypesWindows vmss.VirtualMachineProfile.OsProfile.LinuxConfiguration = nil vmss.VirtualMachineProfile.OsProfile.WindowsConfiguration = &compute.WindowsConfiguration{ - EnableAutomaticUpdates: to.BoolPtr(false), + EnableAutomaticUpdates: pointer.Bool(false), } return vmss } @@ -1250,59 +1249,59 @@ func newDefaultWindowsVMSS() compute.VirtualMachineScaleSet { func newDefaultVMSS(vmSize string) compute.VirtualMachineScaleSet { dataDisk := fetchDataDiskBasedOnSize(vmSize) return compute.VirtualMachineScaleSet{ - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Tags: map[string]*string{ - "Name": to.StringPtr(defaultVMSSName), - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr("node"), + "Name": pointer.String(defaultVMSSName), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "sigs.k8s.io_cluster-api-provider-azure_role": pointer.String("node"), }, Sku: &compute.Sku{ - Name: to.StringPtr(vmSize), - Tier: to.StringPtr("Standard"), - Capacity: to.Int64Ptr(2), + Name: pointer.String(vmSize), + Tier: pointer.String("Standard"), + Capacity: pointer.Int64(2), }, Zones: &[]string{"1", "3"}, VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{ - SinglePlacementGroup: to.BoolPtr(false), + SinglePlacementGroup: pointer.Bool(false), UpgradePolicy: &compute.UpgradePolicy{ Mode: compute.UpgradeModeManual, }, - Overprovision: to.BoolPtr(false), + Overprovision: pointer.Bool(false), OrchestrationMode: compute.OrchestrationModeUniform, VirtualMachineProfile: &compute.VirtualMachineScaleSetVMProfile{ OsProfile: &compute.VirtualMachineScaleSetOSProfile{ - ComputerNamePrefix: to.StringPtr(defaultVMSSName), - AdminUsername: to.StringPtr(azure.DefaultUserName), - CustomData: to.StringPtr("fake-bootstrap-data"), + ComputerNamePrefix: pointer.String(defaultVMSSName), + AdminUsername: pointer.String(azure.DefaultUserName), + CustomData: pointer.String("fake-bootstrap-data"), LinuxConfiguration: &compute.LinuxConfiguration{ SSH: &compute.SSHConfiguration{ PublicKeys: &[]compute.SSHPublicKey{ { - Path: to.StringPtr("/home/capi/.ssh/authorized_keys"), - KeyData: to.StringPtr("fakesshkey\n"), + Path: pointer.String("/home/capi/.ssh/authorized_keys"), + KeyData: pointer.String("fakesshkey\n"), }, }, }, - DisablePasswordAuthentication: to.BoolPtr(true), + DisablePasswordAuthentication: pointer.Bool(true), }, }, ScheduledEventsProfile: &compute.ScheduledEventsProfile{ TerminateNotificationProfile: &compute.TerminateNotificationProfile{ - NotBeforeTimeout: to.StringPtr("PT7M"), - Enable: to.BoolPtr(true), + NotBeforeTimeout: pointer.String("PT7M"), + Enable: pointer.Bool(true), }, }, StorageProfile: &compute.VirtualMachineScaleSetStorageProfile{ ImageReference: &compute.ImageReference{ - Publisher: to.StringPtr("fake-publisher"), - Offer: to.StringPtr("my-offer"), - Sku: to.StringPtr("sku-id"), - Version: to.StringPtr("1.0"), + Publisher: pointer.String("fake-publisher"), + Offer: pointer.String("my-offer"), + Sku: pointer.String("sku-id"), + Version: pointer.String("1.0"), }, OsDisk: &compute.VirtualMachineScaleSetOSDisk{ OsType: "Linux", CreateOption: "FromImage", - DiskSizeGB: to.Int32Ptr(120), + DiskSizeGB: pointer.Int32(120), ManagedDisk: &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, @@ -1311,27 +1310,27 @@ func newDefaultVMSS(vmSize string) compute.VirtualMachineScaleSet { }, DiagnosticsProfile: &compute.DiagnosticsProfile{ BootDiagnostics: &compute.BootDiagnostics{ - Enabled: to.BoolPtr(true), + Enabled: pointer.Bool(true), }, }, NetworkProfile: &compute.VirtualMachineScaleSetNetworkProfile{ NetworkInterfaceConfigurations: &[]compute.VirtualMachineScaleSetNetworkConfiguration{ { - Name: to.StringPtr("my-vmss"), + Name: pointer.String("my-vmss"), VirtualMachineScaleSetNetworkConfigurationProperties: &compute.VirtualMachineScaleSetNetworkConfigurationProperties{ - Primary: to.BoolPtr(true), - EnableAcceleratedNetworking: to.BoolPtr(false), - EnableIPForwarding: to.BoolPtr(true), + Primary: pointer.Bool(true), + EnableAcceleratedNetworking: pointer.Bool(false), + EnableIPForwarding: pointer.Bool(true), IPConfigurations: &[]compute.VirtualMachineScaleSetIPConfiguration{ { - Name: to.StringPtr("my-vmss"), + Name: pointer.String("my-vmss"), VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{ Subnet: &compute.APIEntityReference{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet"), }, - Primary: to.BoolPtr(true), + Primary: pointer.Bool(true), PrivateIPAddressVersion: compute.IPVersionIPv4, - LoadBalancerBackendAddressPools: &[]compute.SubResource{{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/capz-lb/backendAddressPools/backendPool")}}, + LoadBalancerBackendAddressPools: &[]compute.SubResource{{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/capz-lb/backendAddressPools/backendPool")}}, }, }, }, @@ -1342,11 +1341,11 @@ func newDefaultVMSS(vmSize string) compute.VirtualMachineScaleSet { ExtensionProfile: &compute.VirtualMachineScaleSetExtensionProfile{ Extensions: &[]compute.VirtualMachineScaleSetExtension{ { - Name: to.StringPtr("someExtension"), + Name: pointer.String("someExtension"), VirtualMachineScaleSetExtensionProperties: &compute.VirtualMachineScaleSetExtensionProperties{ - Publisher: to.StringPtr("somePublisher"), - Type: to.StringPtr("someExtension"), - TypeHandlerVersion: to.StringPtr("someVersion"), + Publisher: pointer.String("somePublisher"), + Type: pointer.String("someExtension"), + TypeHandlerVersion: pointer.String("someVersion"), Settings: map[string]string{ "someSetting": "someValue", }, @@ -1367,37 +1366,37 @@ func fetchDataDiskBasedOnSize(vmSize string) *[]compute.VirtualMachineScaleSetDa if vmSize == "VM_SIZE" { dataDisk = &[]compute.VirtualMachineScaleSetDataDisk{ { - Lun: to.Int32Ptr(0), - Name: to.StringPtr("my-vmss_my_disk"), + Lun: pointer.Int32(0), + Name: pointer.String("my-vmss_my_disk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), }, { - Lun: to.Int32Ptr(1), - Name: to.StringPtr("my-vmss_my_disk_with_managed_disk"), + Lun: pointer.Int32(1), + Name: pointer.String("my-vmss_my_disk_with_managed_disk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, }, { - Lun: to.Int32Ptr(2), - Name: to.StringPtr("my-vmss_managed_disk_with_encryption"), + Lun: pointer.Int32(2), + Name: pointer.String("my-vmss_managed_disk_with_encryption"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "Standard_LRS", DiskEncryptionSet: &compute.DiskEncryptionSetParameters{ - ID: to.StringPtr("encryption_id"), + ID: pointer.String("encryption_id"), }, }, }, { - Lun: to.Int32Ptr(3), - Name: to.StringPtr("my-vmss_my_disk_with_ultra_disks"), + Lun: pointer.Int32(3), + Name: pointer.String("my-vmss_my_disk_with_ultra_disks"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -1406,29 +1405,29 @@ func fetchDataDiskBasedOnSize(vmSize string) *[]compute.VirtualMachineScaleSetDa } else { dataDisk = &[]compute.VirtualMachineScaleSetDataDisk{ { - Lun: to.Int32Ptr(0), - Name: to.StringPtr("my-vmss_my_disk"), + Lun: pointer.Int32(0), + Name: pointer.String("my-vmss_my_disk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), }, { - Lun: to.Int32Ptr(1), - Name: to.StringPtr("my-vmss_my_disk_with_managed_disk"), + Lun: pointer.Int32(1), + Name: pointer.String("my-vmss_my_disk_with_managed_disk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "Standard_LRS", }, }, { - Lun: to.Int32Ptr(2), - Name: to.StringPtr("my-vmss_managed_disk_with_encryption"), + Lun: pointer.Int32(2), + Name: pointer.String("my-vmss_managed_disk_with_encryption"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.VirtualMachineScaleSetManagedDiskParameters{ StorageAccountType: "Standard_LRS", DiskEncryptionSet: &compute.DiskEncryptionSetParameters{ - ID: to.StringPtr("encryption_id"), + ID: pointer.String("encryption_id"), }, }, }, @@ -1440,39 +1439,39 @@ func fetchDataDiskBasedOnSize(vmSize string) *[]compute.VirtualMachineScaleSetDa func newDefaultInstances() []compute.VirtualMachineScaleSetVM { return []compute.VirtualMachineScaleSetVM{ { - ID: to.StringPtr("my-vm-id"), - InstanceID: to.StringPtr("my-vm-1"), - Name: to.StringPtr("my-vm"), + ID: pointer.String("my-vm-id"), + InstanceID: pointer.String("my-vm-1"), + Name: pointer.String("my-vm"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("instance-000001"), + ComputerName: pointer.String("instance-000001"), }, StorageProfile: &compute.StorageProfile{ ImageReference: &compute.ImageReference{ - Publisher: to.StringPtr("fake-publisher"), - Offer: to.StringPtr("my-offer"), - Sku: to.StringPtr("sku-id"), - Version: to.StringPtr("1.0"), + Publisher: pointer.String("fake-publisher"), + Offer: pointer.String("my-offer"), + Sku: pointer.String("sku-id"), + Version: pointer.String("1.0"), }, }, }, }, { - ID: to.StringPtr("my-vm-id"), - InstanceID: to.StringPtr("my-vm-2"), - Name: to.StringPtr("my-vm"), + ID: pointer.String("my-vm-id"), + InstanceID: pointer.String("my-vm-2"), + Name: pointer.String("my-vm"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), OsProfile: &compute.OSProfile{ - ComputerName: to.StringPtr("instance-000002"), + ComputerName: pointer.String("instance-000002"), }, StorageProfile: &compute.StorageProfile{ ImageReference: &compute.ImageReference{ - Publisher: to.StringPtr("fake-publisher"), - Offer: to.StringPtr("my-offer"), - Sku: to.StringPtr("sku-id"), - Version: to.StringPtr("1.0"), + Publisher: pointer.String("fake-publisher"), + Offer: pointer.String("my-offer"), + Sku: pointer.String("sku-id"), + Version: pointer.String("1.0"), }, }, }, @@ -1481,8 +1480,8 @@ func newDefaultInstances() []compute.VirtualMachineScaleSetVM { } func setupDefaultVMSSInProgressOperationDoneExpectations(s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder, createdVMSS compute.VirtualMachineScaleSet, instances []compute.VirtualMachineScaleSetVM) { - createdVMSS.ID = to.StringPtr("subscriptions/1234/resourceGroups/my_resource_group/providers/Microsoft.Compute/virtualMachines/my-vm") - createdVMSS.ProvisioningState = to.StringPtr(string(infrav1.Succeeded)) + createdVMSS.ID = pointer.String("subscriptions/1234/resourceGroups/my_resource_group/providers/Microsoft.Compute/virtualMachines/my-vm") + createdVMSS.ProvisioningState = pointer.String(string(infrav1.Succeeded)) setupDefaultVMSSExpectations(s) future := &infrav1.Future{ Type: infrav1.PutFuture, diff --git a/azure/services/scalesets/vmssextension_spec.go b/azure/services/scalesets/vmssextension_spec.go index 51143258271c..29438bf8b4d9 100644 --- a/azure/services/scalesets/vmssextension_spec.go +++ b/azure/services/scalesets/vmssextension_spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -59,11 +59,11 @@ func (s *VMSSExtensionSpec) Parameters(ctx context.Context, existing interface{} } return compute.VirtualMachineScaleSetExtension{ - Name: to.StringPtr(s.Name), + Name: pointer.String(s.Name), VirtualMachineScaleSetExtensionProperties: &compute.VirtualMachineScaleSetExtensionProperties{ - Publisher: to.StringPtr(s.Publisher), - Type: to.StringPtr(s.Name), - TypeHandlerVersion: to.StringPtr(s.Version), + Publisher: pointer.String(s.Publisher), + Type: pointer.String(s.Name), + TypeHandlerVersion: pointer.String(s.Version), Settings: s.Settings, ProtectedSettings: s.ProtectedSettings, }, diff --git a/azure/services/scalesets/vmssextension_spec_test.go b/azure/services/scalesets/vmssextension_spec_test.go index 92848ac9a9ac..97e8dc21a373 100644 --- a/azure/services/scalesets/vmssextension_spec_test.go +++ b/azure/services/scalesets/vmssextension_spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -40,11 +40,11 @@ var ( } fakeVMSSExtensionParams = compute.VirtualMachineScaleSetExtension{ - Name: to.StringPtr("my-vm-extension"), + Name: pointer.String("my-vm-extension"), VirtualMachineScaleSetExtensionProperties: &compute.VirtualMachineScaleSetExtensionProperties{ - Publisher: to.StringPtr("my-publisher"), - Type: to.StringPtr("my-vm-extension"), - TypeHandlerVersion: to.StringPtr("1.0"), + Publisher: pointer.String("my-publisher"), + Type: pointer.String("my-vm-extension"), + TypeHandlerVersion: pointer.String("1.0"), Settings: map[string]string{"my-setting": "my-value"}, ProtectedSettings: map[string]string{"my-protected-setting": "my-protected-value"}, }, diff --git a/azure/services/scalesetvms/client.go b/azure/services/scalesetvms/client.go index 15f0a21d5788..bea87d280bb4 100644 --- a/azure/services/scalesetvms/client.go +++ b/azure/services/scalesetvms/client.go @@ -24,8 +24,8 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -136,7 +136,7 @@ func (ac *azureClient) DeleteAsync(ctx context.Context, resourceGroupName, vmssN ctx, _, done := tele.StartSpanWithLogger(ctx, "scalesetvms.azureClient.DeleteAsync") defer done() - future, err := ac.scalesetvms.Delete(ctx, resourceGroupName, vmssName, instanceID, to.BoolPtr(false)) + future, err := ac.scalesetvms.Delete(ctx, resourceGroupName, vmssName, instanceID, pointer.Bool(false)) if err != nil { return nil, errors.Wrapf(err, "failed deleting vmss named %q", vmssName) } diff --git a/azure/services/scalesetvms/scalesetvms_test.go b/azure/services/scalesetvms/scalesetvms_test.go index cb206ab83fe9..18efa9ac714a 100644 --- a/azure/services/scalesetvms/scalesetvms_test.go +++ b/azure/services/scalesetvms/scalesetvms_test.go @@ -24,12 +24,12 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -106,7 +106,7 @@ func TestService_Reconcile(t *testing.T) { s.ProviderID().Return("foo") s.ScaleSetName().Return("scaleset") vm := compute.VirtualMachineScaleSetVM{ - InstanceID: to.StringPtr("0"), + InstanceID: pointer.String("0"), } m.Get(gomock2.AContext(), "rg", "scaleset", "0").Return(vm, nil) s.SetVMSSVM(converters.SDKToVMSSVM(vm)) diff --git a/azure/services/securitygroups/securitygroups_test.go b/azure/services/securitygroups/securitygroups_test.go index b1269f983ae1..e4bcf9149ca9 100644 --- a/azure/services/securitygroups/securitygroups_test.go +++ b/azure/services/securitygroups/securitygroups_test.go @@ -21,10 +21,10 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -44,10 +44,10 @@ var ( Priority: 2200, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionInbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr("22"), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String("22"), }, { Name: "other_rule", @@ -55,10 +55,10 @@ var ( Priority: 500, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionInbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr("80"), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String("80"), }, }, ResourceGroup: "test-group", @@ -248,41 +248,41 @@ func TestDeleteSecurityGroups(t *testing.T) { var ( ruleA = network.SecurityRule{ - Name: to.StringPtr("A"), + Name: pointer.String("A"), SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{ - Description: to.StringPtr("this is rule A"), + Description: pointer.String("this is rule A"), Protocol: network.SecurityRuleProtocolTCP, - DestinationPortRange: to.StringPtr("*"), - SourcePortRange: to.StringPtr("*"), - DestinationAddressPrefix: to.StringPtr("*"), - SourceAddressPrefix: to.StringPtr("*"), - Priority: to.Int32Ptr(100), + DestinationPortRange: pointer.String("*"), + SourcePortRange: pointer.String("*"), + DestinationAddressPrefix: pointer.String("*"), + SourceAddressPrefix: pointer.String("*"), + Priority: pointer.Int32(100), Direction: network.SecurityRuleDirectionInbound, }, } ruleB = network.SecurityRule{ - Name: to.StringPtr("B"), + Name: pointer.String("B"), SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{ - Description: to.StringPtr("this is rule B"), + Description: pointer.String("this is rule B"), Protocol: network.SecurityRuleProtocolTCP, - DestinationPortRange: to.StringPtr("*"), - SourcePortRange: to.StringPtr("*"), - DestinationAddressPrefix: to.StringPtr("*"), - SourceAddressPrefix: to.StringPtr("*"), - Priority: to.Int32Ptr(100), + DestinationPortRange: pointer.String("*"), + SourcePortRange: pointer.String("*"), + DestinationAddressPrefix: pointer.String("*"), + SourceAddressPrefix: pointer.String("*"), + Priority: pointer.Int32(100), Direction: network.SecurityRuleDirectionOutbound, }, } ruleBModified = network.SecurityRule{ - Name: to.StringPtr("B"), + Name: pointer.String("B"), SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{ - Description: to.StringPtr("this is rule B"), + Description: pointer.String("this is rule B"), Protocol: network.SecurityRuleProtocolTCP, - DestinationPortRange: to.StringPtr("80"), - SourcePortRange: to.StringPtr("*"), - DestinationAddressPrefix: to.StringPtr("*"), - SourceAddressPrefix: to.StringPtr("*"), - Priority: to.Int32Ptr(100), + DestinationPortRange: pointer.String("80"), + SourcePortRange: pointer.String("*"), + DestinationAddressPrefix: pointer.String("*"), + SourceAddressPrefix: pointer.String("*"), + Priority: pointer.Int32(100), Direction: network.SecurityRuleDirectionOutbound, }, } diff --git a/azure/services/securitygroups/spec.go b/azure/services/securitygroups/spec.go index b7aecc20d0c7..8d503add478b 100644 --- a/azure/services/securitygroups/spec.go +++ b/azure/services/securitygroups/spec.go @@ -21,8 +21,8 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -87,7 +87,7 @@ func (s *NSGSpec) Parameters(ctx context.Context, existing interface{}) (interfa } return network.SecurityGroup{ - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{ SecurityRules: &securityRules, }, @@ -95,7 +95,7 @@ func (s *NSGSpec) Parameters(ctx context.Context, existing interface{}) (interfa Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), + Name: pointer.String(s.Name), Additional: s.AdditionalTags, })), }, nil @@ -104,10 +104,10 @@ func (s *NSGSpec) Parameters(ctx context.Context, existing interface{}) (interfa // TODO: review this logic and make sure it is what we want. It seems incorrect to skip rules that don't have a certain protocol, etc. func ruleExists(rules []network.SecurityRule, rule network.SecurityRule) bool { for _, existingRule := range rules { - if !strings.EqualFold(to.String(existingRule.Name), to.String(rule.Name)) { + if !strings.EqualFold(pointer.StringDeref(existingRule.Name, ""), pointer.StringDeref(rule.Name, "")) { continue } - if !strings.EqualFold(to.String(existingRule.DestinationPortRange), to.String(rule.DestinationPortRange)) { + if !strings.EqualFold(pointer.StringDeref(existingRule.DestinationPortRange, ""), pointer.StringDeref(rule.DestinationPortRange, "")) { continue } if existingRule.Protocol != network.SecurityRuleProtocolTCP && @@ -115,9 +115,9 @@ func ruleExists(rules []network.SecurityRule, rule network.SecurityRule) bool { existingRule.Direction != network.SecurityRuleDirectionInbound { continue } - if !strings.EqualFold(to.String(existingRule.SourcePortRange), "*") && - !strings.EqualFold(to.String(existingRule.SourceAddressPrefix), "*") && - !strings.EqualFold(to.String(existingRule.DestinationAddressPrefix), "*") { + if !strings.EqualFold(pointer.StringDeref(existingRule.SourcePortRange, ""), "*") && + !strings.EqualFold(pointer.StringDeref(existingRule.SourceAddressPrefix, ""), "*") && + !strings.EqualFold(pointer.StringDeref(existingRule.DestinationAddressPrefix, ""), "*") { continue } return true diff --git a/azure/services/securitygroups/spec_test.go b/azure/services/securitygroups/spec_test.go index 8fbfd8419805..4cdd067536b7 100644 --- a/azure/services/securitygroups/spec_test.go +++ b/azure/services/securitygroups/spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -34,10 +34,10 @@ var ( Priority: 2200, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionInbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr("22"), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String("22"), } otherRule = infrav1.SecurityRule{ Name: "other_rule", @@ -45,10 +45,10 @@ var ( Priority: 500, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionInbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr("80"), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String("80"), } customRule = infrav1.SecurityRule{ Name: "custom_rule", @@ -56,10 +56,10 @@ var ( Priority: 501, Protocol: infrav1.SecurityGroupProtocolTCP, Direction: infrav1.SecurityRuleDirectionOutbound, - Source: to.StringPtr("*"), - SourcePorts: to.StringPtr("*"), - Destination: to.StringPtr("*"), - DestinationPorts: to.StringPtr("80"), + Source: pointer.String("*"), + SourcePorts: pointer.String("*"), + Destination: pointer.String("*"), + DestinationPorts: pointer.String("80"), } ) @@ -84,7 +84,7 @@ func TestParameters(t *testing.T) { ClusterName: "my-cluster", }, existing: network.SecurityGroup{ - Name: to.StringPtr("test-nsg"), + Name: pointer.String("test-nsg"), SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{ SecurityRules: &[]network.SecurityRule{ converters.SecurityRuleToSDK(sshRule), @@ -109,9 +109,9 @@ func TestParameters(t *testing.T) { ClusterName: "my-cluster", }, existing: network.SecurityGroup{ - Name: to.StringPtr("test-nsg"), - Location: to.StringPtr("test-location"), - Etag: to.StringPtr("fake-etag"), + Name: pointer.String("test-nsg"), + Location: pointer.String("test-location"), + Etag: pointer.String("fake-etag"), SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{ SecurityRules: &[]network.SecurityRule{ converters.SecurityRuleToSDK(sshRule), @@ -122,8 +122,8 @@ func TestParameters(t *testing.T) { expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(network.SecurityGroup{})) g.Expect(result).To(Equal(network.SecurityGroup{ - Location: to.StringPtr("test-location"), - Etag: to.StringPtr("fake-etag"), + Location: pointer.String("test-location"), + Etag: pointer.String("fake-etag"), SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{ SecurityRules: &[]network.SecurityRule{ converters.SecurityRuleToSDK(sshRule), @@ -132,8 +132,8 @@ func TestParameters(t *testing.T) { }, }, Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "Name": to.StringPtr("test-nsg"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "Name": pointer.String("test-nsg"), }, })) }, @@ -160,10 +160,10 @@ func TestParameters(t *testing.T) { converters.SecurityRuleToSDK(otherRule), }, }, - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "Name": to.StringPtr("test-nsg"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": pointer.String("owned"), + "Name": pointer.String("test-nsg"), }, })) }, diff --git a/azure/services/subnets/spec.go b/azure/services/subnets/spec.go index 2b9d574ca950..5da1300cdc75 100644 --- a/azure/services/subnets/spec.go +++ b/azure/services/subnets/spec.go @@ -20,9 +20,9 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -79,7 +79,8 @@ func (s *SubnetSpec) Parameters(ctx context.Context, existing interface{}) (para } var newServiceEndpoints []network.ServiceEndpointPropertiesFormat for _, se := range s.ServiceEndpoints { - newServiceEndpoints = append(newServiceEndpoints, network.ServiceEndpointPropertiesFormat{Service: to.StringPtr(se.Service), Locations: to.StringSlicePtr(se.Locations)}) + se := se + newServiceEndpoints = append(newServiceEndpoints, network.ServiceEndpointPropertiesFormat{Service: pointer.String(se.Service), Locations: &se.Locations}) } // Right now only serviceEndpoints are allowed to be updated. More to come later @@ -107,25 +108,26 @@ func (s *SubnetSpec) Parameters(ctx context.Context, existing interface{}) (para if s.RouteTableName != "" { subnetProperties.RouteTable = &network.RouteTable{ - ID: to.StringPtr(azure.RouteTableID(s.SubscriptionID, s.ResourceGroup, s.RouteTableName)), + ID: pointer.String(azure.RouteTableID(s.SubscriptionID, s.ResourceGroup, s.RouteTableName)), } } if s.NatGatewayName != "" { subnetProperties.NatGateway = &network.SubResource{ - ID: to.StringPtr(azure.NatGatewayID(s.SubscriptionID, s.ResourceGroup, s.NatGatewayName)), + ID: pointer.String(azure.NatGatewayID(s.SubscriptionID, s.ResourceGroup, s.NatGatewayName)), } } if s.SecurityGroupName != "" { subnetProperties.NetworkSecurityGroup = &network.SecurityGroup{ - ID: to.StringPtr(azure.SecurityGroupID(s.SubscriptionID, s.ResourceGroup, s.SecurityGroupName)), + ID: pointer.String(azure.SecurityGroupID(s.SubscriptionID, s.ResourceGroup, s.SecurityGroupName)), } } serviceEndpoints := make([]network.ServiceEndpointPropertiesFormat, 0, len(s.ServiceEndpoints)) for _, se := range s.ServiceEndpoints { - serviceEndpoints = append(serviceEndpoints, network.ServiceEndpointPropertiesFormat{Service: to.StringPtr(se.Service), Locations: to.StringSlicePtr(se.Locations)}) + se := se + serviceEndpoints = append(serviceEndpoints, network.ServiceEndpointPropertiesFormat{Service: pointer.String(se.Service), Locations: &se.Locations}) } subnetProperties.ServiceEndpoints = &serviceEndpoints diff --git a/azure/services/subnets/spec_test.go b/azure/services/subnets/spec_test.go index 7146eded67a8..f0be79babd72 100644 --- a/azure/services/subnets/spec_test.go +++ b/azure/services/subnets/spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -43,10 +43,10 @@ var ( fakeSubnetOneCidrParams = network.Subnet{ SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr("10.0.0.0/16"), - RouteTable: &network.RouteTable{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, - NetworkSecurityGroup: &network.SecurityGroup{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, - NatGateway: &network.SubResource{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/natGateways/my-nat-gateway")}, + AddressPrefix: pointer.String("10.0.0.0/16"), + RouteTable: &network.RouteTable{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, + NetworkSecurityGroup: &network.SecurityGroup{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, + NatGateway: &network.SubResource{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/natGateways/my-nat-gateway")}, ServiceEndpoints: &[]network.ServiceEndpointPropertiesFormat{}, }, } @@ -72,9 +72,9 @@ var ( "10.1.0.0/16", "10.2.0.0/16", }, - RouteTable: &network.RouteTable{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, - NetworkSecurityGroup: &network.SecurityGroup{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, - NatGateway: &network.SubResource{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/natGateways/my-nat-gateway")}, + RouteTable: &network.RouteTable{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, + NetworkSecurityGroup: &network.SecurityGroup{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, + NatGateway: &network.SubResource{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/natGateways/my-nat-gateway")}, ServiceEndpoints: &[]network.ServiceEndpointPropertiesFormat{}, }, } @@ -93,15 +93,15 @@ var ( } fakeIpv6SubnetNotManaged = network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-ipv6-subnet"), - Name: to.StringPtr("my-ipv6-subnet"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-ipv6-subnet"), + Name: pointer.String("my-ipv6-subnet"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ AddressPrefixes: &[]string{ "10.0.0.0/16", "2001:1234:5678:9abd::/64", }, - RouteTable: &network.RouteTable{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, - NetworkSecurityGroup: &network.SecurityGroup{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, + RouteTable: &network.RouteTable{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, + NetworkSecurityGroup: &network.SecurityGroup{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, }, } ) diff --git a/azure/services/subnets/subnets.go b/azure/services/subnets/subnets.go index 0b8700df1eaa..666ca815bd52 100644 --- a/azure/services/subnets/subnets.go +++ b/azure/services/subnets/subnets.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -90,7 +90,7 @@ func (s *Service) Reconcile(ctx context.Context) error { if !ok { return errors.Errorf("%T is not a network.Subnet", result) } - s.Scope.UpdateSubnetID(subnetSpec.ResourceName(), to.String(subnet.ID)) + s.Scope.UpdateSubnetID(subnetSpec.ResourceName(), pointer.StringDeref(subnet.ID, "")) s.Scope.UpdateSubnetCIDRs(subnetSpec.ResourceName(), converters.GetSubnetAddresses(subnet)) } } diff --git a/azure/services/subnets/subnets_test.go b/azure/services/subnets/subnets_test.go index faf90895c54c..77c15fe7e30d 100644 --- a/azure/services/subnets/subnets_test.go +++ b/azure/services/subnets/subnets_test.go @@ -23,10 +23,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -49,17 +49,17 @@ var ( } fakeSubnet1 = network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet-1"), - Name: to.StringPtr("my-subnet-1"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet-1"), + Name: pointer.String("my-subnet-1"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr("10.0.0.0/16"), + AddressPrefix: pointer.String("10.0.0.0/16"), RouteTable: &network.RouteTable{ - ID: to.StringPtr("rt-id"), - Name: to.StringPtr("my-subnet_route_table"), + ID: pointer.String("rt-id"), + Name: pointer.String("my-subnet_route_table"), }, NetworkSecurityGroup: &network.SecurityGroup{ - ID: to.StringPtr("sg-id-1"), - Name: to.StringPtr("my-sg-1"), + ID: pointer.String("sg-id-1"), + Name: pointer.String("my-sg-1"), }, }, } @@ -78,17 +78,17 @@ var ( } fakeSubnet2 = network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet-2"), - Name: to.StringPtr("my-subnet-2"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet-2"), + Name: pointer.String("my-subnet-2"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr("10.2.0.0/16"), + AddressPrefix: pointer.String("10.2.0.0/16"), RouteTable: &network.RouteTable{ - ID: to.StringPtr("rt-id"), - Name: to.StringPtr("my-subnet_route_table"), + ID: pointer.String("rt-id"), + Name: pointer.String("my-subnet_route_table"), }, NetworkSecurityGroup: &network.SecurityGroup{ - ID: to.StringPtr("sg-id-2"), - Name: to.StringPtr("my-sg-2"), + ID: pointer.String("sg-id-2"), + Name: pointer.String("my-sg-2"), }, }, } @@ -106,17 +106,17 @@ var ( Role: infrav1.SubnetNode, } fakeSubnetNotManaged = network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet-1"), - Name: to.StringPtr("my-subnet-1"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet-1"), + Name: pointer.String("my-subnet-1"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr("10.0.0.0/16"), + AddressPrefix: pointer.String("10.0.0.0/16"), RouteTable: &network.RouteTable{ - ID: to.StringPtr("rt-id"), - Name: to.StringPtr("my-subnet_route_table"), + ID: pointer.String("rt-id"), + Name: pointer.String("my-subnet_route_table"), }, NetworkSecurityGroup: &network.SecurityGroup{ - ID: to.StringPtr("sg-id-1"), - Name: to.StringPtr("my-sg-1"), + ID: pointer.String("sg-id-1"), + Name: pointer.String("my-sg-1"), }, }, } @@ -148,15 +148,15 @@ var ( } fakeIpv6Subnet = network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-ipv6-subnet"), - Name: to.StringPtr("my-ipv6-subnet"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-ipv6-subnet"), + Name: pointer.String("my-ipv6-subnet"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ AddressPrefixes: &[]string{ "10.0.0.0/16", "2001:1234:5678:9abd::/64", }, - RouteTable: &network.RouteTable{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, - NetworkSecurityGroup: &network.SecurityGroup{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, + RouteTable: &network.RouteTable{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, + NetworkSecurityGroup: &network.SecurityGroup{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, }, } @@ -174,15 +174,15 @@ var ( } fakeIpv6SubnetCP = network.Subnet{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-ipv6-subnet-cp"), - Name: to.StringPtr("my-ipv6-subnet-cp"), + ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-ipv6-subnet-cp"), + Name: pointer.String("my-ipv6-subnet-cp"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ AddressPrefixes: &[]string{ "10.2.0.0/16", "2001:1234:5678:9abc::/64", }, - RouteTable: &network.RouteTable{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, - NetworkSecurityGroup: &network.SecurityGroup{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, + RouteTable: &network.RouteTable{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/routeTables/my-subnet_route_table")}, + NetworkSecurityGroup: &network.SecurityGroup{ID: pointer.String("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/networkSecurityGroups/my-sg")}, }, } @@ -211,8 +211,8 @@ func TestReconcileSubnets(t *testing.T) { s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1}) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(fakeSubnet1, nil) - s.UpdateSubnetID(fakeSubnetSpec1.Name, to.String(fakeSubnet1.ID)) - s.UpdateSubnetCIDRs(fakeSubnetSpec1.Name, []string{to.String(fakeSubnet1.AddressPrefix)}) + s.UpdateSubnetID(fakeSubnetSpec1.Name, pointer.StringDeref(fakeSubnet1.ID, "")) + s.UpdateSubnetCIDRs(fakeSubnetSpec1.Name, []string{pointer.StringDeref(fakeSubnet1.AddressPrefix, "")}) s.IsVnetManaged().AnyTimes().Return(true) s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil) @@ -225,12 +225,12 @@ func TestReconcileSubnets(t *testing.T) { s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1, &fakeSubnetSpec2}) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(fakeSubnet1, nil) - s.UpdateSubnetID(fakeSubnetSpec1.Name, to.String(fakeSubnet1.ID)) - s.UpdateSubnetCIDRs(fakeSubnetSpec1.Name, []string{to.String(fakeSubnet1.AddressPrefix)}) + s.UpdateSubnetID(fakeSubnetSpec1.Name, pointer.StringDeref(fakeSubnet1.ID, "")) + s.UpdateSubnetCIDRs(fakeSubnetSpec1.Name, []string{pointer.StringDeref(fakeSubnet1.AddressPrefix, "")}) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeSubnetSpec2, serviceName).Return(fakeSubnet2, nil) - s.UpdateSubnetID(fakeSubnetSpec2.Name, to.String(fakeSubnet2.ID)) - s.UpdateSubnetCIDRs(fakeSubnetSpec2.Name, []string{to.String(fakeSubnet2.AddressPrefix)}) + s.UpdateSubnetID(fakeSubnetSpec2.Name, pointer.StringDeref(fakeSubnet2.ID, "")) + s.UpdateSubnetCIDRs(fakeSubnetSpec2.Name, []string{pointer.StringDeref(fakeSubnet2.AddressPrefix, "")}) s.IsVnetManaged().AnyTimes().Return(true) s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil) @@ -243,8 +243,8 @@ func TestReconcileSubnets(t *testing.T) { s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpecNotManaged}) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeSubnetSpecNotManaged, serviceName).Return(fakeSubnetNotManaged, nil) - s.UpdateSubnetID(fakeSubnetSpecNotManaged.Name, to.String(fakeSubnetNotManaged.ID)) - s.UpdateSubnetCIDRs(fakeSubnetSpecNotManaged.Name, []string{to.String(fakeSubnetNotManaged.AddressPrefix)}) + s.UpdateSubnetID(fakeSubnetSpecNotManaged.Name, pointer.StringDeref(fakeSubnetNotManaged.ID, "")) + s.UpdateSubnetCIDRs(fakeSubnetSpecNotManaged.Name, []string{pointer.StringDeref(fakeSubnetNotManaged.AddressPrefix, "")}) s.IsVnetManaged().AnyTimes().Return(false) }, @@ -256,8 +256,8 @@ func TestReconcileSubnets(t *testing.T) { s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeIpv6SubnetSpec}) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeIpv6SubnetSpec, serviceName).Return(fakeIpv6Subnet, nil) - s.UpdateSubnetID(fakeIpv6SubnetSpec.Name, to.String(fakeIpv6Subnet.ID)) - s.UpdateSubnetCIDRs(fakeIpv6SubnetSpec.Name, to.StringSlice(fakeIpv6Subnet.AddressPrefixes)) + s.UpdateSubnetID(fakeIpv6SubnetSpec.Name, pointer.StringDeref(fakeIpv6Subnet.ID, "")) + s.UpdateSubnetCIDRs(fakeIpv6SubnetSpec.Name, azure.StringSlice(fakeIpv6Subnet.AddressPrefixes)) s.IsVnetManaged().AnyTimes().Return(true) s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil) @@ -270,12 +270,12 @@ func TestReconcileSubnets(t *testing.T) { s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeIpv6SubnetSpec, &fakeIpv6SubnetSpecCP}) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeIpv6SubnetSpec, serviceName).Return(fakeIpv6Subnet, nil) - s.UpdateSubnetID(fakeIpv6SubnetSpec.Name, to.String(fakeIpv6Subnet.ID)) - s.UpdateSubnetCIDRs(fakeIpv6SubnetSpec.Name, to.StringSlice(fakeIpv6Subnet.AddressPrefixes)) + s.UpdateSubnetID(fakeIpv6SubnetSpec.Name, pointer.StringDeref(fakeIpv6Subnet.ID, "")) + s.UpdateSubnetCIDRs(fakeIpv6SubnetSpec.Name, azure.StringSlice(fakeIpv6Subnet.AddressPrefixes)) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeIpv6SubnetSpecCP, serviceName).Return(fakeIpv6SubnetCP, nil) - s.UpdateSubnetID(fakeIpv6SubnetSpecCP.Name, to.String(fakeIpv6SubnetCP.ID)) - s.UpdateSubnetCIDRs(fakeIpv6SubnetSpecCP.Name, to.StringSlice(fakeIpv6SubnetCP.AddressPrefixes)) + s.UpdateSubnetID(fakeIpv6SubnetSpecCP.Name, pointer.StringDeref(fakeIpv6SubnetCP.ID, "")) + s.UpdateSubnetCIDRs(fakeIpv6SubnetSpecCP.Name, azure.StringSlice(fakeIpv6SubnetCP.AddressPrefixes)) s.IsVnetManaged().AnyTimes().Return(true) s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil) @@ -308,8 +308,8 @@ func TestReconcileSubnets(t *testing.T) { r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(nil, internalError) r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeSubnetSpec2, serviceName).Return(fakeSubnet2, nil) - s.UpdateSubnetID(fakeSubnetSpec2.Name, to.String(fakeSubnet2.ID)) - s.UpdateSubnetCIDRs(fakeSubnetSpec2.Name, []string{to.String(fakeSubnet2.AddressPrefix)}) + s.UpdateSubnetID(fakeSubnetSpec2.Name, pointer.StringDeref(fakeSubnet2.ID, "")) + s.UpdateSubnetCIDRs(fakeSubnetSpec2.Name, []string{pointer.StringDeref(fakeSubnet2.AddressPrefix, "")}) s.IsVnetManaged().AnyTimes().Return(true) s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, internalError) diff --git a/azure/services/tags/tags.go b/azure/services/tags/tags.go index 3413c6c88809..2f5aa5df5383 100644 --- a/azure/services/tags/tags.go +++ b/azure/services/tags/tags.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-10-01/resources" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" "sigs.k8s.io/cluster-api-provider-azure/util/tele" @@ -87,7 +87,7 @@ func (s *Service) Reconcile(ctx context.Context) error { if len(createdOrUpdated) > 0 { createdOrUpdatedTags := make(map[string]*string) for k, v := range createdOrUpdated { - createdOrUpdatedTags[k] = to.StringPtr(v) + createdOrUpdatedTags[k] = pointer.String(v) } if _, err := s.client.UpdateAtScope(ctx, tagsSpec.Scope, resources.TagsPatchResource{Operation: "Merge", Properties: &resources.Tags{Tags: createdOrUpdatedTags}}); err != nil { @@ -98,7 +98,7 @@ func (s *Service) Reconcile(ctx context.Context) error { if len(deleted) > 0 { deletedTags := make(map[string]*string) for k, v := range deleted { - deletedTags[k] = to.StringPtr(v) + deletedTags[k] = pointer.String(v) } if _, err := s.client.UpdateAtScope(ctx, tagsSpec.Scope, resources.TagsPatchResource{Operation: "Delete", Properties: &resources.Tags{Tags: deletedTags}}); err != nil { diff --git a/azure/services/tags/tags_test.go b/azure/services/tags/tags_test.go index b3e02a6671ce..1d6f1ffa796a 100644 --- a/azure/services/tags/tags_test.go +++ b/azure/services/tags/tags_test.go @@ -23,9 +23,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-10-01/resources" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/tags/mock_tags" gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock" @@ -62,8 +62,8 @@ func TestReconcileTags(t *testing.T) { }), m.GetAtScope(gomockinternal.AContext(), "/sub/123/fake/scope").Return(resources.TagsResource{Properties: &resources.Tags{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), - "externalSystemTag": to.StringPtr("randomValue"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), + "externalSystemTag": pointer.String("randomValue"), }, }}, nil), s.AnnotationJSON("my-annotation"), @@ -71,16 +71,16 @@ func TestReconcileTags(t *testing.T) { Operation: "Merge", Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "thing": to.StringPtr("stuff"), + "foo": pointer.String("bar"), + "thing": pointer.String("stuff"), }, }, }), s.UpdateAnnotationJSON("my-annotation", map[string]interface{}{"foo": "bar", "thing": "stuff"}), m.GetAtScope(gomockinternal.AContext(), "/sub/123/other/scope").Return(resources.TagsResource{Properties: &resources.Tags{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), - "externalSystem2Tag": to.StringPtr("randomValue2"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), + "externalSystem2Tag": pointer.String("randomValue2"), }, }}, nil), s.AnnotationJSON("my-annotation-2"), @@ -88,7 +88,7 @@ func TestReconcileTags(t *testing.T) { Operation: "Merge", Properties: &resources.Tags{ Tags: map[string]*string{ - "tag1": to.StringPtr("value1"), + "tag1": pointer.String("value1"), }, }, }), @@ -131,9 +131,9 @@ func TestReconcileTags(t *testing.T) { }), m.GetAtScope(gomockinternal.AContext(), "/sub/123/fake/scope").Return(resources.TagsResource{Properties: &resources.Tags{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), - "foo": to.StringPtr("bar"), - "thing": to.StringPtr("stuff"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), + "foo": pointer.String("bar"), + "thing": pointer.String("stuff"), }, }}, nil), s.AnnotationJSON("my-annotation").Return(map[string]interface{}{"foo": "bar", "thing": "stuff"}, nil), @@ -141,7 +141,7 @@ func TestReconcileTags(t *testing.T) { Operation: "Delete", Properties: &resources.Tags{ Tags: map[string]*string{ - "thing": to.StringPtr("stuff"), + "thing": pointer.String("stuff"), }, }, }), @@ -183,7 +183,7 @@ func TestReconcileTags(t *testing.T) { }) m.GetAtScope(gomockinternal.AContext(), "/sub/123/fake/scope").Return(resources.TagsResource{Properties: &resources.Tags{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), }, }}, nil) s.AnnotationJSON("my-annotation") @@ -191,7 +191,7 @@ func TestReconcileTags(t *testing.T) { Operation: "Merge", Properties: &resources.Tags{ Tags: map[string]*string{ - "key": to.StringPtr("value"), + "key": pointer.String("value"), }, }, }).Return(resources.TagsResource{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: http.StatusInternalServerError}, "Internal Server Error")) @@ -213,8 +213,8 @@ func TestReconcileTags(t *testing.T) { }) m.GetAtScope(gomockinternal.AContext(), "/sub/123/fake/scope").Return(resources.TagsResource{Properties: &resources.Tags{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), - "key": to.StringPtr("value"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), + "key": pointer.String("value"), }, }}, nil) s.AnnotationJSON("my-annotation").Return(map[string]interface{}{"key": "value"}, nil) @@ -270,7 +270,7 @@ func TestTagsChanged(t *testing.T) { "foo": "hello", }, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), + "foo": pointer.String("hello"), }, expectedResult: false, expectedCreatedOrUpdated: map[string]string{}, @@ -286,7 +286,7 @@ func TestTagsChanged(t *testing.T) { "foo": "goodbye", }, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), + "foo": pointer.String("hello"), }, expectedResult: true, expectedCreatedOrUpdated: map[string]string{ @@ -302,7 +302,7 @@ func TestTagsChanged(t *testing.T) { }, desiredTags: map[string]string{}, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), + "foo": pointer.String("hello"), }, expectedResult: true, expectedCreatedOrUpdated: map[string]string{}, @@ -319,7 +319,7 @@ func TestTagsChanged(t *testing.T) { "bar": "welcome", }, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), + "foo": pointer.String("hello"), }, expectedResult: true, expectedCreatedOrUpdated: map[string]string{ @@ -338,7 +338,7 @@ func TestTagsChanged(t *testing.T) { "bar": "welcome", }, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), + "foo": pointer.String("hello"), }, expectedResult: true, expectedCreatedOrUpdated: map[string]string{ @@ -361,7 +361,7 @@ func TestTagsChanged(t *testing.T) { "bar": "welcome", }, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), + "foo": pointer.String("hello"), }, expectedResult: true, expectedCreatedOrUpdated: map[string]string{ @@ -383,8 +383,8 @@ func TestTagsChanged(t *testing.T) { "bar": "welcome", }, currentTags: map[string]*string{ - "foo": to.StringPtr("hello"), - "bar": to.StringPtr("random"), + "foo": pointer.String("hello"), + "bar": pointer.String("random"), }, expectedResult: true, expectedCreatedOrUpdated: map[string]string{ diff --git a/azure/services/virtualmachineimages/cache_test.go b/azure/services/virtualmachineimages/cache_test.go index a4d382a64816..6afb91e88978 100644 --- a/azure/services/virtualmachineimages/cache_test.go +++ b/azure/services/virtualmachineimages/cache_test.go @@ -21,10 +21,10 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachineimages/mock_virtualmachineimages" ) @@ -41,7 +41,7 @@ func TestCacheGet(t *testing.T) { location: "test", publisher: "foo", offer: "bar", sku: "baz", have: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("foo")}, + {Name: pointer.String("foo")}, }, }, expectedError: nil, diff --git a/azure/services/virtualmachineimages/images_test.go b/azure/services/virtualmachineimages/images_test.go index cef13acd43a5..09935b02b804 100644 --- a/azure/services/virtualmachineimages/images_test.go +++ b/azure/services/virtualmachineimages/images_test.go @@ -22,9 +22,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachineimages/mock_virtualmachineimages" @@ -88,9 +88,9 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "121.13.20220613", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("121.13.20220526")}, - {Name: to.StringPtr("121.13.20220613")}, - {Name: to.StringPtr("121.13.20220524")}, + {Name: pointer.String("121.13.20220526")}, + {Name: pointer.String("121.13.20220613")}, + {Name: pointer.String("121.13.20220524")}, }, }, }, @@ -110,8 +110,8 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "122.10.20220613", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("122.10.20220524")}, - {Name: to.StringPtr("122.10.20220613")}, + {Name: pointer.String("122.10.20220524")}, + {Name: pointer.String("122.10.20220613")}, }, }, }, @@ -121,7 +121,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "122.16.20221117", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("122.16.20221117")}, + {Name: pointer.String("122.16.20221117")}, }, }, }, @@ -136,10 +136,10 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "123.7.20231231", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("123.7.20221124")}, - {Name: to.StringPtr("123.7.20220524")}, - {Name: to.StringPtr("123.7.20231231")}, - {Name: to.StringPtr("123.7.20220818")}, + {Name: pointer.String("123.7.20221124")}, + {Name: pointer.String("123.7.20220524")}, + {Name: pointer.String("123.7.20231231")}, + {Name: pointer.String("123.7.20220818")}, }, }, }, @@ -149,7 +149,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "124.0.20220512", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("124.0.20220512")}, + {Name: pointer.String("124.0.20220512")}, }, }, }, @@ -159,7 +159,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "123.12.20220921", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("123.12.20220921")}, + {Name: pointer.String("123.12.20220921")}, }, }, }, @@ -169,7 +169,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "123.13.20221014", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("123.13.20221014")}, + {Name: pointer.String("123.13.20221014")}, }, }, }, @@ -179,7 +179,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "124.6.20220921", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("124.6.20220921")}, + {Name: pointer.String("124.6.20220921")}, }, }, }, @@ -189,7 +189,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "124.7.20221014", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("124.7.20221014")}, + {Name: pointer.String("124.7.20221014")}, }, }, }, @@ -199,7 +199,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "125.2.20220921", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("125.2.20220921")}, + {Name: pointer.String("125.2.20220921")}, }, }, }, @@ -209,7 +209,7 @@ func TestGetDefaultUbuntuImage(t *testing.T) { expectedVersion: "125.3.20221014", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("125.3.20221014")}, + {Name: pointer.String("125.3.20221014")}, }, }, }, @@ -434,17 +434,17 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "windows-2022", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("121.13.20220524")}, - {Name: to.StringPtr("124.0.20220512")}, - {Name: to.StringPtr("121.13.20220524")}, - {Name: to.StringPtr("123.13.20220524")}, - {Name: to.StringPtr("121.13.20220619")}, - {Name: to.StringPtr("121.13.20300524")}, - {Name: to.StringPtr("121.14.20220524")}, - {Name: to.StringPtr("121.12.20220524")}, - {Name: to.StringPtr("121.13.20220101")}, - {Name: to.StringPtr("121.13.20231231")}, - {Name: to.StringPtr("121.13.19991231")}, + {Name: pointer.String("121.13.20220524")}, + {Name: pointer.String("124.0.20220512")}, + {Name: pointer.String("121.13.20220524")}, + {Name: pointer.String("123.13.20220524")}, + {Name: pointer.String("121.13.20220619")}, + {Name: pointer.String("121.13.20300524")}, + {Name: pointer.String("121.14.20220524")}, + {Name: pointer.String("121.12.20220524")}, + {Name: pointer.String("121.13.20220101")}, + {Name: pointer.String("121.13.20231231")}, + {Name: pointer.String("121.13.19991231")}, }, }, }, @@ -484,7 +484,7 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "ubuntu-2004", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("123.12.20220921")}, + {Name: pointer.String("123.12.20220921")}, }, }, }, @@ -496,7 +496,7 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "ubuntu-2204", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("123.13.20220524")}, + {Name: pointer.String("123.13.20220524")}, }, }, }, @@ -516,7 +516,7 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "ubuntu-2004", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("124.0.20220512")}, + {Name: pointer.String("124.0.20220512")}, }, }, }, @@ -528,7 +528,7 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "windows-2022-containerd", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("124.0.20220606")}, + {Name: pointer.String("124.0.20220606")}, }, }, }, @@ -538,7 +538,7 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "windows-2022-containerd", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("124.0.20220606")}, + {Name: pointer.String("124.0.20220606")}, }, }, }, @@ -550,7 +550,7 @@ func TestGetDefaultImageSKUID(t *testing.T) { osAndVersion: "ubuntu-2204", versions: compute.ListVirtualMachineImageResource{ Value: &[]compute.VirtualMachineImageResource{ - {Name: to.StringPtr("125.4.20221011")}, + {Name: pointer.String("125.4.20221011")}, }, }, }, diff --git a/azure/services/virtualmachines/client.go b/azure/services/virtualmachines/client.go index ccc20869c005..a29510699273 100644 --- a/azure/services/virtualmachines/client.go +++ b/azure/services/virtualmachines/client.go @@ -26,8 +26,8 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/go-autorest/autorest" azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/util/reconciler" @@ -137,7 +137,7 @@ func (ac *AzureClient) DeleteAsync(ctx context.Context, spec azure.ResourceSpecG ctx, _, done := tele.StartSpanWithLogger(ctx, "virtualmachines.AzureClient.Delete") defer done() - forceDelete := to.BoolPtr(true) + forceDelete := pointer.Bool(true) deleteFuture, err := ac.virtualmachines.Delete(ctx, spec.ResourceGroupName(), spec.ResourceName(), forceDelete) if err != nil { return nil, err diff --git a/azure/services/virtualmachines/spec.go b/azure/services/virtualmachines/spec.go index 0a056871366f..c6d7fc83e9b4 100644 --- a/azure/services/virtualmachines/spec.go +++ b/azure/services/virtualmachines/spec.go @@ -22,8 +22,8 @@ import ( "fmt" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -115,12 +115,12 @@ func (s *VMSpec) Parameters(ctx context.Context, existing interface{}) (params i return compute.VirtualMachine{ Plan: converters.ImageToPlan(s.Image), - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), - Role: to.StringPtr(s.Role), + Name: pointer.String(s.Name), + Role: pointer.String(s.Role), Additional: s.AdditionalTags, })), VirtualMachineProperties: &compute.VirtualMachineProperties{ @@ -149,7 +149,7 @@ func (s *VMSpec) Parameters(ctx context.Context, existing interface{}) (params i func (s *VMSpec) generateStorageProfile() (*compute.StorageProfile, error) { storageProfile := &compute.StorageProfile{ OsDisk: &compute.OSDisk{ - Name: to.StringPtr(azure.GenerateOSDiskName(s.Name)), + Name: pointer.String(azure.GenerateOSDiskName(s.Name)), OsType: compute.OperatingSystemTypes(s.OSDisk.OSType), CreateOption: compute.DiskCreateOptionTypesFromImage, DiskSizeGB: s.OSDisk.DiskSizeGB, @@ -192,7 +192,7 @@ func (s *VMSpec) generateStorageProfile() (*compute.StorageProfile, error) { storageProfile.OsDisk.ManagedDisk.StorageAccountType = compute.StorageAccountTypes(s.OSDisk.ManagedDisk.StorageAccountType) } if s.OSDisk.ManagedDisk.DiskEncryptionSet != nil { - storageProfile.OsDisk.ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: to.StringPtr(s.OSDisk.ManagedDisk.DiskEncryptionSet.ID)} + storageProfile.OsDisk.ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: pointer.String(s.OSDisk.ManagedDisk.DiskEncryptionSet.ID)} } } @@ -200,9 +200,9 @@ func (s *VMSpec) generateStorageProfile() (*compute.StorageProfile, error) { for i, disk := range s.DataDisks { dataDisks[i] = compute.DataDisk{ CreateOption: compute.DiskCreateOptionTypesEmpty, - DiskSizeGB: to.Int32Ptr(disk.DiskSizeGB), + DiskSizeGB: pointer.Int32(disk.DiskSizeGB), Lun: disk.Lun, - Name: to.StringPtr(azure.GenerateDataDiskName(s.Name, disk.NameSuffix)), + Name: pointer.String(azure.GenerateDataDiskName(s.Name, disk.NameSuffix)), Caching: compute.CachingTypes(disk.CachingType), } @@ -212,7 +212,7 @@ func (s *VMSpec) generateStorageProfile() (*compute.StorageProfile, error) { } if disk.ManagedDisk.DiskEncryptionSet != nil { - dataDisks[i].ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: to.StringPtr(disk.ManagedDisk.DiskEncryptionSet.ID)} + dataDisks[i].ManagedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: pointer.String(disk.ManagedDisk.DiskEncryptionSet.ID)} } // check the support for ultra disks based on location and vm size @@ -240,9 +240,9 @@ func (s *VMSpec) generateOSProfile() (*compute.OSProfile, error) { } osProfile := &compute.OSProfile{ - ComputerName: to.StringPtr(s.Name), - AdminUsername: to.StringPtr(azure.DefaultUserName), - CustomData: to.StringPtr(s.BootstrapData), + ComputerName: pointer.String(s.Name), + AdminUsername: pointer.String(azure.DefaultUserName), + CustomData: pointer.String(s.BootstrapData), } switch s.OSDisk.OSType { @@ -254,18 +254,18 @@ func (s *VMSpec) generateOSProfile() (*compute.OSProfile, error) { // but the password on the VM will NOT be the same as created here. // Access is provided via SSH public key that is set during deployment // Azure also provides a way to reset user passwords in the case of need. - osProfile.AdminPassword = to.StringPtr(generators.SudoRandomPassword(123)) + osProfile.AdminPassword = pointer.String(generators.SudoRandomPassword(123)) osProfile.WindowsConfiguration = &compute.WindowsConfiguration{ - EnableAutomaticUpdates: to.BoolPtr(false), + EnableAutomaticUpdates: pointer.Bool(false), } default: osProfile.LinuxConfiguration = &compute.LinuxConfiguration{ - DisablePasswordAuthentication: to.BoolPtr(true), + DisablePasswordAuthentication: pointer.Bool(true), SSH: &compute.SSHConfiguration{ PublicKeys: &[]compute.SSHPublicKey{ { - Path: to.StringPtr(fmt.Sprintf("/home/%s/.ssh/authorized_keys", azure.DefaultUserName)), - KeyData: to.StringPtr(string(sshKey)), + Path: pointer.String(fmt.Sprintf("/home/%s/.ssh/authorized_keys", azure.DefaultUserName)), + KeyData: pointer.String(string(sshKey)), }, }, }, @@ -294,9 +294,9 @@ func (s *VMSpec) generateNICRefs() *[]compute.NetworkInterfaceReference { for i, id := range s.NICIDs { primary := i == 0 nicRefs[i] = compute.NetworkInterfaceReference{ - ID: to.StringPtr(id), + ID: pointer.String(id), NetworkInterfaceReferenceProperties: &compute.NetworkInterfaceReferenceProperties{ - Primary: to.BoolPtr(primary), + Primary: pointer.Bool(primary), }, } } @@ -311,7 +311,7 @@ func (s *VMSpec) generateAdditionalCapabilities() *compute.AdditionalCapabilitie for _, dataDisk := range s.DataDisks { if dataDisk.ManagedDisk != nil && dataDisk.ManagedDisk.StorageAccountType == string(compute.StorageAccountTypesUltraSSDLRS) { capabilities = &compute.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(true), + UltraSSDEnabled: pointer.Bool(true), } break } diff --git a/azure/services/virtualmachines/spec_test.go b/azure/services/virtualmachines/spec_test.go index 1e01617ef653..69ddfde51de4 100644 --- a/azure/services/virtualmachines/spec_test.go +++ b/azure/services/virtualmachines/spec_test.go @@ -22,9 +22,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus" @@ -33,83 +33,83 @@ import ( var ( validSKU = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v3"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v3"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("2"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("2"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, }, } validSKUWithEncryptionAtHost = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v3"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v3"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("2"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("2"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.EncryptionAtHost), - Value: to.StringPtr(string(resourceskus.CapabilitySupported)), + Name: pointer.String(resourceskus.EncryptionAtHost), + Value: pointer.String(string(resourceskus.CapabilitySupported)), }, }, } validSKUWithEphemeralOS = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v3"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v3"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("2"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("2"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, { - Name: to.StringPtr(resourceskus.EphemeralOSDisk), - Value: to.StringPtr("True"), + Name: pointer.String(resourceskus.EphemeralOSDisk), + Value: pointer.String("True"), }, }, } validSKUWithUltraSSD = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v3"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v3"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, LocationInfo: &[]compute.ResourceSkuLocationInfo{ { - Location: to.StringPtr("test-location"), + Location: pointer.String("test-location"), Zones: &[]string{"1"}, ZoneDetails: &[]compute.ResourceSkuZoneDetails{ { Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr("UltraSSDAvailable"), - Value: to.StringPtr("True"), + Name: pointer.String("UltraSSDAvailable"), + Value: pointer.String("True"), }, }, Name: &[]string{"1"}, @@ -119,48 +119,48 @@ var ( }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("2"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("2"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, }, } invalidCPUSKU = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v3"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v3"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("1"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("1"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("4"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("4"), }, }, } invalidMemSKU = resourceskus.SKU{ - Name: to.StringPtr("Standard_D2v3"), - Kind: to.StringPtr(string(resourceskus.VirtualMachines)), + Name: pointer.String("Standard_D2v3"), + Kind: pointer.String(string(resourceskus.VirtualMachines)), Locations: &[]string{ "test-location", }, Capabilities: &[]compute.ResourceSkuCapabilities{ { - Name: to.StringPtr(resourceskus.VCPUs), - Value: to.StringPtr("2"), + Name: pointer.String(resourceskus.VCPUs), + Value: pointer.String("2"), }, { - Name: to.StringPtr(resourceskus.MemoryGB), - Value: to.StringPtr("1"), + Name: pointer.String(resourceskus.MemoryGB), + Value: pointer.String("1"), }, }, } @@ -214,7 +214,7 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, Identity: infrav1.VMIdentitySystemAssigned, SKU: validSKU, }, @@ -235,7 +235,7 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, Identity: infrav1.VMIdentityUserAssigned, UserAssignedIdentities: []infrav1.UserAssignedIdentity{{ProviderID: "my-user-id"}}, SKU: validSKU, @@ -257,7 +257,7 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SpotVMOptions: &infrav1.SpotVMOptions{}, SKU: validSKU, }, @@ -279,7 +279,7 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SpotVMOptions: &infrav1.SpotVMOptions{EvictionPolicy: &deletePolicy}, SKU: validSKU, }, @@ -301,10 +301,10 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, OSDisk: infrav1.OSDisk{ OSType: "Windows", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, @@ -330,7 +330,7 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, OSDisk: infrav1.OSDisk{ ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", @@ -344,7 +344,7 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).VirtualMachineProperties.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet.ID).To(Equal(to.StringPtr("my-diskencryptionset-id"))) + g.Expect(result.(compute.VirtualMachine).VirtualMachineProperties.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet.ID).To(Equal(pointer.String("my-diskencryptionset-id"))) }, expectedError: "", }, @@ -357,8 +357,8 @@ func TestParameters(t *testing.T) { SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, - SecurityProfile: &infrav1.SecurityProfile{EncryptionAtHost: to.BoolPtr(true)}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, + SecurityProfile: &infrav1.SecurityProfile{EncryptionAtHost: pointer.Bool(true)}, SKU: validSKUWithEncryptionAtHost, }, existing: nil, @@ -378,14 +378,14 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", AvailabilitySetID: "fake-availability-set-id", Zone: "", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SKU: validSKU, }, existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) g.Expect(result.(compute.VirtualMachine).Zones).To(BeNil()) - g.Expect(result.(compute.VirtualMachine).AvailabilitySet.ID).To(Equal(to.StringPtr("fake-availability-set-id"))) + g.Expect(result.(compute.VirtualMachine).AvailabilitySet.ID).To(Equal(pointer.String("fake-availability-set-id"))) }, expectedError: "", }, @@ -399,7 +399,7 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", OSDisk: infrav1.OSDisk{ OSType: "Linux", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, @@ -407,7 +407,7 @@ func TestParameters(t *testing.T) { Option: string(compute.DiffDiskOptionsLocal), }, }, - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SKU: validSKUWithEphemeralOS, }, existing: nil, @@ -427,8 +427,8 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", AvailabilitySetID: "fake-availability-set-id", Zone: "", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, - SecurityProfile: &infrav1.SecurityProfile{EncryptionAtHost: to.BoolPtr(true)}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, + SecurityProfile: &infrav1.SecurityProfile{EncryptionAtHost: pointer.Bool(true)}, SKU: validSKU, }, existing: nil, @@ -447,7 +447,7 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", OSDisk: infrav1.OSDisk{ OSType: "Linux", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, @@ -455,7 +455,7 @@ func TestParameters(t *testing.T) { Option: string(compute.DiffDiskOptionsLocal), }, }, - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SKU: validSKU, }, existing: nil, @@ -472,7 +472,7 @@ func TestParameters(t *testing.T) { NICIDs: []string{"my-nic"}, SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SKU: invalidCPUSKU, }, existing: nil, @@ -489,7 +489,7 @@ func TestParameters(t *testing.T) { NICIDs: []string{"my-nic"}, SSHKeyData: "fakesshpublickey", Size: "Standard_D2v3", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, SKU: invalidMemSKU, }, existing: nil, @@ -522,13 +522,13 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Offer).To(Equal(to.StringPtr("my-offer"))) - g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Publisher).To(Equal(to.StringPtr("fake-publisher"))) - g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Sku).To(Equal(to.StringPtr("sku-id"))) - g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Version).To(Equal(to.StringPtr("1.0"))) - g.Expect(result.(compute.VirtualMachine).Plan.Name).To(Equal(to.StringPtr("sku-id"))) - g.Expect(result.(compute.VirtualMachine).Plan.Publisher).To(Equal(to.StringPtr("fake-publisher"))) - g.Expect(result.(compute.VirtualMachine).Plan.Product).To(Equal(to.StringPtr("my-offer"))) + g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Offer).To(Equal(pointer.String("my-offer"))) + g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Publisher).To(Equal(pointer.String("fake-publisher"))) + g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Sku).To(Equal(pointer.String("sku-id"))) + g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.Version).To(Equal(pointer.String("1.0"))) + g.Expect(result.(compute.VirtualMachine).Plan.Name).To(Equal(pointer.String("sku-id"))) + g.Expect(result.(compute.VirtualMachine).Plan.Publisher).To(Equal(pointer.String("fake-publisher"))) + g.Expect(result.(compute.VirtualMachine).Plan.Product).To(Equal(pointer.String("my-offer"))) }, expectedError: "", }, @@ -547,9 +547,9 @@ func TestParameters(t *testing.T) { Gallery: "fake-gallery", Name: "fake-name", Version: "1.0", - Publisher: to.StringPtr("fake-publisher"), - Offer: to.StringPtr("my-offer"), - SKU: to.StringPtr("sku-id"), + Publisher: pointer.String("fake-publisher"), + Offer: pointer.String("my-offer"), + SKU: pointer.String("sku-id"), }, }, SKU: validSKU, @@ -557,10 +557,10 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.ID).To(Equal(to.StringPtr("/subscriptions/fake-sub-id/resourceGroups/fake-rg/providers/Microsoft.Compute/galleries/fake-gallery/images/fake-name/versions/1.0"))) - g.Expect(result.(compute.VirtualMachine).Plan.Name).To(Equal(to.StringPtr("sku-id"))) - g.Expect(result.(compute.VirtualMachine).Plan.Publisher).To(Equal(to.StringPtr("fake-publisher"))) - g.Expect(result.(compute.VirtualMachine).Plan.Product).To(Equal(to.StringPtr("my-offer"))) + g.Expect(result.(compute.VirtualMachine).StorageProfile.ImageReference.ID).To(Equal(pointer.String("/subscriptions/fake-sub-id/resourceGroups/fake-rg/providers/Microsoft.Compute/galleries/fake-gallery/images/fake-name/versions/1.0"))) + g.Expect(result.(compute.VirtualMachine).Plan.Name).To(Equal(pointer.String("sku-id"))) + g.Expect(result.(compute.VirtualMachine).Plan.Publisher).To(Equal(pointer.String("fake-publisher"))) + g.Expect(result.(compute.VirtualMachine).Plan.Product).To(Equal(pointer.String("my-offer"))) }, expectedError: "", }, @@ -574,17 +574,17 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DataDisks: []infrav1.DataDisk{ { NameSuffix: "mydisk", DiskSizeGB: 64, - Lun: to.Int32Ptr(0), + Lun: pointer.Int32(0), }, { NameSuffix: "myDiskWithUltraDisk", DiskSizeGB: 128, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -592,7 +592,7 @@ func TestParameters(t *testing.T) { { NameSuffix: "myDiskWithManagedDisk", DiskSizeGB: 128, - Lun: to.Int32Ptr(2), + Lun: pointer.Int32(2), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, @@ -600,7 +600,7 @@ func TestParameters(t *testing.T) { { NameSuffix: "managedDiskWithEncryption", DiskSizeGB: 128, - Lun: to.Int32Ptr(3), + Lun: pointer.Int32(3), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", DiskEncryptionSet: &infrav1.DiskEncryptionSetParameters{ @@ -614,41 +614,41 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(to.BoolPtr(true))) + g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(pointer.Bool(true))) expectedDataDisks := &[]compute.DataDisk{ { - Lun: to.Int32Ptr(0), - Name: to.StringPtr("my-ultra-ssd-vm_mydisk"), + Lun: pointer.Int32(0), + Name: pointer.String("my-ultra-ssd-vm_mydisk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(64), + DiskSizeGB: pointer.Int32(64), }, { - Lun: to.Int32Ptr(1), - Name: to.StringPtr("my-ultra-ssd-vm_myDiskWithUltraDisk"), + Lun: pointer.Int32(1), + Name: pointer.String("my-ultra-ssd-vm_myDiskWithUltraDisk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, }, { - Lun: to.Int32Ptr(2), - Name: to.StringPtr("my-ultra-ssd-vm_myDiskWithManagedDisk"), + Lun: pointer.Int32(2), + Name: pointer.String("my-ultra-ssd-vm_myDiskWithManagedDisk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", }, }, { - Lun: to.Int32Ptr(3), - Name: to.StringPtr("my-ultra-ssd-vm_managedDiskWithEncryption"), + Lun: pointer.Int32(3), + Name: pointer.String("my-ultra-ssd-vm_managedDiskWithEncryption"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.ManagedDiskParameters{ StorageAccountType: "Premium_LRS", DiskEncryptionSet: &compute.DiskEncryptionSetParameters{ - ID: to.StringPtr("my_id"), + ID: pointer.String("my_id"), }, }, }, @@ -667,12 +667,12 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DataDisks: []infrav1.DataDisk{ { NameSuffix: "myDiskWithUltraDisk", DiskSizeGB: 128, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -696,15 +696,15 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, AdditionalCapabilities: &infrav1.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(false), + UltraSSDEnabled: pointer.Bool(false), }, DataDisks: []infrav1.DataDisk{ { NameSuffix: "myDiskWithUltraDisk", DiskSizeGB: 128, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -715,13 +715,13 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(to.BoolPtr(false))) + g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(pointer.Bool(false))) expectedDataDisks := &[]compute.DataDisk{ { - Lun: to.Int32Ptr(1), - Name: to.StringPtr("my-ultra-ssd-vm_myDiskWithUltraDisk"), + Lun: pointer.Int32(1), + Name: pointer.String("my-ultra-ssd-vm_myDiskWithUltraDisk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -741,12 +741,12 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DataDisks: []infrav1.DataDisk{ { NameSuffix: "myDiskWithUltraDisk", DiskSizeGB: 128, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -757,13 +757,13 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(to.BoolPtr(true))) + g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(pointer.Bool(true))) expectedDataDisks := &[]compute.DataDisk{ { - Lun: to.Int32Ptr(1), - Name: to.StringPtr("my-ultra-ssd-vm_myDiskWithUltraDisk"), + Lun: pointer.Int32(1), + Name: pointer.String("my-ultra-ssd-vm_myDiskWithUltraDisk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -783,15 +783,15 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, AdditionalCapabilities: &infrav1.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(true), + UltraSSDEnabled: pointer.Bool(true), }, DataDisks: []infrav1.DataDisk{ { NameSuffix: "myDiskWithUltraDisk", DiskSizeGB: 128, - Lun: to.Int32Ptr(1), + Lun: pointer.Int32(1), ManagedDisk: &infrav1.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -802,13 +802,13 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(to.BoolPtr(true))) + g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(pointer.Bool(true))) expectedDataDisks := &[]compute.DataDisk{ { - Lun: to.Int32Ptr(1), - Name: to.StringPtr("my-ultra-ssd-vm_myDiskWithUltraDisk"), + Lun: pointer.Int32(1), + Name: pointer.String("my-ultra-ssd-vm_myDiskWithUltraDisk"), CreateOption: "Empty", - DiskSizeGB: to.Int32Ptr(128), + DiskSizeGB: pointer.Int32(128), ManagedDisk: &compute.ManagedDiskParameters{ StorageAccountType: "UltraSSD_LRS", }, @@ -828,16 +828,16 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, AdditionalCapabilities: &infrav1.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(true), + UltraSSDEnabled: pointer.Bool(true), }, SKU: validSKUWithUltraSSD, }, existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(to.BoolPtr(true))) + g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(pointer.Bool(true))) }, expectedError: "", }, @@ -851,16 +851,16 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, AdditionalCapabilities: &infrav1.AdditionalCapabilities{ - UltraSSDEnabled: to.BoolPtr(false), + UltraSSDEnabled: pointer.Bool(false), }, SKU: validSKUWithUltraSSD, }, existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(to.BoolPtr(false))) + g.Expect(result.(compute.VirtualMachine).AdditionalCapabilities.UltraSSDEnabled).To(Equal(pointer.Bool(false))) }, expectedError: "", }, @@ -874,7 +874,7 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DiagnosticsProfile: &infrav1.Diagnostics{ Boot: &infrav1.BootDiagnostics{ StorageAccountType: infrav1.DisabledDiagnosticsStorage, @@ -885,7 +885,7 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(to.BoolPtr(false))) + g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(pointer.Bool(false))) g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.StorageURI).To(BeNil()) }, expectedError: "", @@ -900,7 +900,7 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DiagnosticsProfile: &infrav1.Diagnostics{ Boot: &infrav1.BootDiagnostics{ StorageAccountType: infrav1.ManagedDiagnosticsStorage, @@ -911,7 +911,7 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(to.BoolPtr(true))) + g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(pointer.Bool(true))) g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.StorageURI).To(BeNil()) }, expectedError: "", @@ -926,7 +926,7 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DiagnosticsProfile: &infrav1.Diagnostics{ Boot: &infrav1.BootDiagnostics{ StorageAccountType: infrav1.UserManagedDiagnosticsStorage, @@ -940,8 +940,8 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(to.BoolPtr(true))) - g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.StorageURI).To(Equal(to.StringPtr("aaa"))) + g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(pointer.Bool(true))) + g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.StorageURI).To(Equal(pointer.String("aaa"))) }, expectedError: "", }, @@ -955,7 +955,7 @@ func TestParameters(t *testing.T) { Size: "Standard_D2v3", Location: "test-location", Zone: "1", - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, DiagnosticsProfile: &infrav1.Diagnostics{ Boot: &infrav1.BootDiagnostics{ StorageAccountType: infrav1.UserManagedDiagnosticsStorage, @@ -969,8 +969,8 @@ func TestParameters(t *testing.T) { existing: nil, expect: func(g *WithT, result interface{}) { g.Expect(result).To(BeAssignableToTypeOf(compute.VirtualMachine{})) - g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(to.BoolPtr(true))) - g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.StorageURI).To(Equal(to.StringPtr("aaa"))) + g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.Enabled).To(Equal(pointer.Bool(true))) + g.Expect(result.(compute.VirtualMachine).DiagnosticsProfile.BootDiagnostics.StorageURI).To(Equal(pointer.String("aaa"))) }, expectedError: "", }, diff --git a/azure/services/virtualmachines/virtualmachines.go b/azure/services/virtualmachines/virtualmachines.go index 3648442e79d5..32ad5679871a 100644 --- a/azure/services/virtualmachines/virtualmachines.go +++ b/azure/services/virtualmachines/virtualmachines.go @@ -22,9 +22,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" + "k8s.io/utils/pointer" azprovider "sigs.k8s.io/cloud-provider-azure/pkg/provider" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" @@ -190,7 +190,7 @@ func (s *Service) getAddresses(ctx context.Context, vm compute.VirtualMachine, r addresses := []corev1.NodeAddress{ { Type: corev1.NodeInternalDNS, - Address: to.String(vm.Name), + Address: pointer.StringDeref(vm.Name, ""), }, } if vm.NetworkProfile.NetworkInterfaces == nil { @@ -203,7 +203,7 @@ func (s *Service) getAddresses(ctx context.Context, vm compute.VirtualMachine, r if nicRef.ID == nil { continue } - nicName := getResourceNameByID(to.String(nicRef.ID)) + nicName := getResourceNameByID(pointer.StringDeref(nicRef.ID, "")) // Fetch nic and append its addresses existingNic, err := s.interfacesGetter.Get(ctx, &networkinterfaces.NICSpec{ @@ -227,7 +227,7 @@ func (s *Service) getAddresses(ctx context.Context, vm compute.VirtualMachine, r addresses = append(addresses, corev1.NodeAddress{ Type: corev1.NodeInternalIP, - Address: to.String(ipConfig.PrivateIPAddress), + Address: pointer.StringDeref(ipConfig.PrivateIPAddress, ""), }, ) } @@ -237,7 +237,7 @@ func (s *Service) getAddresses(ctx context.Context, vm compute.VirtualMachine, r } // ID is the only field populated in PublicIPAddress sub-resource. // Thus, we have to go fetch the publicIP with the name. - publicIPName := getResourceNameByID(to.String(ipConfig.PublicIPAddress.ID)) + publicIPName := getResourceNameByID(pointer.StringDeref(ipConfig.PublicIPAddress.ID, "")) publicNodeAddress, err := s.getPublicIPAddress(ctx, publicIPName, rgName) if err != nil { return addresses, err @@ -269,7 +269,7 @@ func (s *Service) getPublicIPAddress(ctx context.Context, publicIPAddressName st } retAddress.Type = corev1.NodeExternalIP - retAddress.Address = to.String(publicIP.IPAddress) + retAddress.Address = pointer.StringDeref(publicIP.IPAddress, "") return retAddress, nil } diff --git a/azure/services/virtualmachines/virtualmachines_test.go b/azure/services/virtualmachines/virtualmachines_test.go index 797314d1453e..f89d35893ae3 100644 --- a/azure/services/virtualmachines/virtualmachines_test.go +++ b/azure/services/virtualmachines/virtualmachines_test.go @@ -24,11 +24,11 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" "sigs.k8s.io/cluster-api-provider-azure/azure/services/identities/mock_identities" @@ -52,18 +52,18 @@ var ( AvailabilitySetID: "availability-set", Identity: infrav1.VMIdentitySystemAssigned, AdditionalTags: map[string]string{"foo": "bar"}, - Image: &infrav1.Image{ID: to.StringPtr("fake-image-id")}, + Image: &infrav1.Image{ID: pointer.String("fake-image-id")}, BootstrapData: "fake data", } fakeExistingVM = compute.VirtualMachine{ - ID: to.StringPtr("subscriptions/123/resourceGroups/my_resource_group/providers/Microsoft.Compute/virtualMachines/my-vm"), - Name: to.StringPtr("test-vm-name"), + ID: pointer.String("subscriptions/123/resourceGroups/my_resource_group/providers/Microsoft.Compute/virtualMachines/my-vm"), + Name: pointer.String("test-vm-name"), VirtualMachineProperties: &compute.VirtualMachineProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: pointer.String("Succeeded"), NetworkProfile: &compute.NetworkProfile{ NetworkInterfaces: &[]compute.NetworkInterfaceReference{ { - ID: to.StringPtr("/subscriptions/123/resourceGroups/test-rg/providers/Microsoft.Network/networkInterfaces/nic-1"), + ID: pointer.String("/subscriptions/123/resourceGroups/test-rg/providers/Microsoft.Network/networkInterfaces/nic-1"), }, }, }, @@ -78,9 +78,9 @@ var ( IPConfigurations: &[]network.InterfaceIPConfiguration{ { InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ - PrivateIPAddress: to.StringPtr("10.0.0.5"), + PrivateIPAddress: pointer.String("10.0.0.5"), PublicIPAddress: &network.PublicIPAddress{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/test-rg/providers/Microsoft.Network/publicIPAddresses/pip-1"), + ID: pointer.String("/subscriptions/123/resourceGroups/test-rg/providers/Microsoft.Network/publicIPAddresses/pip-1"), }, }, }, @@ -93,7 +93,7 @@ var ( } fakePublicIPs = network.PublicIPAddress{ PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ - IPAddress: to.StringPtr("10.0.0.6"), + IPAddress: pointer.String("10.0.0.6"), }, } fakeNodeAddresses = []corev1.NodeAddress{ diff --git a/azure/services/virtualnetworks/spec.go b/azure/services/virtualnetworks/spec.go index 961e76796ae2..6159ff0548d7 100644 --- a/azure/services/virtualnetworks/spec.go +++ b/azure/services/virtualnetworks/spec.go @@ -20,7 +20,7 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" ) @@ -60,11 +60,11 @@ func (s *VNetSpec) Parameters(ctx context.Context, existing interface{}) (interf Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ ClusterName: s.ClusterName, Lifecycle: infrav1.ResourceLifecycleOwned, - Name: to.StringPtr(s.Name), - Role: to.StringPtr(infrav1.CommonRole), + Name: pointer.String(s.Name), + Role: pointer.String(infrav1.CommonRole), Additional: s.AdditionalTags, })), - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), VirtualNetworkPropertiesFormat: &network.VirtualNetworkPropertiesFormat{ AddressSpace: &network.AddressSpace{ AddressPrefixes: &s.CIDRs, diff --git a/azure/services/virtualnetworks/virtualnetworks.go b/azure/services/virtualnetworks/virtualnetworks.go index 92a15fadfb13..9ee8599d6fbe 100644 --- a/azure/services/virtualnetworks/virtualnetworks.go +++ b/azure/services/virtualnetworks/virtualnetworks.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/converters" @@ -89,12 +89,12 @@ func (s *Service) Reconcile(ctx context.Context) error { return errors.Errorf("%T is not a network.VirtualNetwork", result) } vnet := s.Scope.Vnet() - vnet.ID = to.String(existingVnet.ID) + vnet.ID = pointer.StringDeref(existingVnet.ID, "") vnet.Tags = converters.MapToTags(existingVnet.Tags) var prefixes []string if existingVnet.VirtualNetworkPropertiesFormat != nil && existingVnet.VirtualNetworkPropertiesFormat.AddressSpace != nil { - prefixes = to.StringSlice(existingVnet.VirtualNetworkPropertiesFormat.AddressSpace.AddressPrefixes) + prefixes = azure.StringSlice(existingVnet.VirtualNetworkPropertiesFormat.AddressSpace.AddressPrefixes) } vnet.CIDRBlocks = prefixes @@ -103,7 +103,7 @@ func (s *Service) Reconcile(ctx context.Context) error { // Subnets that are not part of this cluster spec are silently ignored. if existingVnet.Subnets != nil { for _, subnet := range *existingVnet.Subnets { - s.Scope.UpdateSubnetCIDRs(to.String(subnet.Name), converters.GetSubnetAddresses(subnet)) + s.Scope.UpdateSubnetCIDRs(pointer.StringDeref(subnet.Name, ""), converters.GetSubnetAddresses(subnet)) } } } diff --git a/azure/services/virtualnetworks/virtualnetworks_test.go b/azure/services/virtualnetworks/virtualnetworks_test.go index 8fe82195a96f..3af3847f67ee 100644 --- a/azure/services/virtualnetworks/virtualnetworks_test.go +++ b/azure/services/virtualnetworks/virtualnetworks_test.go @@ -24,9 +24,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-10-01/resources" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async" @@ -44,19 +44,19 @@ var ( AdditionalTags: map[string]string{"foo": "bar"}, } managedVnet = network.VirtualNetwork{ - ID: to.StringPtr("/subscriptions/subscription/resourceGroups/test-group/providers/Microsoft.Network/virtualNetworks/test-vnet"), - Name: to.StringPtr("test-vnet"), + ID: pointer.String("/subscriptions/subscription/resourceGroups/test-group/providers/Microsoft.Network/virtualNetworks/test-vnet"), + Name: pointer.String("test-vnet"), Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), + "foo": pointer.String("bar"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), }, } managedTags = resources.TagsResource{ Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": to.StringPtr("owned"), + "foo": pointer.String("bar"), + "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": pointer.String("owned"), }, }, } @@ -64,18 +64,18 @@ var ( unmanagedTags = resources.TagsResource{ Properties: &resources.Tags{ Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "something": to.StringPtr("else"), + "foo": pointer.String("bar"), + "something": pointer.String("else"), }, }, } customVnet = network.VirtualNetwork{ - ID: to.StringPtr("/subscriptions/subscription/resourceGroups/test-group/providers/Microsoft.Network/virtualNetworks/test-vnet"), - Name: to.StringPtr("test-vnet"), + ID: pointer.String("/subscriptions/subscription/resourceGroups/test-group/providers/Microsoft.Network/virtualNetworks/test-vnet"), + Name: pointer.String("test-vnet"), Tags: map[string]*string{ - "foo": to.StringPtr("bar"), - "something": to.StringPtr("else"), + "foo": pointer.String("bar"), + "something": pointer.String("else"), }, VirtualNetworkPropertiesFormat: &network.VirtualNetworkPropertiesFormat{ AddressSpace: &network.AddressSpace{ @@ -83,13 +83,13 @@ var ( }, Subnets: &[]network.Subnet{ { - Name: to.StringPtr("test-subnet"), + Name: pointer.String("test-subnet"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr("subnet-cidr"), + AddressPrefix: pointer.String("subnet-cidr"), }, }, { - Name: to.StringPtr("test-subnet-2"), + Name: pointer.String("test-subnet-2"), SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ AddressPrefixes: &[]string{ "subnet-cidr-1", diff --git a/azure/services/vmextensions/spec.go b/azure/services/vmextensions/spec.go index c7c8873c5545..3ae8129b7c2c 100644 --- a/azure/services/vmextensions/spec.go +++ b/azure/services/vmextensions/spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -61,12 +61,12 @@ func (s *VMExtensionSpec) Parameters(ctx context.Context, existing interface{}) return compute.VirtualMachineExtension{ VirtualMachineExtensionProperties: &compute.VirtualMachineExtensionProperties{ - Publisher: to.StringPtr(s.Publisher), - Type: to.StringPtr(s.Name), - TypeHandlerVersion: to.StringPtr(s.Version), + Publisher: pointer.String(s.Publisher), + Type: pointer.String(s.Name), + TypeHandlerVersion: pointer.String(s.Version), Settings: s.Settings, ProtectedSettings: s.ProtectedSettings, }, - Location: to.StringPtr(s.Location), + Location: pointer.String(s.Location), }, nil } diff --git a/azure/services/vmextensions/spec_test.go b/azure/services/vmextensions/spec_test.go index 8b34639c7db7..9b7ca7821a48 100644 --- a/azure/services/vmextensions/spec_test.go +++ b/azure/services/vmextensions/spec_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -42,13 +42,13 @@ var ( fakeVMExtensionParams = compute.VirtualMachineExtension{ VirtualMachineExtensionProperties: &compute.VirtualMachineExtensionProperties{ - Publisher: to.StringPtr("my-publisher"), - Type: to.StringPtr("my-vm-extension"), - TypeHandlerVersion: to.StringPtr("1.0"), + Publisher: pointer.String("my-publisher"), + Type: pointer.String("my-vm-extension"), + TypeHandlerVersion: pointer.String("1.0"), Settings: map[string]string{"my-setting": "my-value"}, ProtectedSettings: map[string]string{"my-protected-setting": "my-protected-value"}, }, - Location: to.StringPtr("my-location"), + Location: pointer.String("my-location"), } ) diff --git a/azure/services/vnetpeerings/spec.go b/azure/services/vnetpeerings/spec.go index 04a687790d20..9cc8a649cf75 100644 --- a/azure/services/vnetpeerings/spec.go +++ b/azure/services/vnetpeerings/spec.go @@ -20,8 +20,8 @@ import ( "context" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" ) @@ -62,11 +62,11 @@ func (s *VnetPeeringSpec) Parameters(ctx context.Context, existing interface{}) vnetID := azure.VNetID(s.SubscriptionID, s.RemoteResourceGroup, s.RemoteVnetName) peeringProperties := network.VirtualNetworkPeeringPropertiesFormat{ RemoteVirtualNetwork: &network.SubResource{ - ID: to.StringPtr(vnetID), + ID: pointer.String(vnetID), }, } return network.VirtualNetworkPeering{ - Name: to.StringPtr(s.PeeringName), + Name: pointer.String(s.PeeringName), VirtualNetworkPeeringPropertiesFormat: &peeringProperties, }, nil } diff --git a/azure/types_test.go b/azure/types_test.go index d72d3b2878e3..df86eb783d86 100644 --- a/azure/types_test.go +++ b/azure/types_test.go @@ -19,8 +19,8 @@ package azure import ( "testing" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -107,7 +107,7 @@ func TestVMSS_HasModelChanges(t *testing.T) { Factory: func() (VMSS, VMSS) { l := getDefaultVMSSForModelTesting() l.Image = infrav1.Image{ - ID: to.StringPtr("foo"), + ID: pointer.String("foo"), } r := getDefaultVMSSForModelTesting() return r, l diff --git a/exp/api/v1beta1/azuremachinepool_default_test.go b/exp/api/v1beta1/azuremachinepool_default_test.go index a7b982a349d4..3f401b4d5f00 100644 --- a/exp/api/v1beta1/azuremachinepool_default_test.go +++ b/exp/api/v1beta1/azuremachinepool_default_test.go @@ -19,9 +19,9 @@ package v1beta1 import ( "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/google/uuid" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" ) @@ -181,7 +181,7 @@ func TestAzureMachinePool_SetNetworkInterfacesDefaults(t *testing.T) { Spec: AzureMachinePoolSpec{ Template: AzureMachinePoolMachineTemplate{ SubnetName: "test-subnet", - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), }, }, }, @@ -194,7 +194,7 @@ func TestAzureMachinePool_SetNetworkInterfacesDefaults(t *testing.T) { { SubnetName: "test-subnet", PrivateIPConfigs: 1, - AcceleratedNetworking: to.BoolPtr(true), + AcceleratedNetworking: pointer.Bool(true), }, }, }, diff --git a/exp/api/v1beta1/azuremachinepool_test.go b/exp/api/v1beta1/azuremachinepool_test.go index 4b727778568c..833378e15ca9 100644 --- a/exp/api/v1beta1/azuremachinepool_test.go +++ b/exp/api/v1beta1/azuremachinepool_test.go @@ -19,9 +19,9 @@ package v1beta1_test import ( "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/onsi/gomega" utilfeature "k8s.io/component-base/featuregate/testing" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/feature" @@ -88,7 +88,7 @@ func TestAzureMachinePool_Validate(t *testing.T) { return &infrav1exp.AzureMachinePool{ Spec: infrav1exp.AzureMachinePoolSpec{ Template: infrav1exp.AzureMachinePoolMachineTemplate{ - TerminateNotificationTimeout: to.IntPtr(7), + TerminateNotificationTimeout: pointer.Int(7), }, }, } @@ -103,7 +103,7 @@ func TestAzureMachinePool_Validate(t *testing.T) { return &infrav1exp.AzureMachinePool{ Spec: infrav1exp.AzureMachinePoolSpec{ Template: infrav1exp.AzureMachinePoolMachineTemplate{ - TerminateNotificationTimeout: to.IntPtr(20), + TerminateNotificationTimeout: pointer.Int(20), }, }, } @@ -119,7 +119,7 @@ func TestAzureMachinePool_Validate(t *testing.T) { return &infrav1exp.AzureMachinePool{ Spec: infrav1exp.AzureMachinePoolSpec{ Template: infrav1exp.AzureMachinePoolMachineTemplate{ - TerminateNotificationTimeout: to.IntPtr(3), + TerminateNotificationTimeout: pointer.Int(3), }, }, } diff --git a/exp/api/v1beta1/azuremachinepool_webhook_test.go b/exp/api/v1beta1/azuremachinepool_webhook_test.go index 90e0a7a0474d..1ece0c54cca9 100644 --- a/exp/api/v1beta1/azuremachinepool_webhook_test.go +++ b/exp/api/v1beta1/azuremachinepool_webhook_test.go @@ -24,13 +24,13 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/Azure/go-autorest/autorest/to" guuid "github.com/google/uuid" . "github.com/onsi/gomega" "golang.org/x/crypto/ssh" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/uuid" utilfeature "k8s.io/component-base/featuregate/testing" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/feature" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" @@ -64,32 +64,32 @@ func TestAzureMachinePool_ValidateCreate(t *testing.T) { }, { name: "azuremachinepool with marketplace image - full", - amp: createMachinePoolWithMarketPlaceImage("PUB1234", "OFFER1234", "SKU1234", "1.0.0", to.IntPtr(10)), + amp: createMachinePoolWithMarketPlaceImage("PUB1234", "OFFER1234", "SKU1234", "1.0.0", pointer.Int(10)), wantErr: false, }, { name: "azuremachinepool with marketplace image - missing publisher", - amp: createMachinePoolWithMarketPlaceImage("", "OFFER1234", "SKU1234", "1.0.0", to.IntPtr(10)), + amp: createMachinePoolWithMarketPlaceImage("", "OFFER1234", "SKU1234", "1.0.0", pointer.Int(10)), wantErr: true, }, { name: "azuremachinepool with shared gallery image - full", - amp: createMachinePoolWithSharedImage("SUB123", "RG123", "NAME123", "GALLERY1", "1.0.0", to.IntPtr(10)), + amp: createMachinePoolWithSharedImage("SUB123", "RG123", "NAME123", "GALLERY1", "1.0.0", pointer.Int(10)), wantErr: false, }, { name: "azuremachinepool with marketplace image - missing subscription", - amp: createMachinePoolWithSharedImage("", "RG123", "NAME123", "GALLERY1", "1.0.0", to.IntPtr(10)), + amp: createMachinePoolWithSharedImage("", "RG123", "NAME123", "GALLERY1", "1.0.0", pointer.Int(10)), wantErr: true, }, { name: "azuremachinepool with image by - with id", - amp: createMachinePoolWithImageByID("ID123", to.IntPtr(10)), + amp: createMachinePoolWithImageByID("ID123", pointer.Int(10)), wantErr: false, }, { name: "azuremachinepool with image by - without id", - amp: createMachinePoolWithImageByID("", to.IntPtr(10)), + amp: createMachinePoolWithImageByID("", pointer.Int(10)), wantErr: true, }, { @@ -104,7 +104,7 @@ func TestAzureMachinePool_ValidateCreate(t *testing.T) { }, { name: "azuremachinepool with wrong terminate notification", - amp: createMachinePoolWithSharedImage("SUB123", "RG123", "NAME123", "GALLERY1", "1.0.0", to.IntPtr(35)), + amp: createMachinePoolWithSharedImage("SUB123", "RG123", "NAME123", "GALLERY1", "1.0.0", pointer.Int(35)), wantErr: true, }, { @@ -555,7 +555,7 @@ func getKnownValidAzureMachinePool() *AzureMachinePool { Template: AzureMachinePoolMachineTemplate{ Image: &image, SSHPublicKey: validSSHPublicKey, - TerminateNotificationTimeout: to.IntPtr(10), + TerminateNotificationTimeout: pointer.Int(10), }, Identity: infrav1.VMIdentitySystemAssigned, RoleAssignmentName: string(uuid.NewUUID()), diff --git a/exp/api/v1beta1/azuremanagedcontrolplane_default.go b/exp/api/v1beta1/azuremanagedcontrolplane_default.go index bca099835f05..4dc19c061d4c 100644 --- a/exp/api/v1beta1/azuremanagedcontrolplane_default.go +++ b/exp/api/v1beta1/azuremanagedcontrolplane_default.go @@ -20,8 +20,8 @@ import ( "encoding/base64" "fmt" - "github.com/Azure/go-autorest/autorest/to" "golang.org/x/crypto/ssh" + "k8s.io/utils/pointer" utilSSH "sigs.k8s.io/cluster-api-provider-azure/util/ssh" ) @@ -92,55 +92,55 @@ func (m *AzureManagedControlPlane) setDefaultAutoScalerProfile() { // Default values are from https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler#using-the-autoscaler-profile // If any values are set, they all need to be set. if m.Spec.AutoScalerProfile.BalanceSimilarNodeGroups == nil { - m.Spec.AutoScalerProfile.BalanceSimilarNodeGroups = (*BalanceSimilarNodeGroups)(to.StringPtr(string(BalanceSimilarNodeGroupsFalse))) + m.Spec.AutoScalerProfile.BalanceSimilarNodeGroups = (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))) } if m.Spec.AutoScalerProfile.Expander == nil { - m.Spec.AutoScalerProfile.Expander = (*Expander)(to.StringPtr(string(ExpanderRandom))) + m.Spec.AutoScalerProfile.Expander = (*Expander)(pointer.String(string(ExpanderRandom))) } if m.Spec.AutoScalerProfile.MaxEmptyBulkDelete == nil { - m.Spec.AutoScalerProfile.MaxEmptyBulkDelete = to.StringPtr("10") + m.Spec.AutoScalerProfile.MaxEmptyBulkDelete = pointer.String("10") } if m.Spec.AutoScalerProfile.MaxGracefulTerminationSec == nil { - m.Spec.AutoScalerProfile.MaxGracefulTerminationSec = to.StringPtr("600") + m.Spec.AutoScalerProfile.MaxGracefulTerminationSec = pointer.String("600") } if m.Spec.AutoScalerProfile.MaxNodeProvisionTime == nil { - m.Spec.AutoScalerProfile.MaxNodeProvisionTime = to.StringPtr("15m") + m.Spec.AutoScalerProfile.MaxNodeProvisionTime = pointer.String("15m") } if m.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage == nil { - m.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage = to.StringPtr("45") + m.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage = pointer.String("45") } if m.Spec.AutoScalerProfile.NewPodScaleUpDelay == nil { - m.Spec.AutoScalerProfile.NewPodScaleUpDelay = to.StringPtr("0s") + m.Spec.AutoScalerProfile.NewPodScaleUpDelay = pointer.String("0s") } if m.Spec.AutoScalerProfile.OkTotalUnreadyCount == nil { - m.Spec.AutoScalerProfile.OkTotalUnreadyCount = to.StringPtr("3") + m.Spec.AutoScalerProfile.OkTotalUnreadyCount = pointer.String("3") } if m.Spec.AutoScalerProfile.ScanInterval == nil { - m.Spec.AutoScalerProfile.ScanInterval = to.StringPtr("10s") + m.Spec.AutoScalerProfile.ScanInterval = pointer.String("10s") } if m.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd == nil { - m.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd = to.StringPtr("10m") + m.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd = pointer.String("10m") } if m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete == nil { // Default is the same as the ScanInterval so default to that same value if it isn't set m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete = m.Spec.AutoScalerProfile.ScanInterval } if m.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure == nil { - m.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure = to.StringPtr("3m") + m.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure = pointer.String("3m") } if m.Spec.AutoScalerProfile.ScaleDownUnneededTime == nil { - m.Spec.AutoScalerProfile.ScaleDownUnneededTime = to.StringPtr("10m") + m.Spec.AutoScalerProfile.ScaleDownUnneededTime = pointer.String("10m") } if m.Spec.AutoScalerProfile.ScaleDownUnreadyTime == nil { - m.Spec.AutoScalerProfile.ScaleDownUnreadyTime = to.StringPtr("20m") + m.Spec.AutoScalerProfile.ScaleDownUnreadyTime = pointer.String("20m") } if m.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold == nil { - m.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold = to.StringPtr("0.5") + m.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold = pointer.String("0.5") } if m.Spec.AutoScalerProfile.SkipNodesWithLocalStorage == nil { - m.Spec.AutoScalerProfile.SkipNodesWithLocalStorage = (*SkipNodesWithLocalStorage)(to.StringPtr(string(SkipNodesWithLocalStorageFalse))) + m.Spec.AutoScalerProfile.SkipNodesWithLocalStorage = (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageFalse))) } if m.Spec.AutoScalerProfile.SkipNodesWithSystemPods == nil { - m.Spec.AutoScalerProfile.SkipNodesWithSystemPods = (*SkipNodesWithSystemPods)(to.StringPtr(string(SkipNodesWithSystemPodsTrue))) + m.Spec.AutoScalerProfile.SkipNodesWithSystemPods = (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))) } } diff --git a/exp/api/v1beta1/azuremanagedcontrolplane_webhook.go b/exp/api/v1beta1/azuremanagedcontrolplane_webhook.go index 6badeb8e133b..a298631132f5 100644 --- a/exp/api/v1beta1/azuremanagedcontrolplane_webhook.go +++ b/exp/api/v1beta1/azuremanagedcontrolplane_webhook.go @@ -27,11 +27,11 @@ import ( "strings" "time" - "github.com/Azure/go-autorest/autorest/to" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/feature" webhookutils "sigs.k8s.io/cluster-api-provider-azure/util/webhook" @@ -603,8 +603,8 @@ func (m *AzureManagedControlPlane) validateAutoScalerProfile(_ client.Client) er // validateMaxNodeProvisionTime validates update to AutoscalerProfile.MaxNodeProvisionTime. func (m *AzureManagedControlPlane) validateMaxNodeProvisionTime() field.ErrorList { var allErrs field.ErrorList - if to.String(m.Spec.AutoScalerProfile.MaxNodeProvisionTime) != "" { - if !rMaxNodeProvisionTime.MatchString(to.String(m.Spec.AutoScalerProfile.MaxNodeProvisionTime)) { + if pointer.StringDeref(m.Spec.AutoScalerProfile.MaxNodeProvisionTime, "") != "" { + if !rMaxNodeProvisionTime.MatchString(pointer.StringDeref(m.Spec.AutoScalerProfile.MaxNodeProvisionTime, "")) { allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", "MaxNodeProvisionTime"), m.Spec.AutoScalerProfile.MaxNodeProvisionTime, "invalid value")) } } @@ -614,8 +614,8 @@ func (m *AzureManagedControlPlane) validateMaxNodeProvisionTime() field.ErrorLis // validateScanInterval validates update to AutoscalerProfile.ScanInterval. func (m *AzureManagedControlPlane) validateScanInterval() field.ErrorList { var allErrs field.ErrorList - if to.String(m.Spec.AutoScalerProfile.ScanInterval) != "" { - if !rScanInterval.MatchString(to.String(m.Spec.AutoScalerProfile.ScanInterval)) { + if pointer.StringDeref(m.Spec.AutoScalerProfile.ScanInterval, "") != "" { + if !rScanInterval.MatchString(pointer.StringDeref(m.Spec.AutoScalerProfile.ScanInterval, "")) { allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", "ScanInterval"), m.Spec.AutoScalerProfile.ScanInterval, "invalid value")) } } @@ -625,8 +625,8 @@ func (m *AzureManagedControlPlane) validateScanInterval() field.ErrorList { // validateNewPodScaleUpDelay validates update to AutoscalerProfile.NewPodScaleUpDelay. func (m *AzureManagedControlPlane) validateNewPodScaleUpDelay() field.ErrorList { var allErrs field.ErrorList - if to.String(m.Spec.AutoScalerProfile.NewPodScaleUpDelay) != "" { - _, err := time.ParseDuration(to.String(m.Spec.AutoScalerProfile.NewPodScaleUpDelay)) + if pointer.StringDeref(m.Spec.AutoScalerProfile.NewPodScaleUpDelay, "") != "" { + _, err := time.ParseDuration(pointer.StringDeref(m.Spec.AutoScalerProfile.NewPodScaleUpDelay, "")) if err != nil { allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", "NewPodScaleUpDelay"), m.Spec.AutoScalerProfile.NewPodScaleUpDelay, "invalid value")) } @@ -637,9 +637,9 @@ func (m *AzureManagedControlPlane) validateNewPodScaleUpDelay() field.ErrorList // validateScaleDownDelayAfterDelete validates update to AutoscalerProfile.ScaleDownDelayAfterDelete value. func (m *AzureManagedControlPlane) validateScaleDownDelayAfterDelete() field.ErrorList { var allErrs field.ErrorList - if to.String(m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete) != "" { - if !rScaleDownDelayAfterDelete.MatchString(to.String(m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete)) { - allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", "ScaleDownDelayAfterDelete"), to.String(m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete), "invalid value")) + if pointer.StringDeref(m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete, "") != "" { + if !rScaleDownDelayAfterDelete.MatchString(pointer.StringDeref(m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete, "")) { + allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", "ScaleDownDelayAfterDelete"), pointer.StringDeref(m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete, ""), "invalid value")) } } return allErrs @@ -648,9 +648,9 @@ func (m *AzureManagedControlPlane) validateScaleDownDelayAfterDelete() field.Err // validateScaleDownTime validates update to AutoscalerProfile.ScaleDown* values. func (m *AzureManagedControlPlane) validateScaleDownTime(scaleDownValue *string, fieldName string) field.ErrorList { var allErrs field.ErrorList - if to.String(scaleDownValue) != "" { - if !rScaleDownTime.MatchString(to.String(scaleDownValue)) { - allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", fieldName), to.String(scaleDownValue), "invalid value")) + if pointer.StringDeref(scaleDownValue, "") != "" { + if !rScaleDownTime.MatchString(pointer.StringDeref(scaleDownValue, "")) { + allErrs = append(allErrs, field.Invalid(field.NewPath("Spec", "AutoscalerProfile", fieldName), pointer.StringDeref(scaleDownValue, ""), "invalid value")) } } return allErrs diff --git a/exp/api/v1beta1/azuremanagedcontrolplane_webhook_test.go b/exp/api/v1beta1/azuremanagedcontrolplane_webhook_test.go index 0d5ed4210cdc..f166ad8f6972 100644 --- a/exp/api/v1beta1/azuremanagedcontrolplane_webhook_test.go +++ b/exp/api/v1beta1/azuremanagedcontrolplane_webhook_test.go @@ -19,7 +19,6 @@ package v1beta1 import ( "testing" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilfeature "k8s.io/component-base/featuregate/testing" @@ -169,9 +168,9 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.21.2", LoadBalancerProfile: &LoadBalancerProfile{ - ManagedOutboundIPs: to.Int32Ptr(10), - AllocatedOutboundPorts: to.Int32Ptr(1000), - IdleTimeoutInMinutes: to.Int32Ptr(60), + ManagedOutboundIPs: pointer.Int32(10), + AllocatedOutboundPorts: pointer.Int32(1000), + IdleTimeoutInMinutes: pointer.Int32(60), }, }, }, @@ -183,7 +182,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.21.2", LoadBalancerProfile: &LoadBalancerProfile{ - ManagedOutboundIPs: to.Int32Ptr(200), + ManagedOutboundIPs: pointer.Int32(200), }, }, }, @@ -195,7 +194,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.21.2", LoadBalancerProfile: &LoadBalancerProfile{ - AllocatedOutboundPorts: to.Int32Ptr(80000), + AllocatedOutboundPorts: pointer.Int32(80000), }, }, }, @@ -207,7 +206,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.21.2", LoadBalancerProfile: &LoadBalancerProfile{ - IdleTimeoutInMinutes: to.Int32Ptr(600), + IdleTimeoutInMinutes: pointer.Int32(600), }, }, }, @@ -219,7 +218,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.21.2", LoadBalancerProfile: &LoadBalancerProfile{ - ManagedOutboundIPs: to.Int32Ptr(1), + ManagedOutboundIPs: pointer.Int32(1), OutboundIPs: []string{ "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo-bar/providers/Microsoft.Network/publicIPAddresses/my-public-ip", }, @@ -246,23 +245,23 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(to.StringPtr(string(BalanceSimilarNodeGroupsFalse))), - Expander: (*Expander)(to.StringPtr(string(ExpanderRandom))), - MaxEmptyBulkDelete: to.StringPtr("10"), - MaxGracefulTerminationSec: to.StringPtr("600"), - MaxNodeProvisionTime: to.StringPtr("10m"), - MaxTotalUnreadyPercentage: to.StringPtr("45"), - NewPodScaleUpDelay: to.StringPtr("10m"), - OkTotalUnreadyCount: to.StringPtr("3"), - ScanInterval: to.StringPtr("60s"), - ScaleDownDelayAfterAdd: to.StringPtr("10m"), - ScaleDownDelayAfterDelete: to.StringPtr("10s"), - ScaleDownDelayAfterFailure: to.StringPtr("10m"), - ScaleDownUnneededTime: to.StringPtr("10m"), - ScaleDownUnreadyTime: to.StringPtr("10m"), - ScaleDownUtilizationThreshold: to.StringPtr("0.5"), - SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(to.StringPtr(string(SkipNodesWithLocalStorageTrue))), - SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(to.StringPtr(string(SkipNodesWithSystemPodsTrue))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))), + Expander: (*Expander)(pointer.String(string(ExpanderRandom))), + MaxEmptyBulkDelete: pointer.String("10"), + MaxGracefulTerminationSec: pointer.String("600"), + MaxNodeProvisionTime: pointer.String("10m"), + MaxTotalUnreadyPercentage: pointer.String("45"), + NewPodScaleUpDelay: pointer.String("10m"), + OkTotalUnreadyCount: pointer.String("3"), + ScanInterval: pointer.String("60s"), + ScaleDownDelayAfterAdd: pointer.String("10m"), + ScaleDownDelayAfterDelete: pointer.String("10s"), + ScaleDownDelayAfterFailure: pointer.String("10m"), + ScaleDownUnneededTime: pointer.String("10m"), + ScaleDownUnreadyTime: pointer.String("10m"), + ScaleDownUtilizationThreshold: pointer.String("0.5"), + SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageTrue))), + SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))), }, }, }, @@ -274,7 +273,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - Expander: (*Expander)(to.StringPtr(string(ExpanderRandom))), + Expander: (*Expander)(pointer.String(string(ExpanderRandom))), }, }, }, @@ -286,7 +285,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - Expander: (*Expander)(to.StringPtr(string(ExpanderLeastWaste))), + Expander: (*Expander)(pointer.String(string(ExpanderLeastWaste))), }, }, }, @@ -298,7 +297,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - Expander: (*Expander)(to.StringPtr(string(ExpanderMostPods))), + Expander: (*Expander)(pointer.String(string(ExpanderMostPods))), }, }, }, @@ -310,7 +309,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - Expander: (*Expander)(to.StringPtr(string(ExpanderPriority))), + Expander: (*Expander)(pointer.String(string(ExpanderPriority))), }, }, }, @@ -322,7 +321,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(to.StringPtr(string(BalanceSimilarNodeGroupsTrue))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsTrue))), }, }, }, @@ -334,7 +333,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(to.StringPtr(string(BalanceSimilarNodeGroupsFalse))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))), }, }, }, @@ -346,7 +345,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - MaxEmptyBulkDelete: to.StringPtr("invalid"), + MaxEmptyBulkDelete: pointer.String("invalid"), }, }, }, @@ -358,7 +357,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - MaxGracefulTerminationSec: to.StringPtr("invalid"), + MaxGracefulTerminationSec: pointer.String("invalid"), }, }, }, @@ -370,7 +369,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - MaxNodeProvisionTime: to.StringPtr("invalid"), + MaxNodeProvisionTime: pointer.String("invalid"), }, }, }, @@ -382,7 +381,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - MaxTotalUnreadyPercentage: to.StringPtr("invalid"), + MaxTotalUnreadyPercentage: pointer.String("invalid"), }, }, }, @@ -394,7 +393,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - NewPodScaleUpDelay: to.StringPtr("invalid"), + NewPodScaleUpDelay: pointer.String("invalid"), }, }, }, @@ -406,7 +405,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - OkTotalUnreadyCount: to.StringPtr("invalid"), + OkTotalUnreadyCount: pointer.String("invalid"), }, }, }, @@ -418,7 +417,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScanInterval: to.StringPtr("invalid"), + ScanInterval: pointer.String("invalid"), }, }, }, @@ -430,7 +429,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScaleDownDelayAfterAdd: to.StringPtr("invalid"), + ScaleDownDelayAfterAdd: pointer.String("invalid"), }, }, }, @@ -442,7 +441,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScaleDownDelayAfterDelete: to.StringPtr("invalid"), + ScaleDownDelayAfterDelete: pointer.String("invalid"), }, }, }, @@ -454,7 +453,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScaleDownDelayAfterFailure: to.StringPtr("invalid"), + ScaleDownDelayAfterFailure: pointer.String("invalid"), }, }, }, @@ -466,7 +465,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScaleDownUnneededTime: to.StringPtr("invalid"), + ScaleDownUnneededTime: pointer.String("invalid"), }, }, }, @@ -478,7 +477,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScaleDownUnreadyTime: to.StringPtr("invalid"), + ScaleDownUnreadyTime: pointer.String("invalid"), }, }, }, @@ -490,7 +489,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - ScaleDownUtilizationThreshold: to.StringPtr("invalid"), + ScaleDownUtilizationThreshold: pointer.String("invalid"), }, }, }, @@ -502,7 +501,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(to.StringPtr(string(SkipNodesWithLocalStorageTrue))), + SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageTrue))), }, }, }, @@ -514,7 +513,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(to.StringPtr(string(SkipNodesWithLocalStorageFalse))), + SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageFalse))), }, }, }, @@ -526,7 +525,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(to.StringPtr(string(SkipNodesWithSystemPodsTrue))), + SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))), }, }, }, @@ -538,7 +537,7 @@ func TestValidatingWebhook(t *testing.T) { Spec: AzureManagedControlPlaneSpec{ Version: "v1.24.1", AutoScalerProfile: &AutoScalerProfile{ - SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(to.StringPtr(string(SkipNodesWithSystemPodsFalse))), + SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsFalse))), }, }, }, @@ -607,7 +606,7 @@ func TestAzureManagedControlPlane_ValidateCreate(t *testing.T) { }, Spec: AzureManagedControlPlaneSpec{ SSHPublicKey: generateSSHPublicKey(true), - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.23.5", }, }, @@ -622,7 +621,7 @@ func TestAzureManagedControlPlane_ValidateCreate(t *testing.T) { }, Spec: AzureManagedControlPlaneSpec{ SSHPublicKey: generateSSHPublicKey(true), - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.23.5", }, }, @@ -636,7 +635,7 @@ func TestAzureManagedControlPlane_ValidateCreate(t *testing.T) { ControlPlaneEndpoint: clusterv1.APIEndpoint{ Host: "my-host", }, - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", SSHPublicKey: generateSSHPublicKey(true), AADProfile: &AADProfile{ @@ -656,7 +655,7 @@ func TestAzureManagedControlPlane_ValidateCreate(t *testing.T) { ControlPlaneEndpoint: clusterv1.APIEndpoint{ Port: 444, }, - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", SSHPublicKey: generateSSHPublicKey(true), AADProfile: &AADProfile{ @@ -751,14 +750,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane SubscriptionID is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), SubscriptionID: "212ec1q8", Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), SubscriptionID: "212ec1q9", Version: "v1.18.0", }, @@ -769,14 +768,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane ResourceGroupName is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), ResourceGroupName: "hello-1", Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), ResourceGroupName: "hello-2", Version: "v1.18.0", }, @@ -787,14 +786,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane NodeResourceGroupName is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), NodeResourceGroupName: "hello-1", Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), NodeResourceGroupName: "hello-2", Version: "v1.18.0", }, @@ -805,14 +804,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane Location is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Location: "westeurope", Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Location: "eastus", Version: "v1.18.0", }, @@ -823,14 +822,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane SSHPublicKey is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), SSHPublicKey: generateSSHPublicKey(true), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), SSHPublicKey: generateSSHPublicKey(true), Version: "v1.18.0", }, @@ -841,13 +840,13 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane DNSServiceIP is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.1"), + DNSServiceIP: pointer.String("192.168.0.1"), Version: "v1.18.0", }, }, @@ -857,7 +856,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane DNSServiceIP is immutable, unsetting is not allowed", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -872,15 +871,15 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane NetworkPlugin is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - NetworkPlugin: to.StringPtr("azure"), + DNSServiceIP: pointer.String("192.168.0.0"), + NetworkPlugin: pointer.String("azure"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - NetworkPlugin: to.StringPtr("kubenet"), + DNSServiceIP: pointer.String("192.168.0.0"), + NetworkPlugin: pointer.String("kubenet"), Version: "v1.18.0", }, }, @@ -890,14 +889,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane NetworkPlugin is immutable, unsetting is not allowed", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - NetworkPlugin: to.StringPtr("azure"), + DNSServiceIP: pointer.String("192.168.0.0"), + NetworkPlugin: pointer.String("azure"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -907,15 +906,15 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane NetworkPolicy is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - NetworkPolicy: to.StringPtr("azure"), + DNSServiceIP: pointer.String("192.168.0.0"), + NetworkPolicy: pointer.String("azure"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - NetworkPolicy: to.StringPtr("calico"), + DNSServiceIP: pointer.String("192.168.0.0"), + NetworkPolicy: pointer.String("calico"), Version: "v1.18.0", }, }, @@ -925,14 +924,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane NetworkPolicy is immutable, unsetting is not allowed", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - NetworkPolicy: to.StringPtr("azure"), + DNSServiceIP: pointer.String("192.168.0.0"), + NetworkPolicy: pointer.String("azure"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -942,15 +941,15 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane LoadBalancerSKU is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - LoadBalancerSKU: to.StringPtr("Standard"), + DNSServiceIP: pointer.String("192.168.0.0"), + LoadBalancerSKU: pointer.String("Standard"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - LoadBalancerSKU: to.StringPtr("Basic"), + DNSServiceIP: pointer.String("192.168.0.0"), + LoadBalancerSKU: pointer.String("Basic"), Version: "v1.18.0", }, }, @@ -960,14 +959,14 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane LoadBalancerSKU is immutable, unsetting is not allowed", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), - LoadBalancerSKU: to.StringPtr("Standard"), + DNSServiceIP: pointer.String("192.168.0.0"), + LoadBalancerSKU: pointer.String("Standard"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -1088,16 +1087,16 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane EnablePrivateCluster is immutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", APIServerAccessProfile: &APIServerAccessProfile{ - EnablePrivateCluster: to.BoolPtr(true), + EnablePrivateCluster: pointer.Bool(true), }, }, }, @@ -1107,13 +1106,13 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { name: "AzureManagedControlPlane AuthorizedIPRanges is mutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, amcp: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", APIServerAccessProfile: &APIServerAccessProfile{ AuthorizedIPRanges: []string{"192.168.0.1/32"}, @@ -1129,7 +1128,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -1138,7 +1137,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "new-test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", APIServerAccessProfile: &APIServerAccessProfile{ AuthorizedIPRanges: []string{"192.168.0.1/32"}, @@ -1154,7 +1153,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", VirtualNetwork: ManagedControlPlaneVirtualNetwork{ Name: "test-network", @@ -1172,7 +1171,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -1185,7 +1184,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", }, }, @@ -1194,7 +1193,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", VirtualNetwork: ManagedControlPlaneVirtualNetwork{ Name: "test-network", @@ -1216,7 +1215,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", VirtualNetwork: ManagedControlPlaneVirtualNetwork{ Name: "test-network", @@ -1234,7 +1233,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { Name: "test-cluster", }, Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", VirtualNetwork: ManagedControlPlaneVirtualNetwork{ Name: "test-network", @@ -1341,7 +1340,7 @@ func createAzureManagedControlPlane(serviceIP, version, sshKey string) *AzureMan return &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ SSHPublicKey: sshKey, - DNSServiceIP: to.StringPtr(serviceIP), + DNSServiceIP: pointer.String(serviceIP), Version: version, }, } @@ -1350,7 +1349,7 @@ func createAzureManagedControlPlane(serviceIP, version, sshKey string) *AzureMan func getKnownValidAzureManagedControlPlane() *AzureManagedControlPlane { return &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ - DNSServiceIP: to.StringPtr("192.168.0.0"), + DNSServiceIP: pointer.String("192.168.0.0"), Version: "v1.18.0", SSHPublicKey: generateSSHPublicKey(true), AADProfile: &AADProfile{ diff --git a/exp/api/v1beta1/azuremanagedmachinepool_webhook.go b/exp/api/v1beta1/azuremanagedmachinepool_webhook.go index 10f6a4b2dc88..e49879093f46 100644 --- a/exp/api/v1beta1/azuremanagedmachinepool_webhook.go +++ b/exp/api/v1beta1/azuremanagedmachinepool_webhook.go @@ -23,12 +23,12 @@ import ( "regexp" "strings" - "github.com/Azure/go-autorest/autorest/to" "github.com/pkg/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/feature" azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" @@ -54,7 +54,7 @@ func (m *AzureManagedMachinePool) Default(client client.Client) { } if m.Spec.OSType == nil { - m.Spec.OSType = to.StringPtr(DefaultOSType) + m.Spec.OSType = pointer.String(DefaultOSType) } } @@ -273,7 +273,7 @@ func (m *AzureManagedMachinePool) validateLastSystemNodePool(cli client.Client) func (m *AzureManagedMachinePool) validateMaxPods() error { if m.Spec.MaxPods != nil { - if to.Int32(m.Spec.MaxPods) < 10 || to.Int32(m.Spec.MaxPods) > 250 { + if pointer.Int32Deref(m.Spec.MaxPods, 0) < 10 || pointer.Int32Deref(m.Spec.MaxPods, 0) > 250 { return field.Invalid( field.NewPath("Spec", "MaxPods"), m.Spec.MaxPods, @@ -355,7 +355,7 @@ func (m *AzureManagedMachinePool) validateKubeletConfig() error { } if m.Spec.KubeletConfig != nil { if m.Spec.KubeletConfig.CPUCfsQuotaPeriod != nil { - if !strings.HasSuffix(to.String(m.Spec.KubeletConfig.CPUCfsQuotaPeriod), "ms") { + if !strings.HasSuffix(pointer.StringDeref(m.Spec.KubeletConfig.CPUCfsQuotaPeriod, ""), "ms") { return field.Invalid( field.NewPath("Spec", "KubeletConfig", "CPUCfsQuotaPeriod"), m.Spec.KubeletConfig.CPUCfsQuotaPeriod, @@ -363,12 +363,12 @@ func (m *AzureManagedMachinePool) validateKubeletConfig() error { } } if m.Spec.KubeletConfig.ImageGcHighThreshold != nil && m.Spec.KubeletConfig.ImageGcLowThreshold != nil { - if to.Int32(m.Spec.KubeletConfig.ImageGcLowThreshold) > to.Int32(m.Spec.KubeletConfig.ImageGcHighThreshold) { + if pointer.Int32Deref(m.Spec.KubeletConfig.ImageGcLowThreshold, 0) > pointer.Int32Deref(m.Spec.KubeletConfig.ImageGcHighThreshold, 0) { return field.Invalid( field.NewPath("Spec", "KubeletConfig", "ImageGcLowThreshold"), m.Spec.KubeletConfig.ImageGcLowThreshold, fmt.Sprintf("must not be greater than ImageGcHighThreshold, ImageGcLowThreshold=%d, ImageGcHighThreshold=%d", - to.Int32(m.Spec.KubeletConfig.ImageGcLowThreshold), to.Int32(m.Spec.KubeletConfig.ImageGcHighThreshold))) + pointer.Int32Deref(m.Spec.KubeletConfig.ImageGcLowThreshold, 0), pointer.Int32Deref(m.Spec.KubeletConfig.ImageGcHighThreshold, 0))) } } for _, val := range m.Spec.KubeletConfig.AllowedUnsafeSysctls { diff --git a/exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go b/exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go index d3f9e454b487..c5973bddedd3 100644 --- a/exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go +++ b/exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go @@ -20,10 +20,10 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilfeature "k8s.io/component-base/featuregate/testing" + "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api-provider-azure/azure" "sigs.k8s.io/cluster-api-provider-azure/feature" "sigs.k8s.io/controller-runtime/pkg/client" @@ -40,7 +40,7 @@ func TestAzureManagedMachinePoolDefaultingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, } var client client.Client @@ -86,12 +86,12 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { name: "Cannot change Name of the agentpool", new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - Name: to.StringPtr("pool-new"), + Name: pointer.String("pool-new"), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - Name: to.StringPtr("pool-old"), + Name: pointer.String("pool-old"), }, }, wantErr: true, @@ -102,14 +102,14 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V4", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, wantErr: true, @@ -118,18 +118,18 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { name: "Cannot change OSType of the agentpool", new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - OSType: to.StringPtr("Linux"), + OSType: pointer.String("Linux"), Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - OSType: to.StringPtr("Windows"), + OSType: pointer.String("Windows"), Mode: "System", SKU: "StandardD2S_V4", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, wantErr: true, @@ -140,14 +140,14 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(1024), + OSDiskSizeGB: pointer.Int32(1024), }, }, wantErr: true, @@ -158,7 +158,7 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), AvailabilityZones: []string{"1", "2", "3"}, }, }, @@ -166,7 +166,7 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, wantErr: true, @@ -177,14 +177,14 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), AvailabilityZones: []string{"1", "2", "3"}, }, }, @@ -196,7 +196,7 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), AvailabilityZones: []string{"1", "2"}, }, }, @@ -204,7 +204,7 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), AvailabilityZones: []string{"1", "2", "3"}, }, }, @@ -216,7 +216,7 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), AvailabilityZones: []string{"1", "3", "2"}, }, }, @@ -224,7 +224,7 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), AvailabilityZones: []string{"1", "2", "3"}, }, }, @@ -236,16 +236,16 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(24), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(24), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(25), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(25), }, }, wantErr: true, @@ -256,16 +256,16 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(30), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(30), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(30), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(30), }, }, wantErr: false, @@ -276,18 +276,18 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(24), - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(24), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeEphemeral)), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(24), - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(24), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeManaged)), }, }, wantErr: true, @@ -379,18 +379,18 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(30), - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(30), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeManaged)), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", SKU: "StandardD2S_V3", - OSDiskSizeGB: to.Int32Ptr(512), - MaxPods: to.Int32Ptr(30), - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)), + OSDiskSizeGB: pointer.Int32(512), + MaxPods: pointer.Int32(30), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeManaged)), }, }, wantErr: false, @@ -399,12 +399,12 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { name: "Unexpected error, value EnableUltraSSD is unchanged", new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableUltraSSD: to.BoolPtr(true), + EnableUltraSSD: pointer.Bool(true), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableUltraSSD: to.BoolPtr(true), + EnableUltraSSD: pointer.Bool(true), }, }, wantErr: false, @@ -413,12 +413,12 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { name: "EnableUltraSSD feature is immutable and currently enabled on this agentpool", new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableUltraSSD: to.BoolPtr(false), + EnableUltraSSD: pointer.Bool(false), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableUltraSSD: to.BoolPtr(true), + EnableUltraSSD: pointer.Bool(true), }, }, wantErr: true, @@ -427,12 +427,12 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { name: "Unexpected error, value EnableNodePublicIP is unchanged", new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), + EnableNodePublicIP: pointer.Bool(true), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), + EnableNodePublicIP: pointer.Bool(true), }, }, wantErr: false, @@ -441,12 +441,12 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { name: "EnableNodePublicIP feature is immutable and currently enabled on this agentpool", new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(false), + EnableNodePublicIP: pointer.Bool(false), }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), + EnableNodePublicIP: pointer.Bool(true), }, }, wantErr: true, @@ -501,14 +501,14 @@ func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) { new: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ KubeletConfig: &KubeletConfig{ - CPUCfsQuota: to.BoolPtr(true), + CPUCfsQuota: pointer.Bool(true), }, }, }, old: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ KubeletConfig: &KubeletConfig{ - CPUCfsQuota: to.BoolPtr(false), + CPUCfsQuota: pointer.Bool(false), }, }, }, @@ -549,8 +549,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "another valid permutation", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - MaxPods: to.Int32Ptr(249), - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)), + MaxPods: pointer.Int32(249), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeManaged)), }, }, wantErr: false, @@ -566,7 +566,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "too many MaxPods", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - MaxPods: to.Int32Ptr(251), + MaxPods: pointer.Int32(251), }, }, wantErr: true, @@ -576,7 +576,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "too few MaxPods", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - MaxPods: to.Int32Ptr(9), + MaxPods: pointer.Int32(9), }, }, wantErr: true, @@ -587,7 +587,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "System", - OSType: to.StringPtr(azure.WindowsOS), + OSType: pointer.String(azure.WindowsOS), }, }, wantErr: true, @@ -598,7 +598,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "User", - OSType: to.StringPtr(azure.WindowsOS), + OSType: pointer.String(azure.WindowsOS), }, }, wantErr: false, @@ -611,7 +611,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { }, Spec: AzureManagedMachinePoolSpec{ Mode: "User", - OSType: to.StringPtr(azure.WindowsOS), + OSType: pointer.String(azure.WindowsOS), }, }, wantErr: false, @@ -624,7 +624,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { }, Spec: AzureManagedMachinePoolSpec{ Mode: "User", - OSType: to.StringPtr(azure.WindowsOS), + OSType: pointer.String(azure.WindowsOS), }, }, wantErr: true, @@ -635,7 +635,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "User", - OSType: to.StringPtr(azure.LinuxOS), + OSType: pointer.String(azure.LinuxOS), NodeLabels: map[string]string{ "foo": "bar", }, @@ -648,7 +648,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ Mode: "User", - OSType: to.StringPtr(azure.LinuxOS), + OSType: pointer.String(azure.LinuxOS), NodeLabels: map[string]string{ "kubernetes.azure.com/scalesetpriority": "spot", }, @@ -661,8 +661,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "pool with invalid public ip prefix", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), - NodePublicIPPrefixID: to.StringPtr("not a valid resource ID"), + EnableNodePublicIP: pointer.Bool(true), + NodePublicIPPrefixID: pointer.String("not a valid resource ID"), }, }, wantErr: true, @@ -673,7 +673,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ EnableNodePublicIP: nil, - NodePublicIPPrefixID: to.StringPtr("subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), + NodePublicIPPrefixID: pointer.String("subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), }, }, wantErr: true, @@ -683,8 +683,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "pool with public ip prefix cannot disable node public IP", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(false), - NodePublicIPPrefixID: to.StringPtr("subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), + EnableNodePublicIP: pointer.Bool(false), + NodePublicIPPrefixID: pointer.String("subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), }, }, wantErr: true, @@ -694,8 +694,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "pool with public ip prefix with node public IP enabled ok", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), - NodePublicIPPrefixID: to.StringPtr("subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), + EnableNodePublicIP: pointer.Bool(true), + NodePublicIPPrefixID: pointer.String("subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), }, }, wantErr: false, @@ -704,8 +704,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "pool with public ip prefix with leading slash with node public IP enabled ok", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), - NodePublicIPPrefixID: to.StringPtr("/subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), + EnableNodePublicIP: pointer.Bool(true), + NodePublicIPPrefixID: pointer.String("/subscriptions/11111111-2222-aaaa-bbbb-cccccccccccc/resourceGroups/public-ip-test/providers/Microsoft.Network/publicipprefixes/public-ip-prefix"), }, }, wantErr: false, @@ -723,7 +723,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "pool without public ip prefix with node public IP enabled ok", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(true), + EnableNodePublicIP: pointer.Bool(true), }, }, wantErr: false, @@ -732,7 +732,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { name: "pool without public ip prefix with node public IP disabled ok", ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - EnableNodePublicIP: to.BoolPtr(false), + EnableNodePublicIP: pointer.Bool(false), }, }, wantErr: false, @@ -742,7 +742,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ KubeletConfig: &KubeletConfig{ - CPUCfsQuotaPeriod: to.StringPtr("100"), + CPUCfsQuotaPeriod: pointer.String("100"), }, }, }, @@ -754,7 +754,7 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ KubeletConfig: &KubeletConfig{ - CPUCfsQuotaPeriod: to.StringPtr("100ms"), + CPUCfsQuotaPeriod: pointer.String("100ms"), }, }, }, @@ -765,8 +765,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ KubeletConfig: &KubeletConfig{ - ImageGcLowThreshold: to.Int32Ptr(100), - ImageGcHighThreshold: to.Int32Ptr(99), + ImageGcLowThreshold: pointer.Int32(100), + ImageGcHighThreshold: pointer.Int32(99), }, }, }, @@ -778,8 +778,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { ammp: &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ KubeletConfig: &KubeletConfig{ - ImageGcLowThreshold: to.Int32Ptr(99), - ImageGcHighThreshold: to.Int32Ptr(100), + ImageGcLowThreshold: pointer.Int32(99), + ImageGcHighThreshold: pointer.Int32(100), }, }, }, @@ -885,8 +885,8 @@ func TestAzureManagedMachinePool_ValidateCreateFailure(t *testing.T) { func getKnownValidAzureManagedMachinePool() *AzureManagedMachinePool { return &AzureManagedMachinePool{ Spec: AzureManagedMachinePoolSpec{ - MaxPods: to.Int32Ptr(30), - OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeEphemeral)), + MaxPods: pointer.Int32(30), + OsDiskType: pointer.String(string(containerservice.OSDiskTypeEphemeral)), }, } } diff --git a/exp/controllers/azuremachinepool_controller_unit_test.go b/exp/controllers/azuremachinepool_controller_unit_test.go index 5eff93954092..945ddce3d7c5 100644 --- a/exp/controllers/azuremachinepool_controller_unit_test.go +++ b/exp/controllers/azuremachinepool_controller_unit_test.go @@ -19,12 +19,12 @@ package controllers import ( "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure" "sigs.k8s.io/cluster-api-provider-azure/azure/scope" @@ -94,7 +94,7 @@ func newMachinePool(clusterName, poolName string) *expv1.MachinePool { Namespace: "default", }, Spec: expv1.MachinePoolSpec{ - Replicas: to.Int32Ptr(2), + Replicas: pointer.Int32(2), }, } } diff --git a/exp/controllers/helpers_test.go b/exp/controllers/helpers_test.go index fa54c9d02864..75c96e979514 100644 --- a/exp/controllers/helpers_test.go +++ b/exp/controllers/helpers_test.go @@ -20,7 +20,6 @@ import ( "context" "testing" - "github.com/Azure/go-autorest/autorest/to" "github.com/go-logr/logr" "github.com/golang/mock/gomock" . "github.com/onsi/gomega" @@ -28,6 +27,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock" @@ -747,7 +747,7 @@ func newAzureManagedMachinePool(clusterName, poolName, mode string) *infrav1exp. Spec: infrav1exp.AzureManagedMachinePoolSpec{ Mode: mode, SKU: "Standard_B2s", - OSDiskSizeGB: to.Int32Ptr(512), + OSDiskSizeGB: pointer.Int32(512), KubeletConfig: &infrav1exp.KubeletConfig{ CPUManagerPolicy: &cpuManagerPolicyStatic, TopologyManagerPolicy: &topologyManagerPolicy, diff --git a/go.mod b/go.mod index ff67bee10b55..23d64bc9f626 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 github.com/Azure/go-autorest/autorest v0.11.28 github.com/Azure/go-autorest/autorest/azure/auth v0.5.10 - github.com/Azure/go-autorest/autorest/to v0.4.0 github.com/Azure/go-autorest/tracing v0.6.0 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/blang/semver v3.5.1+incompatible @@ -61,6 +60,7 @@ require ( github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/autorest/mocks v0.4.2 // indirect + github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect diff --git a/internal/test/env/env.go b/internal/test/env/env.go index 03ba142649a1..3986e70b3313 100644 --- a/internal/test/env/env.go +++ b/internal/test/env/env.go @@ -27,7 +27,6 @@ import ( goruntime "runtime" "strings" - "github.com/Azure/go-autorest/autorest/to" "github.com/go-logr/logr" "github.com/onsi/ginkgo/v2" "k8s.io/apimachinery/pkg/runtime" @@ -35,6 +34,7 @@ import ( clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/klog/v2" + "k8s.io/utils/pointer" infrav1alpha3 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3" infrav1alpha4 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha4" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" @@ -48,7 +48,7 @@ import ( ) var ( - logger = record.NewLogger(record.WithThreshold(to.IntPtr(1)), record.WithWriter(ginkgo.GinkgoWriter)) + logger = record.NewLogger(record.WithThreshold(pointer.Int(1)), record.WithWriter(ginkgo.GinkgoWriter)) scheme = runtime.NewScheme() env *envtest.Environment clusterAPIVersionRegex = regexp.MustCompile(`^(\W)sigs.k8s.io/cluster-api v(.+)`) diff --git a/test/e2e/aks_autoscaler.go b/test/e2e/aks_autoscaler.go index 78b79c65421d..647e3f3ae9f9 100644 --- a/test/e2e/aks_autoscaler.go +++ b/test/e2e/aks_autoscaler.go @@ -24,10 +24,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -84,8 +84,8 @@ func AKSAutoscaleSpec(ctx context.Context, inputGetter func() AKSAutoscaleSpecIn } else { enabling = "Enabling" ammp.Spec.Scaling = &infrav1exp.ManagedMachinePoolScaling{ - MinSize: to.Int32Ptr(1), - MaxSize: to.Int32Ptr(2), + MinSize: pointer.Int32(1), + MaxSize: pointer.Int32(2), } } By(enabling + " autoscaling") @@ -112,7 +112,7 @@ func validateAKSAutoscaleDisabled(agentPoolGetter func() (containerservice.Agent Eventually(func(g Gomega) { agentpool, err := agentPoolGetter() g.Expect(err).NotTo(HaveOccurred()) - g.Expect(to.Bool(agentpool.EnableAutoScaling)).To(BeFalse()) + g.Expect(pointer.BoolDeref(agentpool.EnableAutoScaling, false)).To(BeFalse()) }, inputGetter().WaitIntervals...).Should(Succeed()) } @@ -121,6 +121,6 @@ func validateAKSAutoscaleEnabled(agentPoolGetter func() (containerservice.AgentP Eventually(func(g Gomega) { agentpool, err := agentPoolGetter() g.Expect(err).NotTo(HaveOccurred()) - g.Expect(to.Bool(agentpool.EnableAutoScaling)).To(BeTrue()) + g.Expect(pointer.BoolDeref(agentpool.EnableAutoScaling, false)).To(BeTrue()) }, inputGetter().WaitIntervals...).Should(Succeed()) } diff --git a/test/e2e/aks_azure_cluster_autoscaler.go b/test/e2e/aks_azure_cluster_autoscaler.go index b5292c0d003a..43ac3bf598e2 100644 --- a/test/e2e/aks_azure_cluster_autoscaler.go +++ b/test/e2e/aks_azure_cluster_autoscaler.go @@ -24,10 +24,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) @@ -87,7 +87,7 @@ func AKSAzureClusterAutoscalerSettingsSpec(ctx context.Context, inputGetter func // Now set to the new value amcp.Spec.AutoScalerProfile = &infrav1exp.AutoScalerProfile{ - Expander: (*infrav1exp.Expander)(to.StringPtr(string(newExpanderValue))), + Expander: (*infrav1exp.Expander)(pointer.String(string(newExpanderValue))), } Expect(mgmtClient.Update(ctx, amcp)).To(Succeed()) By("Verifying the cluster-autoscaler settings have changed") diff --git a/test/e2e/aks_machinepools.go b/test/e2e/aks_machinepools.go index e6137d7660e1..d454a2c52d3f 100644 --- a/test/e2e/aks_machinepools.go +++ b/test/e2e/aks_machinepools.go @@ -23,10 +23,10 @@ import ( "context" "sync" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" @@ -46,7 +46,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp originalReplicas := map[types.NamespacedName]int32{} for _, mp := range input.MachinePools { - originalReplicas[client.ObjectKeyFromObject(mp)] = to.Int32(mp.Spec.Replicas) + originalReplicas[client.ObjectKeyFromObject(mp)] = pointer.Int32Deref(mp.Spec.Replicas, 0) } By("Scaling the machine pools out") @@ -58,7 +58,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{ ClusterProxy: bootstrapClusterProxy, Cluster: input.Cluster, - Replicas: to.Int32(mp.Spec.Replicas) + 1, + Replicas: pointer.Int32Deref(mp.Spec.Replicas, 0) + 1, MachinePools: []*expv1.MachinePool{mp}, WaitForMachinePoolToScale: input.WaitIntervals, }) @@ -75,7 +75,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{ ClusterProxy: bootstrapClusterProxy, Cluster: input.Cluster, - Replicas: to.Int32(mp.Spec.Replicas) - 1, + Replicas: pointer.Int32Deref(mp.Spec.Replicas, 0) - 1, MachinePools: []*expv1.MachinePool{mp}, WaitForMachinePoolToScale: input.WaitIntervals, }) diff --git a/test/e2e/aks_public_ip_prefix.go b/test/e2e/aks_public_ip_prefix.go index abe22dea6425..e01537e31afa 100644 --- a/test/e2e/aks_public_ip_prefix.go +++ b/test/e2e/aks_public_ip_prefix.go @@ -24,12 +24,12 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" @@ -68,12 +68,12 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr By("Creating public IP prefix with 2 addresses") publicIPPrefixFuture, err := publicIPPrefixClient.CreateOrUpdate(ctx, resourceGroupName, input.Cluster.Name, network.PublicIPPrefix{ - Location: to.StringPtr(infraControlPlane.Spec.Location), + Location: pointer.String(infraControlPlane.Spec.Location), Sku: &network.PublicIPPrefixSku{ Name: network.PublicIPPrefixSkuNameStandard, }, PublicIPPrefixPropertiesFormat: &network.PublicIPPrefixPropertiesFormat{ - PrefixLength: to.Int32Ptr(31), // In bits. This provides 2 addresses. + PrefixLength: pointer.Int32(31), // In bits. This provides 2 addresses. }, }) Expect(err).NotTo(HaveOccurred()) @@ -92,8 +92,8 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr Spec: infrav1exp.AzureManagedMachinePoolSpec{ Mode: "User", SKU: "Standard_D2s_v3", - EnableNodePublicIP: to.BoolPtr(true), - NodePublicIPPrefixID: to.StringPtr("/subscriptions/" + subscriptionID + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/publicipprefixes/" + *publicIPPrefix.Name), + EnableNodePublicIP: pointer.Bool(true), + NodePublicIPPrefixID: pointer.String("/subscriptions/" + subscriptionID + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/publicipprefixes/" + *publicIPPrefix.Name), }, } err = mgmtClient.Create(ctx, infraMachinePool) @@ -106,11 +106,11 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr }, Spec: expv1.MachinePoolSpec{ ClusterName: input.Cluster.Name, - Replicas: to.Int32Ptr(3), + Replicas: pointer.Int32(3), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ - DataSecretName: to.StringPtr(""), + DataSecretName: pointer.String(""), }, ClusterName: input.Cluster.Name, InfrastructureRef: corev1.ObjectReference{ @@ -118,7 +118,7 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr Kind: "AzureManagedMachinePool", Name: infraMachinePool.Name, }, - Version: to.StringPtr(input.KubernetesVersion), + Version: pointer.String(input.KubernetesVersion), }, }, }, @@ -157,7 +157,7 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr By("Scaling the MachinePool to 2 nodes") err = mgmtClient.Get(ctx, client.ObjectKeyFromObject(machinePool), machinePool) Expect(err).NotTo(HaveOccurred()) - machinePool.Spec.Replicas = to.Int32Ptr(2) + machinePool.Spec.Replicas = pointer.Int32(2) err = mgmtClient.Update(ctx, machinePool) Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/azure_clusterproxy.go b/test/e2e/azure_clusterproxy.go index 430070d62e3f..0ec129c26238 100644 --- a/test/e2e/azure_clusterproxy.go +++ b/test/e2e/azure_clusterproxy.go @@ -35,7 +35,6 @@ import ( aadpodv1 "github.com/Azure/aad-pod-identity/pkg/apis/aadpodidentity/v1" "github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -43,6 +42,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/utils/pointer" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1" azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" @@ -267,7 +267,7 @@ func (acp *AzureClusterProxy) collectActivityLogs(ctx context.Context, namespace return } event := itr.Value() - if to.String(event.Category.Value) != "Policy" { + if pointer.StringDeref(event.Category.Value, "") != "Policy" { b, err := json.MarshalIndent(myEventData(event), "", " ") if err != nil { Logf("Got error converting activity logs data to json: %v", err) diff --git a/test/e2e/azure_privatecluster.go b/test/e2e/azure_privatecluster.go index 988051041b68..0910bcb98e5d 100644 --- a/test/e2e/azure_privatecluster.go +++ b/test/e2e/azure_privatecluster.go @@ -33,7 +33,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-05-01/resources" azureautorest "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/pkg/errors" @@ -389,7 +388,7 @@ func SetupExistingVNet(ctx context.Context, vnetCidr string, cpSubnetCidrs, node resClient := resources.NewClient(subscriptionID) resClient.Authorizer = authorizer Eventually(func() ([]resources.GenericResourceExpanded, error) { - page, err := resClient.ListByResourceGroup(ctx, groupName, "", "provisioningState", to.Int32Ptr(10)) + page, err := resClient.ListByResourceGroup(ctx, groupName, "", "provisioningState", pointer.Int32(10)) if err != nil { return nil, err } diff --git a/test/e2e/kubernetes/pvc/pvc.go b/test/e2e/kubernetes/pvc/pvc.go index 8c8c710f12ca..af632165d34b 100644 --- a/test/e2e/kubernetes/pvc/pvc.go +++ b/test/e2e/kubernetes/pvc/pvc.go @@ -24,12 +24,12 @@ import ( "log" "time" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "k8s.io/utils/pointer" ) const ( @@ -105,7 +105,7 @@ func (b *Builder) WithAnnotations(annotations map[string]string) *Builder { } func (b *Builder) WithStorageClass(scName string) *Builder { - b.pvc.Spec.StorageClassName = to.StringPtr(scName) + b.pvc.Spec.StorageClassName = pointer.String(scName) return b } diff --git a/util/webhook/validator_test.go b/util/webhook/validator_test.go index 1603d06b43ba..7657fbbbd27b 100644 --- a/util/webhook/validator_test.go +++ b/util/webhook/validator_test.go @@ -19,9 +19,9 @@ package webhook import ( "testing" - "github.com/Azure/go-autorest/autorest/to" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/pointer" ) func TestValidateImmutableBoolPtr(t *testing.T) { @@ -40,25 +40,25 @@ func TestValidateImmutableBoolPtr(t *testing.T) { }, { name: "no change", - input1: to.BoolPtr(true), - input2: to.BoolPtr(true), + input1: pointer.Bool(true), + input2: pointer.Bool(true), }, { name: "can't unset", - input1: to.BoolPtr(true), + input1: pointer.Bool(true), input2: nil, expectedOutput: field.Invalid(testPath, nil, unsetMessage), }, { name: "can't set from empty", input1: nil, - input2: to.BoolPtr(true), + input2: pointer.Bool(true), expectedOutput: field.Invalid(testPath, nil, setMessage), }, { name: "can't change", - input1: to.BoolPtr(true), - input2: to.BoolPtr(false), + input1: pointer.Bool(true), + input2: pointer.Bool(false), expectedOutput: field.Invalid(testPath, nil, immutableMessage), }, } @@ -148,25 +148,25 @@ func TestValidateImmutableStringPtr(t *testing.T) { }, { name: "no change", - input1: to.StringPtr("foo"), - input2: to.StringPtr("foo"), + input1: pointer.String("foo"), + input2: pointer.String("foo"), }, { name: "can't unset", - input1: to.StringPtr("foo"), + input1: pointer.String("foo"), input2: nil, expectedOutput: field.Invalid(testPath, nil, unsetMessage), }, { name: "can't set from empty", input1: nil, - input2: to.StringPtr("foo"), + input2: pointer.String("foo"), expectedOutput: field.Invalid(testPath, nil, setMessage), }, { name: "can't change", - input1: to.StringPtr("foo"), - input2: to.StringPtr("bar"), + input1: pointer.String("foo"), + input2: pointer.String("bar"), expectedOutput: field.Invalid(testPath, nil, immutableMessage), }, }