Skip to content

Commit 7f103d4

Browse files
Merge pull request openshift#7778 from r4f4/azure-install-errors-deprec
CORS-2775: ic: azure: remove deprecated `errors` package
2 parents 31607ba + a8b8faa commit 7f103d4

File tree

6 files changed

+41
-43
lines changed

6 files changed

+41
-43
lines changed

pkg/asset/installconfig/azure/azure.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
survey "github.com/AlecAivazis/survey/v2"
1010
"github.com/AlecAivazis/survey/v2/core"
1111
"github.com/Azure/go-autorest/autorest/to"
12-
"github.com/pkg/errors"
1312

1413
"github.com/openshift/installer/pkg/types/azure"
1514
)
@@ -31,12 +30,12 @@ func Platform() (*azure.Platform, error) {
3130

3231
regions, err := getRegions(context.TODO(), client)
3332
if err != nil {
34-
return nil, errors.Wrap(err, "failed to get list of regions")
33+
return nil, fmt.Errorf("failed to get list of regions: %w", err)
3534
}
3635

3736
resourceCapableRegions, err := getResourceCapableRegions(context.TODO(), client)
3837
if err != nil {
39-
return nil, errors.Wrap(err, "failed to get list of resources to check available regions")
38+
return nil, fmt.Errorf("failed to get list of resources to check available regions: %w", err)
4039
}
4140

4241
longRegions := make([]string, 0, len(regions))
@@ -63,7 +62,7 @@ func Platform() (*azure.Platform, error) {
6362

6463
_, ok := regions[defaultRegion]
6564
if !ok {
66-
return nil, errors.Errorf("installer bug: invalid default azure region %q", defaultRegion)
65+
return nil, fmt.Errorf("installer bug: invalid default azure region %q", defaultRegion)
6766
}
6867

6968
sort.Strings(longRegions)
@@ -82,7 +81,7 @@ func Platform() (*azure.Platform, error) {
8281
choice := regionTransform(ans).(core.OptionAnswer).Value
8382
i := sort.SearchStrings(shortRegions, choice)
8483
if i == len(shortRegions) || shortRegions[i] != choice {
85-
return errors.Errorf("invalid region %q", choice)
84+
return fmt.Errorf("invalid region %q", choice)
8685
}
8786
return nil
8887
}),

pkg/asset/installconfig/azure/client.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package azure
22

33
import (
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
281281
func (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
298298
func (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.

pkg/asset/installconfig/azure/dns.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package azure
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

89
survey "github.com/AlecAivazis/survey/v2"
910
azdns "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/dns/mgmt/dns"
1011
"github.com/Azure/go-autorest/autorest/to"
11-
"github.com/pkg/errors"
1212
)
1313

1414
// DNSConfig exposes functions to choose the DNS settings
@@ -85,7 +85,7 @@ func (config DNSConfig) GetDNSZone() (*Zone, error) {
8585
},
8686
}, &zoneName)
8787
if err != nil {
88-
return nil, errors.Wrap(err, "failed UserInput")
88+
return nil, fmt.Errorf("failed UserInput: %w", err)
8989
}
9090

9191
return &Zone{

pkg/asset/installconfig/azure/metadata.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package azure
22

33
import (
4+
"fmt"
45
"sync"
56

6-
"github.com/pkg/errors"
7-
87
typesazure "github.com/openshift/installer/pkg/types/azure"
98
)
109

@@ -63,7 +62,7 @@ func (m *Metadata) unlockedSession() (*Session, error) {
6362
var err error
6463
m.session, err = GetSessionWithCredentials(m.CloudName, m.ARMEndpoint, m.Credentials)
6564
if err != nil {
66-
return nil, errors.Wrap(err, "creating Azure session")
65+
return nil, fmt.Errorf("creating Azure session: %w", err)
6766
}
6867
}
6968

pkg/asset/installconfig/azure/session.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package azure
22

33
import (
44
"encoding/json"
5+
"errors"
6+
"fmt"
57
"io/fs"
68
"os"
79
"path/filepath"
@@ -16,7 +18,6 @@ import (
1618
azureenv "github.com/Azure/go-autorest/autorest/azure"
1719
"github.com/jongio/azidext/go/azidext"
1820
azurekiota "github.com/microsoft/kiota-authentication-azure-go"
19-
"github.com/pkg/errors"
2021
"github.com/sirupsen/logrus"
2122

2223
"github.com/openshift/installer/pkg/types/azure"
@@ -79,7 +80,7 @@ func GetSessionWithCredentials(cloudName azure.CloudEnvironment, armEndpoint str
7980
cloudEnv, err = azureenv.EnvironmentFromName(string(cloudName))
8081
}
8182
if err != nil {
82-
return nil, errors.Wrapf(err, "failed to get Azure environment for the %q cloud", cloudName)
83+
return nil, fmt.Errorf("failed to get Azure environment for the %q cloud: %w", cloudName, err)
8384
}
8485

8586
var cloudConfig cloud.Configuration
@@ -152,11 +153,11 @@ func credentialsFromFileOrUser() (*Credentials, error) {
152153
logrus.Infof("Asking user to provide authentication info")
153154
credentials, cerr := askForCredentials()
154155
if cerr != nil {
155-
return nil, errors.Wrap(cerr, "failed to retrieve credentials from user")
156+
return nil, fmt.Errorf("failed to retrieve credentials from user: %w", cerr)
156157
}
157158
logrus.Infof("Saving user credentials to %q", authFilePath)
158159
if cerr = saveCredentials(*credentials, authFilePath); cerr != nil {
159-
return nil, errors.Wrap(cerr, "failed to save credentials")
160+
return nil, fmt.Errorf("failed to save credentials: %w", cerr)
160161
}
161162
authFile = *credentials
162163
} else {
@@ -280,7 +281,7 @@ func newTokenCredentialFromCredentials(credentials *Credentials, cloudConfig clo
280281

281282
cred, err := azidentity.NewClientSecretCredential(credentials.TenantID, credentials.ClientID, credentials.ClientSecret, &options)
282283
if err != nil {
283-
return nil, errors.Wrap(err, "failed to get client credentials from secret")
284+
return nil, fmt.Errorf("failed to get client credentials from secret: %w", err)
284285
}
285286
return cred, nil
286287
}
@@ -294,7 +295,7 @@ func newTokenCredentialFromCertificates(credentials *Credentials, cloudConfig cl
294295

295296
data, err := os.ReadFile(credentials.ClientCertificatePath)
296297
if err != nil {
297-
return nil, errors.Wrap(err, "failed to read client certificate file")
298+
return nil, fmt.Errorf("failed to read client certificate file: %w", err)
298299
}
299300

300301
// NewClientCertificateCredential requires at least one *x509.Certificate,
@@ -304,12 +305,12 @@ func newTokenCredentialFromCertificates(credentials *Credentials, cloudConfig cl
304305
// keys.
305306
certs, key, err := azidentity.ParseCertificates(data, []byte(credentials.ClientCertificatePassword))
306307
if err != nil {
307-
return nil, errors.Wrap(err, "failed to parse client certificate")
308+
return nil, fmt.Errorf("failed to parse client certificate: %w", err)
308309
}
309310

310311
cred, err := azidentity.NewClientCertificateCredential(credentials.TenantID, credentials.ClientID, certs, key, &options)
311312
if err != nil {
312-
return nil, errors.Wrap(err, "failed to get client credentials from certificate")
313+
return nil, fmt.Errorf("failed to get client credentials from certificate: %w", err)
313314
}
314315
return cred, nil
315316
}
@@ -327,7 +328,7 @@ func newTokenCredentialFromMSI(credentials *Credentials, cloudConfig cloud.Confi
327328

328329
cred, err := azidentity.NewManagedIdentityCredential(&options)
329330
if err != nil {
330-
return nil, errors.Wrap(err, "failed to get client credentials from MSI")
331+
return nil, fmt.Errorf("failed to get client credentials from MSI: %w", err)
331332
}
332333
return cred, nil
333334
}
@@ -343,7 +344,7 @@ func newSessionFromCredentials(cloudEnv azureenv.Environment, credentials *Crede
343344
}
344345
authProvider, err := azurekiota.NewAzureIdentityAuthenticationProviderWithScopes(cred, scope)
345346
if err != nil {
346-
return nil, errors.Wrap(err, "failed to get Azidentity authentication provider")
347+
return nil, fmt.Errorf("failed to get Azidentity authentication provider: %w", err)
347348
}
348349

349350
// Use an adapter so azidentity in the Azure SDK can be used as

pkg/asset/installconfig/azure/validation.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/network/mgmt/network"
1414
azenc "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
1515
"github.com/Azure/go-autorest/autorest/to"
16-
"github.com/pkg/errors"
1716
"github.com/sirupsen/logrus"
1817
"k8s.io/apimachinery/pkg/util/sets"
1918
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -98,7 +97,7 @@ func validateConfidentialDiskEncryptionSet(client API, diskEncryptionSet *aztype
9897
if requestErr != nil {
9998
return requestErr
10099
} else if resp == nil || resp.EncryptionSetProperties == nil || resp.EncryptionSetProperties.EncryptionType != azenc.ConfidentialVMEncryptedWithCustomerKey {
101-
return errors.Errorf("the disk encryption set should be created with type %s", azenc.ConfidentialVMEncryptedWithCustomerKey)
100+
return fmt.Errorf("the disk encryption set should be created with type %s", azenc.ConfidentialVMEncryptedWithCustomerKey)
102101
}
103102
return nil
104103
}
@@ -549,7 +548,7 @@ func validateMachineNetworksContainIP(fldPath *field.Path, networks []types.Mach
549548
func validateRegion(client API, fieldPath *field.Path, p *aztypes.Platform) field.ErrorList {
550549
locations, err := client.ListLocations(context.TODO())
551550
if err != nil {
552-
return field.ErrorList{field.InternalError(fieldPath, errors.Wrap(err, "failed to retrieve available regions"))}
551+
return field.ErrorList{field.InternalError(fieldPath, fmt.Errorf("failed to retrieve available regions: %w", err))}
553552
}
554553

555554
availableRegions := map[string]string{}
@@ -572,7 +571,7 @@ func validateRegion(client API, fieldPath *field.Path, p *aztypes.Platform) fiel
572571

573572
provider, err := client.GetResourcesProvider(context.TODO(), "Microsoft.Resources")
574573
if err != nil {
575-
return field.ErrorList{field.InternalError(fieldPath, errors.Wrap(err, "failed to retrieve resource capable regions"))}
574+
return field.ErrorList{field.InternalError(fieldPath, fmt.Errorf("failed to retrieve resource capable regions: %w", err))}
576575
}
577576

578577
for _, resType := range *provider.ResourceTypes {
@@ -605,19 +604,19 @@ func ValidatePublicDNS(ic *types.InstallConfig, azureDNS *DNSConfig) error {
605604
// Look for an existing CNAME first
606605
rs, err := azureDNS.GetDNSRecordSet(rgName, zoneName, record, azdns.CNAME)
607606
if err == nil && rs.CnameRecord != nil {
608-
return errors.New(fmt.Sprintf(fmtStr, zoneName, azdns.CNAME, clusterName))
607+
return fmt.Errorf(fmtStr, zoneName, azdns.CNAME, clusterName)
609608
}
610609

611610
// Look for an A record
612611
rs, err = azureDNS.GetDNSRecordSet(rgName, zoneName, record, azdns.A)
613612
if err == nil && rs.ARecords != nil && len(*rs.ARecords) > 0 {
614-
return errors.New(fmt.Sprintf(fmtStr, zoneName, azdns.A, clusterName))
613+
return fmt.Errorf(fmtStr, zoneName, azdns.A, clusterName)
615614
}
616615

617616
// Look for an AAAA record
618617
rs, err = azureDNS.GetDNSRecordSet(rgName, zoneName, record, azdns.AAAA)
619618
if err == nil && rs.AaaaRecords != nil && len(*rs.AaaaRecords) > 0 {
620-
return errors.New(fmt.Sprintf(fmtStr, zoneName, azdns.AAAA, clusterName))
619+
return fmt.Errorf(fmtStr, zoneName, azdns.AAAA, clusterName)
621620
}
622621

623622
return nil
@@ -642,7 +641,7 @@ func validateResourceGroup(client API, fieldPath *field.Path, platform *aztypes.
642641
}
643642
group, err := client.GetGroup(context.TODO(), platform.ResourceGroupName)
644643
if err != nil {
645-
return append(allErrs, field.InternalError(fieldPath.Child("resourceGroupName"), errors.Wrap(err, "failed to get resource group")))
644+
return append(allErrs, field.InternalError(fieldPath.Child("resourceGroupName"), fmt.Errorf("failed to get resource group: %w", err)))
646645
}
647646

648647
normalizedRegion := strings.Replace(strings.ToLower(to.String(group.Location)), " ", "", -1)
@@ -669,7 +668,7 @@ func validateResourceGroup(client API, fieldPath *field.Path, platform *aztypes.
669668
if !platform.IsARO() {
670669
ids, err := client.ListResourceIDsByGroup(context.TODO(), platform.ResourceGroupName)
671670
if err != nil {
672-
return append(allErrs, field.InternalError(fieldPath.Child("resourceGroupName"), errors.Wrap(err, "failed to list resources in the resource group")))
671+
return append(allErrs, field.InternalError(fieldPath.Child("resourceGroupName"), fmt.Errorf("failed to list resources in the resource group: %w", err)))
673672
}
674673
if l := len(ids); l > 0 {
675674
if len(ids) > 2 {

0 commit comments

Comments
 (0)