Skip to content

Commit 5c28bc0

Browse files
committed
Replace some usage of Azure/go-autorest
1 parent 5a4257d commit 5c28bc0

File tree

15 files changed

+51
-46
lines changed

15 files changed

+51
-46
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ linters-settings:
106106
# Azure
107107
- pkg: github.com/Azure/go-autorest/autorest/azure
108108
alias: azureautorest
109+
# Deprecated
110+
- pkg: github.com/Azure/go-autorest/autorest/to
111+
alias: deprecated-use-k8s.io-utils-pointer
109112
gocritic:
110113
enabled-tags:
111114
- "experimental"

azure/converters/extendedlocation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package converters
1919
import (
2020
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
2121
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"
22-
"github.com/Azure/go-autorest/autorest/to"
22+
"k8s.io/utils/pointer"
2323
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2424
)
2525

@@ -29,7 +29,7 @@ func ExtendedLocationToNetworkSDK(src *infrav1.ExtendedLocationSpec) *network.Ex
2929
return nil
3030
}
3131
return &network.ExtendedLocation{
32-
Name: to.StringPtr(src.Name),
32+
Name: pointer.String(src.Name),
3333
Type: network.ExtendedLocationTypes(src.Type),
3434
}
3535
}
@@ -40,7 +40,7 @@ func ExtendedLocationToComputeSDK(src *infrav1.ExtendedLocationSpec) *compute.Ex
4040
return nil
4141
}
4242
return &compute.ExtendedLocation{
43-
Name: to.StringPtr(src.Name),
43+
Name: pointer.String(src.Name),
4444
Type: compute.ExtendedLocationTypes(src.Type),
4545
}
4646
}

azure/converters/extendedlocation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
2424
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"
25-
"github.com/Azure/go-autorest/autorest/to"
25+
"k8s.io/utils/pointer"
2626
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2727
)
2828

@@ -39,7 +39,7 @@ func TestExtendedLocationToNetworkSDK(t *testing.T) {
3939
Type: "Edge",
4040
},
4141
want: &network.ExtendedLocation{
42-
Name: to.StringPtr("value"),
42+
Name: pointer.String("value"),
4343
Type: network.ExtendedLocationTypes("Edge"),
4444
},
4545
},
@@ -71,7 +71,7 @@ func TestExtendedLocationToComputeSDK(t *testing.T) {
7171
Type: "Edge",
7272
},
7373
want: &compute.ExtendedLocation{
74-
Name: to.StringPtr("value"),
74+
Name: pointer.String("value"),
7575
Type: compute.ExtendedLocationTypes("Edge"),
7676
},
7777
},

azure/defaults.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"net/http"
2222

2323
"github.com/Azure/go-autorest/autorest"
24-
azureautorest "github.com/Azure/go-autorest/autorest/azure"
2524
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
2625
"sigs.k8s.io/cluster-api-provider-azure/version"
2726
)
@@ -31,6 +30,8 @@ const (
3130
DefaultUserName = "capi"
3231
// DefaultAKSUserName is the default username for a created AKS VM.
3332
DefaultAKSUserName = "azureuser"
33+
// PublicCloudName is the name of the Azure public cloud.
34+
PublicCloudName = "AzurePublicCloud"
3435
)
3536

3637
const (
@@ -300,7 +301,7 @@ func ManagedClusterID(subscriptionID, resourceGroup, managedClusterName string)
300301
// Its role is to detect and report Kubernetes bootstrap failure or success.
301302
func GetBootstrappingVMExtension(osType string, cloud string, vmName string) *ExtensionSpec {
302303
// currently, the bootstrap extension is only available in AzurePublicCloud.
303-
if osType == LinuxOS && cloud == azureautorest.PublicCloud.Name {
304+
if osType == LinuxOS && cloud == PublicCloudName {
304305
// The command checks for the existence of the bootstrapSentinelFile on the machine, with retries and sleep between retries.
305306
return &ExtensionSpec{
306307
Name: BootstrappingExtensionLinux,
@@ -311,7 +312,7 @@ func GetBootstrappingVMExtension(osType string, cloud string, vmName string) *Ex
311312
"commandToExecute": LinuxBootstrapExtensionCommand,
312313
},
313314
}
314-
} else if osType == WindowsOS && cloud == azureautorest.PublicCloud.Name {
315+
} else if osType == WindowsOS && cloud == PublicCloudName {
315316
// This command for the existence of the bootstrapSentinelFile on the machine, with retries and sleep between reties.
316317
// If the file is not present after the retries are exhausted the extension fails with return code '-2' - ERROR_FILE_NOT_FOUND.
317318
return &ExtensionSpec{

azure/scope/machinepool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"io"
2525
"strings"
2626

27-
azureautorest "github.com/Azure/go-autorest/autorest/azure"
27+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2828
"github.com/pkg/errors"
2929
corev1 "k8s.io/api/core/v1"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -377,11 +377,11 @@ func (m *MachinePoolScope) createMachine(ctx context.Context, machine azure.VMSS
377377
ctx, _, done := tele.StartSpanWithLogger(ctx, "scope.MachinePoolScope.createMachine")
378378
defer done()
379379

380-
parsed, err := azureautorest.ParseResourceID(machine.ID)
380+
parsed, err := arm.ParseResourceID(machine.ID)
381381
if err != nil {
382382
return errors.Wrap(err, fmt.Sprintf("failed to parse resource id %q", machine.ID))
383383
}
384-
instanceID := strings.ReplaceAll(parsed.ResourceName, "_", "-")
384+
instanceID := strings.ReplaceAll(parsed.Name, "_", "-")
385385

386386
ampm := infrav1exp.AzureMachinePoolMachine{
387387
ObjectMeta: metav1.ObjectMeta{

azure/services/identities/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package identities
1919
import (
2020
"context"
2121

22+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2223
"github.com/Azure/azure-sdk-for-go/services/msi/mgmt/2018-11-30/msi"
2324
"github.com/Azure/go-autorest/autorest"
24-
azureautorest "github.com/Azure/go-autorest/autorest/azure"
2525
"sigs.k8s.io/cluster-api-provider-azure/azure"
2626
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
2727
)
@@ -63,11 +63,11 @@ func (ac *AzureClient) GetClientID(ctx context.Context, providerID string) (stri
6363
ctx, _, done := tele.StartSpanWithLogger(ctx, "identities.GetClientID")
6464
defer done()
6565

66-
parsed, err := azureautorest.ParseResourceID(providerID)
66+
parsed, err := arm.ParseResourceID(providerID)
6767
if err != nil {
6868
return "", err
6969
}
70-
ident, err := ac.Get(ctx, parsed.ResourceGroup, parsed.ResourceName)
70+
ident, err := ac.Get(ctx, parsed.ResourceGroupName, parsed.Name)
7171
if err != nil {
7272
return "", err
7373
}

azure/services/natgateways/spec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package natgateways
1919
import (
2020
"context"
2121

22+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2223
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"
23-
azureautorest "github.com/Azure/go-autorest/autorest/azure"
2424
"github.com/pkg/errors"
2525
"k8s.io/utils/pointer"
2626
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
@@ -97,11 +97,11 @@ func hasPublicIP(natGateway network.NatGateway, publicIPName string) bool {
9797
}
9898

9999
for _, publicIP := range *natGateway.PublicIPAddresses {
100-
resource, err := azureautorest.ParseResourceID(*publicIP.ID)
100+
resource, err := arm.ParseResourceID(*publicIP.ID)
101101
if err != nil {
102102
continue
103103
}
104-
if resource.ResourceName == publicIPName {
104+
if resource.Name == publicIPName {
105105
return true
106106
}
107107
}

azure/services/scalesetvms/scalesetvms.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25-
azureautorest "github.com/Azure/go-autorest/autorest/azure"
25+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2626
"github.com/go-logr/logr"
2727
"github.com/pkg/errors"
2828
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
@@ -147,11 +147,11 @@ func (s *Service) deleteVMSSFlexVM(ctx context.Context, resourceID string) error
147147
}
148148
}()
149149

150-
parsed, err := azureautorest.ParseResourceID(resourceID)
150+
parsed, err := arm.ParseResourceID(resourceID)
151151
if err != nil {
152152
return errors.Wrap(err, fmt.Sprintf("failed to parse resource id %q", resourceID))
153153
}
154-
resourceGroup, resourceName := parsed.ResourceGroup, parsed.ResourceName
154+
resourceGroup, resourceName := parsed.ResourceGroupName, parsed.Name
155155

156156
log.V(4).Info("entering delete")
157157
future := s.Scope.GetLongRunningOperationState(resourceName, serviceName, infrav1.DeleteFuture)

azure/services/scalesetvms/scalesetvms_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func TestService_Delete(t *testing.T) {
293293
s.OrchestrationMode().Return(infrav1.FlexibleOrchestrationMode)
294294
v.GetByID(gomock2.AContext(), "foo").Return(compute.VirtualMachine{}, nil)
295295
},
296-
Err: errors.Wrap(fmt.Errorf("parsing failed for %s. Invalid resource Id format", "foo"), fmt.Sprintf("failed to parse resource id %q", "foo")),
296+
Err: errors.Wrap(fmt.Errorf("invalid resource ID: resource id '%s' must start with '/'", "foo"), fmt.Sprintf("failed to parse resource id %q", "foo")),
297297
},
298298
}
299299

azure/services/virtualmachines/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"time"
2525

26+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2627
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
2728
"github.com/Azure/go-autorest/autorest"
2829
azureautorest "github.com/Azure/go-autorest/autorest/azure"
@@ -89,14 +90,14 @@ func (ac *AzureClient) GetByID(ctx context.Context, resourceID string) (compute.
8990
ctx, log, done := tele.StartSpanWithLogger(ctx, "virtualmachines.AzureClient.GetByID")
9091
defer done()
9192

92-
parsed, err := azureautorest.ParseResourceID(resourceID)
93+
parsed, err := arm.ParseResourceID(resourceID)
9394
if err != nil {
9495
return compute.VirtualMachine{}, errors.Wrap(err, fmt.Sprintf("failed parsing the VM resource id %q", resourceID))
9596
}
9697

9798
log.V(4).Info("parsed VM resourceID", "parsed", parsed)
9899

99-
return ac.virtualmachines.Get(ctx, parsed.ResourceGroup, parsed.ResourceName, "")
100+
return ac.virtualmachines.Get(ctx, parsed.ResourceGroupName, parsed.Name, "")
100101
}
101102

102103
// CreateOrUpdateAsync creates or updates a virtual machine asynchronously.

0 commit comments

Comments
 (0)