Skip to content

Commit 6f4b11e

Browse files
Merge pull request #7835 from r4f4/aws-validate-instance-arch
OCPBUGS-25600: aws: validate instance arch
2 parents 7ef1c84 + 161789f commit 6f4b11e

File tree

11 files changed

+134
-82
lines changed

11 files changed

+134
-82
lines changed

pkg/asset/installconfig/aws/availabilityzones.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/aws/aws-sdk-go/aws"
88
"github.com/aws/aws-sdk-go/aws/session"
99
"github.com/aws/aws-sdk-go/service/ec2"
10-
"github.com/pkg/errors"
1110

1211
typesaws "github.com/openshift/installer/pkg/types/aws"
1312
)
@@ -64,7 +63,7 @@ func describeAvailabilityZones(ctx context.Context, session *session.Session, re
6463
}
6564
resp, err := client.DescribeAvailabilityZonesWithContext(ctx, input)
6665
if err != nil {
67-
return nil, errors.Wrap(err, "fetching zones")
66+
return nil, fmt.Errorf("fetching zones: %w", err)
6867
}
6968

7069
return resp.AvailabilityZones, nil
@@ -75,7 +74,7 @@ func describeAvailabilityZones(ctx context.Context, session *session.Session, re
7574
func filterZonesByType(ctx context.Context, session *session.Session, region string, zoneType string) ([]string, error) {
7675
azs, err := describeAvailabilityZones(ctx, session, region, []string{})
7776
if err != nil {
78-
return nil, errors.Wrapf(err, "fetching %s", zoneType)
77+
return nil, fmt.Errorf("fetching %s: %w", zoneType, err)
7978
}
8079
zones := []string{}
8180
for _, zone := range azs {
@@ -85,7 +84,7 @@ func filterZonesByType(ctx context.Context, session *session.Session, region str
8584
}
8685

8786
if len(zones) == 0 {
88-
return nil, errors.Errorf("no zones with type %s in %s", zoneType, region)
87+
return nil, fmt.Errorf("no zones with type %s in %s", zoneType, region)
8988
}
9089

9190
return zones, nil
@@ -118,7 +117,7 @@ func edgeZones(ctx context.Context, session *session.Session, region string) ([]
118117
func describeFilteredZones(ctx context.Context, session *session.Session, region string, zones []string) ([]*ec2.AvailabilityZone, error) {
119118
azs, err := describeAvailabilityZones(ctx, session, region, zones)
120119
if err != nil {
121-
return nil, errors.Wrapf(err, "fetching %s", zones)
120+
return nil, fmt.Errorf("fetching %s: %w", zones, err)
122121
}
123122

124123
return azs, nil

pkg/asset/installconfig/aws/basedomain.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package aws
22

33
import (
4+
"errors"
5+
"fmt"
46
"net/http"
57
"sort"
68
"strings"
@@ -11,15 +13,14 @@ import (
1113
"github.com/aws/aws-sdk-go/aws/awserr"
1214
"github.com/aws/aws-sdk-go/aws/session"
1315
"github.com/aws/aws-sdk-go/service/route53"
14-
"github.com/pkg/errors"
1516
"github.com/sirupsen/logrus"
1617
)
1718

1819
// IsForbidden returns true if and only if the input error is an HTTP
1920
// 403 error from the AWS API.
2021
func IsForbidden(err error) bool {
21-
requestError, ok := err.(awserr.RequestFailure)
22-
return ok && requestError.StatusCode() == http.StatusForbidden
22+
var requestError awserr.RequestFailure
23+
return errors.As(err, &requestError) && requestError.StatusCode() == http.StatusForbidden
2324
}
2425

2526
// GetBaseDomain returns a base domain chosen from among the account's
@@ -45,7 +46,7 @@ func GetBaseDomain() (string, error) {
4546
return !lastPage
4647
},
4748
); err != nil {
48-
return "", errors.Wrap(err, "list hosted zones")
49+
return "", fmt.Errorf("list hosted zones: %w", err)
4950
}
5051

5152
publicZones := make([]string, 0, len(publicZoneMap))
@@ -69,12 +70,12 @@ func GetBaseDomain() (string, error) {
6970
choice := ans.(core.OptionAnswer).Value
7071
i := sort.SearchStrings(publicZones, choice)
7172
if i == len(publicZones) || publicZones[i] != choice {
72-
return errors.Errorf("invalid base domain %q", choice)
73+
return fmt.Errorf("invalid base domain %q", choice)
7374
}
7475
return nil
7576
}),
7677
); err != nil {
77-
return "", errors.Wrap(err, "failed UserInput")
78+
return "", fmt.Errorf("failed UserInput: %w", err)
7879
}
7980

8081
return domain, nil
@@ -95,10 +96,10 @@ func GetPublicZone(sess *session.Session, name string) (*route53.HostedZone, err
9596

9697
client := route53.New(sess)
9798
if err := client.ListHostedZonesPages(&route53.ListHostedZonesInput{}, f); err != nil {
98-
return nil, errors.Wrap(err, "listing hosted zones")
99+
return nil, fmt.Errorf("listing hosted zones: %w", err)
99100
}
100101
if res == nil {
101-
return nil, errors.Errorf("No public route53 zone found matching name %q", name)
102+
return nil, fmt.Errorf("no public route53 zone found matching name %q", name)
102103
}
103104
return res, nil
104105
}

pkg/asset/installconfig/aws/instancetypes.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package aws
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/aws/aws-sdk-go/aws"
78
"github.com/aws/aws-sdk-go/aws/session"
89
"github.com/aws/aws-sdk-go/service/ec2"
9-
"github.com/pkg/errors"
1010
)
1111

1212
// InstanceType holds metadata for an instance type.
1313
type InstanceType struct {
1414
DefaultVCpus int64
1515
MemInMiB int64
16+
Arches []string
1617
}
1718

1819
// instanceTypes retrieves a list of instance types for the given region.
@@ -27,11 +28,12 @@ func instanceTypes(ctx context.Context, session *session.Session, region string)
2728
types[*info.InstanceType] = InstanceType{
2829
DefaultVCpus: aws.Int64Value(info.VCpuInfo.DefaultVCpus),
2930
MemInMiB: aws.Int64Value(info.MemoryInfo.SizeInMiB),
31+
Arches: aws.StringValueSlice(info.ProcessorInfo.SupportedArchitectures),
3032
}
3133
}
3234
return !lastPage
3335
}); err != nil {
34-
return nil, errors.Wrap(err, "fetching instance types")
36+
return nil, fmt.Errorf("fetching instance types: %w", err)
3537
}
3638

3739
return types, nil

pkg/asset/installconfig/aws/metadata.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package aws
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
57
"sync"
68

79
awssdk "github.com/aws/aws-sdk-go/aws"
810
"github.com/aws/aws-sdk-go/aws/session"
9-
"github.com/pkg/errors"
1011

1112
typesaws "github.com/openshift/installer/pkg/types/aws"
1213
)
@@ -50,7 +51,7 @@ func (m *Metadata) unlockedSession(ctx context.Context) (*session.Session, error
5051
var err error
5152
m.session, err = GetSessionWithOptions(WithRegion(m.Region), WithServiceEndpoints(m.Region, m.Services))
5253
if err != nil {
53-
return nil, errors.Wrap(err, "creating AWS session")
54+
return nil, fmt.Errorf("creating AWS session: %w", err)
5455
}
5556
}
5657

@@ -69,7 +70,7 @@ func (m *Metadata) AvailabilityZones(ctx context.Context) ([]string, error) {
6970
}
7071
m.availabilityZones, err = availabilityZones(ctx, session, m.Region)
7172
if err != nil {
72-
return nil, errors.Wrap(err, "error retrieving Availability Zones")
73+
return nil, fmt.Errorf("error retrieving Availability Zones: %w", err)
7374
}
7475
}
7576

@@ -89,7 +90,7 @@ func (m *Metadata) EdgeZones(ctx context.Context) ([]string, error) {
8990

9091
m.edgeZones, err = edgeZones(ctx, session, m.Region)
9192
if err != nil {
92-
return nil, errors.Wrap(err, "getting Local Zones")
93+
return nil, fmt.Errorf("getting Local Zones: %w", err)
9394
}
9495
}
9596

@@ -102,7 +103,7 @@ func (m *Metadata) EdgeZones(ctx context.Context) ([]string, error) {
102103
func (m *Metadata) EdgeSubnets(ctx context.Context) (Subnets, error) {
103104
err := m.populateSubnets(ctx)
104105
if err != nil {
105-
return nil, errors.Wrap(err, "error retrieving Edge Subnets")
106+
return nil, fmt.Errorf("error retrieving Edge Subnets: %w", err)
106107
}
107108
return m.edgeSubnets, nil
108109
}
@@ -111,11 +112,11 @@ func (m *Metadata) EdgeSubnets(ctx context.Context) (Subnets, error) {
111112
func (m *Metadata) SetZoneAttributes(ctx context.Context, zoneNames []string, zones Zones) error {
112113
sess, err := m.Session(ctx)
113114
if err != nil {
114-
return errors.Wrap(err, "unable to get aws session to populate zone details")
115+
return fmt.Errorf("unable to get aws session to populate zone details: %w", err)
115116
}
116117
azs, err := describeFilteredZones(ctx, sess, m.Region, zoneNames)
117118
if err != nil {
118-
return errors.Wrap(err, "unable to filter zones")
119+
return fmt.Errorf("unable to filter zones: %w", err)
119120
}
120121

121122
for _, az := range azs {
@@ -140,11 +141,11 @@ func (m *Metadata) SetZoneAttributes(ctx context.Context, zoneNames []string, zo
140141
func (m *Metadata) AllZones(ctx context.Context) (Zones, error) {
141142
sess, err := m.Session(ctx)
142143
if err != nil {
143-
return nil, errors.Wrap(err, "unable to get aws session to populate zone details")
144+
return nil, fmt.Errorf("unable to get aws session to populate zone details: %w", err)
144145
}
145146
azs, err := describeAvailabilityZones(ctx, sess, m.Region, []string{})
146147
if err != nil {
147-
return nil, errors.Wrap(err, "unable to gather availability zones")
148+
return nil, fmt.Errorf("unable to gather availability zones: %w", err)
148149
}
149150
zoneDesc := make(Zones, len(azs))
150151
for _, az := range azs {
@@ -167,7 +168,7 @@ func (m *Metadata) AllZones(ctx context.Context) (Zones, error) {
167168
func (m *Metadata) PrivateSubnets(ctx context.Context) (Subnets, error) {
168169
err := m.populateSubnets(ctx)
169170
if err != nil {
170-
return nil, errors.Wrap(err, "error retrieving Private Subnets")
171+
return nil, fmt.Errorf("error retrieving Private Subnets: %w", err)
171172
}
172173
return m.privateSubnets, nil
173174
}
@@ -178,7 +179,7 @@ func (m *Metadata) PrivateSubnets(ctx context.Context) (Subnets, error) {
178179
func (m *Metadata) PublicSubnets(ctx context.Context) (Subnets, error) {
179180
err := m.populateSubnets(ctx)
180181
if err != nil {
181-
return nil, errors.Wrap(err, "error retrieving Public Subnets")
182+
return nil, fmt.Errorf("error retrieving Public Subnets: %w", err)
182183
}
183184
return m.publicSubnets, nil
184185
}
@@ -187,7 +188,7 @@ func (m *Metadata) PublicSubnets(ctx context.Context) (Subnets, error) {
187188
func (m *Metadata) VPC(ctx context.Context) (string, error) {
188189
err := m.populateSubnets(ctx)
189190
if err != nil {
190-
return "", errors.Wrap(err, "error retrieving VPC")
191+
return "", fmt.Errorf("error retrieving VPC: %w", err)
191192
}
192193
return m.vpc, nil
193194
}
@@ -231,7 +232,7 @@ func (m *Metadata) InstanceTypes(ctx context.Context) (map[string]InstanceType,
231232

232233
m.instanceTypes, err = instanceTypes(ctx, session, m.Region)
233234
if err != nil {
234-
return nil, errors.Wrap(err, "error listing instance types")
235+
return nil, fmt.Errorf("error listing instance types: %w", err)
235236
}
236237
}
237238

pkg/asset/installconfig/aws/permissions.go

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

44
import (
5+
"errors"
6+
"fmt"
7+
58
"github.com/aws/aws-sdk-go/aws/session"
69
"github.com/aws/aws-sdk-go/service/iam"
7-
"github.com/pkg/errors"
810
"github.com/sirupsen/logrus"
911

1012
ccaws "github.com/openshift/cloud-credential-operator/pkg/aws"
@@ -270,14 +272,14 @@ func ValidateCreds(ssn *session.Session, groups []PermissionGroup, region string
270272
for _, group := range groups {
271273
groupPerms, ok := permissions[group]
272274
if !ok {
273-
return errors.Errorf("unable to access permissions group %s", group)
275+
return fmt.Errorf("unable to access permissions group %s", group)
274276
}
275277
requiredPermissions = append(requiredPermissions, groupPerms...)
276278
}
277279

278280
client, err := ccaws.NewClientFromIAMClient(iam.New(ssn))
279281
if err != nil {
280-
return errors.Wrap(err, "failed to create client for permission check")
282+
return fmt.Errorf("failed to create client for permission check: %w", err)
281283
}
282284

283285
sParams := &ccaws.SimulateParams{
@@ -288,7 +290,7 @@ func ValidateCreds(ssn *session.Session, groups []PermissionGroup, region string
288290
logger := logrus.StandardLogger()
289291
canInstall, err := ccaws.CheckPermissionsAgainstActions(client, requiredPermissions, sParams, logger)
290292
if err != nil {
291-
return errors.Wrap(err, "checking install permissions")
293+
return fmt.Errorf("checking install permissions: %w", err)
292294
}
293295
if !canInstall {
294296
return errors.New("current credentials insufficient for performing cluster installation")
@@ -297,7 +299,7 @@ func ValidateCreds(ssn *session.Session, groups []PermissionGroup, region string
297299
// Check whether we can mint new creds for cluster services needing to interact with the cloud
298300
canMint, err := ccaws.CheckCloudCredCreation(client, logger)
299301
if err != nil {
300-
return errors.Wrap(err, "mint credentials check")
302+
return fmt.Errorf("mint credentials check: %w", err)
301303
}
302304
if canMint {
303305
return nil
@@ -307,7 +309,7 @@ func ValidateCreds(ssn *session.Session, groups []PermissionGroup, region string
307309
// cluster services needing to interact with the cloud
308310
canPassthrough, err := ccaws.CheckCloudCredPassthrough(client, sParams, logger)
309311
if err != nil {
310-
return errors.Wrap(err, "passthrough credentials check")
312+
return fmt.Errorf("passthrough credentials check: %w", err)
311313
}
312314
if canPassthrough {
313315
return nil

pkg/asset/installconfig/aws/platform.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
survey "github.com/AlecAivazis/survey/v2"
99
"github.com/AlecAivazis/survey/v2/core"
10-
"github.com/pkg/errors"
1110
"github.com/sirupsen/logrus"
1211

1312
"github.com/openshift/installer/pkg/types/aws"
@@ -69,7 +68,7 @@ func Platform() (*aws.Platform, error) {
6968
choice := regionTransform(ans).(core.OptionAnswer).Value
7069
i := sort.SearchStrings(shortRegions, choice)
7170
if i == len(shortRegions) || shortRegions[i] != choice {
72-
return errors.Errorf("invalid region %q", choice)
71+
return fmt.Errorf("invalid region %q", choice)
7372
}
7473
return nil
7574
}),

pkg/asset/installconfig/aws/route53.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/aws/aws-sdk-go/aws/endpoints"
1010
awss "github.com/aws/aws-sdk-go/aws/session"
1111
"github.com/aws/aws-sdk-go/service/route53"
12-
"github.com/pkg/errors"
1312
"k8s.io/apimachinery/pkg/util/validation/field"
1413

1514
"github.com/openshift/installer/pkg/types"
@@ -46,7 +45,7 @@ func (c *Client) GetHostedZone(hostedZone string, cfg *aws.Config) (*route53.Get
4645
// validate that the hosted zone exists
4746
hostedZoneOutput, err := r53.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(hostedZone)})
4847
if err != nil {
49-
return nil, errors.Wrapf(err, "could not get hosted zone: %s", hostedZone)
48+
return nil, fmt.Errorf("could not get hosted zone: %s: %w", hostedZone, err)
5049
}
5150
return hostedZoneOutput, nil
5251
}
@@ -58,7 +57,7 @@ func (c *Client) ValidateZoneRecords(zone *route53.HostedZone, zoneName string,
5857
problematicRecords, err := c.GetSubDomainDNSRecords(zone, ic, cfg)
5958
if err != nil {
6059
allErrs = append(allErrs, field.InternalError(zonePath,
61-
errors.Wrapf(err, "could not list record sets for domain %q", zoneName)))
60+
fmt.Errorf("could not list record sets for domain %q: %w", zoneName, err)))
6261
}
6362

6463
if len(problematicRecords) > 0 {
@@ -79,7 +78,7 @@ func (c *Client) GetSubDomainDNSRecords(hostedZone *route53.HostedZone, ic *type
7978

8079
// validate that the domain of the hosted zone is the cluster domain or a parent of the cluster domain
8180
if !isHostedZoneDomainParentOfClusterDomain(hostedZone, dottedClusterDomain) {
82-
return nil, errors.Errorf("hosted zone domain %q is not a parent of the cluster domain %q", *hostedZone.Name, dottedClusterDomain)
81+
return nil, fmt.Errorf("hosted zone domain %q is not a parent of the cluster domain %q", *hostedZone.Name, dottedClusterDomain)
8382
}
8483

8584
r53 := route53.New(c.ssn, cfg)
@@ -132,7 +131,7 @@ func isHostedZoneDomainParentOfClusterDomain(hostedZone *route53.HostedZone, dot
132131
func (c *Client) GetBaseDomain(baseDomainName string) (*route53.HostedZone, error) {
133132
baseDomainZone, err := GetPublicZone(c.ssn, baseDomainName)
134133
if err != nil {
135-
return nil, errors.Wrapf(err, "could not find public zone: %s", baseDomainName)
134+
return nil, fmt.Errorf("could not find public zone: %s: %w", baseDomainName, err)
136135
}
137136
return baseDomainZone, nil
138137
}

0 commit comments

Comments
 (0)