Skip to content

Commit ad6c085

Browse files
plural up shouldn't choke on availability zones missing
This is no longer even used, and apparently can cause some weird interactions w/ --ignore-preflights
1 parent 520f5a0 commit ad6c085

File tree

1 file changed

+3
-79
lines changed

1 file changed

+3
-79
lines changed

pkg/provider/aws.go

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8-
"sort"
98
"strings"
109

1110
"github.com/AlecAivazis/survey/v2"
@@ -113,32 +112,21 @@ func mkAWS(conf config.Config) (provider *AWSProvider, err error) {
113112
return
114113
}
115114

116-
account, err := GetAwsAccount(ctx)
117-
if err != nil {
118-
err = plrlErrors.ErrorWrap(err, "Failed to get aws account (is your aws cli configured?)")
119-
return
120-
}
121-
122-
if len(account) == 0 {
115+
provider.project = lo.FromPtr(callerIdentity.Account)
116+
if len(provider.project) == 0 {
123117
err = plrlErrors.ErrorWrap(fmt.Errorf("unable to find AWS account ID, make sure that your AWS CLI is configured"), "AWS cli error:")
124118
return
125119
}
126120

127-
provider.project = account
128121
provider.storageClient = client
129122

130-
azones, err := getAvailabilityZones(ctx, provider.Region())
131-
if err != nil {
132-
return
133-
}
134-
135123
projectManifest := manifest.ProjectManifest{
136124
Cluster: provider.Cluster(),
137125
Project: provider.Project(),
138126
Provider: api.ProviderAWS,
139127
Region: provider.Region(),
140128
Context: provider.Context(),
141-
AvailabilityZones: azones,
129+
AvailabilityZones: []string{},
142130
Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint},
143131
}
144132

@@ -167,56 +155,6 @@ func getClient(region string, context context.Context) (*s3.Client, error) {
167155
return s3.NewFromConfig(cfg), nil
168156
}
169157

170-
func getEC2Client(ctx context.Context, region string) (*ec2.Client, error) {
171-
cfg, err := awsConfig.LoadDefaultConfig(ctx)
172-
if err != nil {
173-
return nil, err
174-
}
175-
cfg.Region = region
176-
return ec2.NewFromConfig(cfg), nil
177-
}
178-
179-
func getAvailabilityZones(ctx context.Context, region string) ([]string, error) {
180-
return fetchAZ(ctx, region, true)
181-
}
182-
183-
func fetchAZ(context context.Context, region string, sorted bool) ([]string, error) {
184-
ec2Client, err := getEC2Client(context, region)
185-
if err != nil {
186-
return nil, err
187-
}
188-
allAvailabilityZones := true
189-
dryRun := false
190-
regionName := "region-name"
191-
azones, err := ec2Client.DescribeAvailabilityZones(context, &ec2.DescribeAvailabilityZonesInput{
192-
AllAvailabilityZones: &allAvailabilityZones,
193-
DryRun: &dryRun,
194-
Filters: []ec2Types.Filter{
195-
{
196-
Name: &regionName,
197-
Values: []string{region},
198-
},
199-
},
200-
})
201-
if err != nil {
202-
return nil, err
203-
}
204-
result := []string{}
205-
for _, az := range azones.AvailabilityZones {
206-
if az.ParentZoneId == nil {
207-
result = append(result, *az.ZoneName)
208-
}
209-
}
210-
// append when there are fewer zones than 3
211-
for i := 0; (3 - len(result)) > 0; i++ {
212-
result = append(result, result[i])
213-
}
214-
if sorted {
215-
sort.Strings(result)
216-
}
217-
return result, nil
218-
}
219-
220158
func getAwsConfig(ctx context.Context) (aws.Config, error) {
221159
cfg, err := awsConfig.LoadDefaultConfig(ctx)
222160
return cfg, plrlErrors.ErrorWrap(err, "Failed to initialize aws client: ")
@@ -334,20 +272,6 @@ func (prov *AWSProvider) Decommision(node *v1.Node) error {
334272
return plrlErrors.ErrorWrap(err, "failed to terminate instance")
335273
}
336274

337-
func GetAwsAccount(ctx context.Context) (string, error) {
338-
cfg, err := getAwsConfig(ctx)
339-
if err != nil {
340-
return "", err
341-
}
342-
svc := sts.NewFromConfig(cfg)
343-
result, err := svc.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
344-
if err != nil {
345-
return "", plrlErrors.ErrorWrap(err, "Error finding iam identity: ")
346-
}
347-
348-
return *result.Account, nil
349-
}
350-
351275
func ValidateAWSDomainRegistration(ctx context.Context, domain, region string) error {
352276
cfg, err := getAwsConfig(ctx)
353277
if err != nil {

0 commit comments

Comments
 (0)