@@ -2,6 +2,7 @@ package azure
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "strings"
78 "time"
@@ -13,7 +14,6 @@ import (
1314 azenc "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
1415 azmarketplace "github.com/Azure/azure-sdk-for-go/profiles/latest/marketplaceordering/mgmt/marketplaceordering"
1516 "github.com/Azure/go-autorest/autorest/to"
16- "github.com/pkg/errors"
1717)
1818
1919//go:generate mockgen -source=./client.go -destination=mock/azureclient_generated.go -package=mock
@@ -65,7 +65,7 @@ func (c *Client) GetVirtualNetwork(ctx context.Context, resourceGroupName, virtu
6565
6666 vnet , err := vnetClient .Get (ctx , resourceGroupName , virtualNetwork , "" )
6767 if err != nil {
68- return nil , errors . Wrapf ( err , "failed to get virtual network %s" , virtualNetwork )
68+ return nil , fmt . Errorf ( "failed to get virtual network %s: %w " , virtualNetwork , err )
6969 }
7070
7171 return & vnet , nil
@@ -83,7 +83,7 @@ func (c *Client) getSubnet(ctx context.Context, resourceGroupName, virtualNetwor
8383
8484 subnet , err := subnetsClient .Get (ctx , resourceGroupName , virtualNetwork , subNetwork , "" )
8585 if err != nil {
86- return nil , errors . Wrapf ( err , "failed to get subnet %s" , subNetwork )
86+ return nil , fmt . Errorf ( "failed to get subnet %s: %w " , subNetwork , err )
8787 }
8888
8989 return & subnet , nil
@@ -131,7 +131,7 @@ func (c *Client) ListLocations(ctx context.Context) (*[]azsubs.Location, error)
131131
132132 locations , err := subsClient .ListLocations (ctx , c .ssn .Credentials .SubscriptionID )
133133 if err != nil {
134- return nil , errors . Wrapf ( err , "failed to list locations" )
134+ return nil , fmt . Errorf ( "failed to list locations: %w" , err )
135135 }
136136
137137 return locations .Value , nil
@@ -156,7 +156,7 @@ func (c *Client) GetResourcesProvider(ctx context.Context, resourceProviderNames
156156
157157 provider , err := providersClient .Get (ctx , resourceProviderNamespace , "" )
158158 if err != nil {
159- return nil , errors . Wrapf ( err , "failed to get resource provider %s" , resourceProviderNamespace )
159+ return nil , fmt . Errorf ( "failed to get resource provider %s: %w " , resourceProviderNamespace , err )
160160 }
161161
162162 return & provider , nil
@@ -180,7 +180,7 @@ func (c *Client) GetDiskSkus(ctx context.Context, region string) ([]azsku.Resour
180180
181181 for skuPage , err := client .List (ctx ); skuPage .NotDone (); err = skuPage .NextWithContext (ctx ) {
182182 if err != nil {
183- return nil , errors . Wrap ( err , "error fetching SKU pages" )
183+ return nil , fmt . Errorf ( "error fetching SKU pages: %w" , err )
184184 }
185185 for _ , page := range skuPage .Values () {
186186 for _ , diskRegion := range to .StringSlice (page .Locations ) {
@@ -195,7 +195,7 @@ func (c *Client) GetDiskSkus(ctx context.Context, region string) ([]azsku.Resour
195195 return sku , nil
196196 }
197197
198- return nil , errors .Errorf ("no disks for specified subscription in region %s" , region )
198+ return nil , fmt .Errorf ("no disks for specified subscription in region %s" , region )
199199}
200200
201201// GetGroup returns resource group for the groupName.
@@ -207,7 +207,7 @@ func (c *Client) GetGroup(ctx context.Context, groupName string) (*azres.Group,
207207
208208 res , err := client .Get (ctx , groupName )
209209 if err != nil {
210- return nil , errors . Wrap ( err , "failed to get resource group" )
210+ return nil , fmt . Errorf ( "failed to get resource group: %w" , err )
211211 }
212212 return & res , nil
213213}
@@ -222,7 +222,7 @@ func (c *Client) ListResourceIDsByGroup(ctx context.Context, groupName string) (
222222 var res []string
223223 for resPage , err := client .ListByResourceGroup (ctx , groupName , "" , "" , nil ); resPage .NotDone (); err = resPage .NextWithContext (ctx ) {
224224 if err != nil {
225- return nil , errors . Wrap ( err , "error fetching resource pages" )
225+ return nil , fmt . Errorf ( "error fetching resource pages: %w" , err )
226226 }
227227 for _ , page := range resPage .Values () {
228228 res = append (res , to .String (page .ID ))
@@ -240,7 +240,7 @@ func (c *Client) GetVirtualMachineSku(ctx context.Context, name, region string)
240240
241241 for page , err := client .List (ctx ); page .NotDone (); err = page .NextWithContext (ctx ) {
242242 if err != nil {
243- return nil , errors . Wrap ( err , "error fetching SKU pages" )
243+ return nil , fmt . Errorf ( "error fetching SKU pages: %w" , err )
244244 }
245245 for _ , sku := range page .Values () {
246246 // Filter out resources that are not virtualMachines
@@ -271,7 +271,7 @@ func (c *Client) GetDiskEncryptionSet(ctx context.Context, subscriptionID, group
271271
272272 diskEncryptionSet , err := client .Get (ctx , groupName , diskEncryptionSetName )
273273 if err != nil {
274- return nil , errors . Wrap ( err , "failed to get disk encryption set" )
274+ return nil , fmt . Errorf ( "failed to get disk encryption set: %w" , err )
275275 }
276276
277277 return & diskEncryptionSet , nil
@@ -281,7 +281,7 @@ func (c *Client) GetDiskEncryptionSet(ctx context.Context, subscriptionID, group
281281func (c * Client ) GetVirtualMachineFamily (ctx context.Context , name , region string ) (string , error ) {
282282 typeMeta , err := c .GetVirtualMachineSku (ctx , name , region )
283283 if err != nil {
284- return "" , fmt .Errorf ("error connecting to Azure client: %v " , err )
284+ return "" , fmt .Errorf ("error connecting to Azure client: %w " , err )
285285 }
286286 if typeMeta == nil {
287287 return "" , fmt .Errorf ("not found in region %s" , region )
@@ -298,7 +298,7 @@ func (c *Client) GetVirtualMachineFamily(ctx context.Context, name, region strin
298298func (c * Client ) GetVMCapabilities (ctx context.Context , instanceType , region string ) (map [string ]string , error ) {
299299 typeMeta , err := c .GetVirtualMachineSku (ctx , instanceType , region )
300300 if err != nil {
301- return nil , fmt .Errorf ("error connecting to Azure client: %v " , err )
301+ return nil , fmt .Errorf ("error connecting to Azure client: %w " , err )
302302 }
303303 if typeMeta == nil {
304304 return nil , fmt .Errorf ("not found in region %s" , region )
@@ -330,7 +330,7 @@ func (c *Client) GetMarketplaceImage(ctx context.Context, region, publisher, off
330330 defer cancel ()
331331
332332 image , err := client .Get (ctx , region , publisher , offer , sku , version )
333- return image , errors . Wrap ( err , "could not get marketplace image" )
333+ return image , fmt . Errorf ( "could not get marketplace image: %w" , err )
334334}
335335
336336// AreMarketplaceImageTermsAccepted tests whether the terms have been accepted for the specified marketplace VM image.
0 commit comments