Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 40 additions & 28 deletions pkg/asset/installconfig/aws/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,52 @@ func subnets(ctx context.Context, session *session.Session, region string, ids [
for _, id := range ids {
idPointers = append(idPointers, aws.String(id))
}
results, err := client.DescribeSubnetsWithContext( // FIXME: port to DescribeSubnetsPagesWithContext once we bump our vendored AWS package past v1.19.30

var lastError error
err = client.DescribeSubnetsPagesWithContext(
ctx,
&ec2.DescribeSubnetsInput{SubnetIds: idPointers},
func(results *ec2.DescribeSubnetsOutput, lastPage bool) bool {
for _, subnet := range results.Subnets {
if subnet.SubnetId == nil {
continue
}
if subnet.SubnetArn == nil {
lastError = errors.Errorf("%s has no ARN", *subnet.SubnetId)
return false
}
if subnet.VpcId == nil {
lastError = errors.Errorf("%s has no VPC", *subnet.SubnetId)
return false
}
if subnet.AvailabilityZone == nil {
lastError = errors.Errorf("%s has not availability zone", *subnet.SubnetId)
return false
}

if vpc == "" {
vpc = *subnet.VpcId
vpcFromSubnet = *subnet.SubnetId
} else if *subnet.VpcId != vpc {
lastError = errors.Errorf("all subnets must belong to the same VPC: %s is from %s, but %s is from %s", *subnet.SubnetId, *subnet.VpcId, vpcFromSubnet, vpc)
return false
}

metas[*subnet.SubnetId] = Subnet{
ARN: *subnet.SubnetArn,
Zone: *subnet.AvailabilityZone,
CIDR: *subnet.CidrBlock,
}
}
return !lastPage
},
)
if err == nil {
err = lastError
}
if err != nil {
return vpc, nil, nil, errors.Wrap(err, "describing subnets")
}
for _, subnet := range results.Subnets {
if subnet.SubnetId == nil {
continue
}
if subnet.SubnetArn == nil {
return vpc, nil, nil, errors.Errorf("%s has no ARN", *subnet.SubnetId)
}
if subnet.VpcId == nil {
return vpc, nil, nil, errors.Errorf("%s has no VPC", *subnet.SubnetId)
}
if subnet.AvailabilityZone == nil {
return vpc, nil, nil, errors.Errorf("%s has no availability zone", *subnet.SubnetId)
}

if vpc == "" {
vpc = *subnet.VpcId
vpcFromSubnet = *subnet.SubnetId
} else if *subnet.VpcId != vpc {
return vpc, nil, nil, errors.Errorf("all subnets must belong to the same VPC: %s is from %s, but %s is from %s", *subnet.SubnetId, *subnet.VpcId, vpcFromSubnet, vpc)
}

metas[*subnet.SubnetId] = Subnet{
ARN: *subnet.SubnetArn,
Zone: *subnet.AvailabilityZone,
CIDR: *subnet.CidrBlock,
}
}

var routeTables []*ec2.RouteTable
err = client.DescribeRouteTablesPagesWithContext(
Expand Down
35 changes: 18 additions & 17 deletions pkg/destroy/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,8 +1297,8 @@ func deleteEC2Subnet(ctx context.Context, client *ec2.EC2, id string, logger log
}

func deleteEC2SubnetsByVPC(ctx context.Context, client *ec2.EC2, vpc string, failFast bool, logger logrus.FieldLogger) error {
// FIXME: port to DescribeSubnetsPages once we bump our vendored AWS package past v1.19.30
results, err := client.DescribeSubnetsWithContext(
var lastError error
err := client.DescribeSubnetsPagesWithContext(
ctx,
&ec2.DescribeSubnetsInput{
Filters: []*ec2.Filter{
Expand All @@ -1308,26 +1308,27 @@ func deleteEC2SubnetsByVPC(ctx context.Context, client *ec2.EC2, vpc string, fai
},
},
},
func(results *ec2.DescribeSubnetsOutput, lastPage bool) bool {
for _, subnet := range results.Subnets {
err := deleteEC2Subnet(ctx, client, *subnet.SubnetId, logger.WithField("subnet", *subnet.SubnetId))
if err != nil {
err = errors.Wrapf(err, "deleting EC2 subnet %s", *subnet.SubnetId)
if lastError != nil {
logger.Debug(lastError)
}
lastError = err
if failFast {
return false
}
}
}
return !lastPage
},
)
if err != nil {
return err
}

var lastError error
for _, subnet := range results.Subnets {
err := deleteEC2Subnet(ctx, client, *subnet.SubnetId, logger.WithField("subnet", *subnet.SubnetId))
if err != nil {
err = errors.Wrapf(err, "deleting EC2 subnet %s", *subnet.SubnetId)
if failFast {
return err
}
if lastError != nil {
logger.Debug(lastError)
}
lastError = err
}
}

return lastError
}

Expand Down