Skip to content

Commit 9978285

Browse files
Merge pull request openshift#7983 from mtulio/aws-byoip
SPLAT-1434: aws: add support of BYO public ipv4 pool
2 parents d8a8d2b + 1fc258e commit 9978285

File tree

15 files changed

+187
-2
lines changed

15 files changed

+187
-2
lines changed

data/data/aws/bootstrap/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,11 @@ resource "aws_security_group_rule" "bootstrap_journald_gateway" {
249249
from_port = 19531
250250
to_port = 19531
251251
}
252+
253+
resource "aws_eip" "bootstrap" {
254+
domain = "vpc"
255+
instance = aws_instance.bootstrap.id
256+
public_ipv4_pool = var.aws_public_ipv4_pool == "" ? null : var.aws_public_ipv4_pool
257+
258+
depends_on = [aws_instance.bootstrap]
259+
}

data/data/aws/cluster/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ module "vpc" {
109109
edge_parent_gw_map = var.aws_edge_parent_zones_index
110110
edge_zones_type = var.aws_edge_zones_type
111111

112+
public_ipv4_pool = var.aws_public_ipv4_pool
113+
112114
tags = local.tags
113115
}
114116

data/data/aws/cluster/vpc/master-elb.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ resource "aws_lb" "api_external" {
2424

2525
name = "${var.cluster_id}-ext"
2626
load_balancer_type = "network"
27-
subnets = data.aws_subnet.public.*.id
2827
internal = false
2928
enable_cross_zone_load_balancing = true
3029

30+
dynamic "subnet_mapping" {
31+
for_each = range(length(data.aws_subnet.public))
32+
33+
content {
34+
subnet_id = data.aws_subnet.public[subnet_mapping.key].id
35+
allocation_id = aws_eip.api_nlb_public[subnet_mapping.key].id
36+
}
37+
}
38+
3139
tags = merge(
3240
{
3341
"Name" = "${var.cluster_id}-ext"
@@ -38,7 +46,24 @@ resource "aws_lb" "api_external" {
3846
timeouts {
3947
create = "20m"
4048
}
49+
}
50+
51+
resource "aws_eip" "api_nlb_public" {
52+
count = length(var.availability_zones)
53+
domain = "vpc"
54+
55+
public_ipv4_pool = var.public_ipv4_pool == "" ? null : var.public_ipv4_pool
56+
57+
tags = merge(
58+
{
59+
"Name" = "${var.cluster_id}-eip-${var.availability_zones[count.index]}-lb-api"
60+
},
61+
var.tags,
62+
)
4163

64+
# Terraform does not declare an explicit dependency towards the internet gateway.
65+
# this can cause the internet gateway to be deleted/detached before the EIPs.
66+
# https://github.com/coreos/tectonic-installer/issues/1017#issuecomment-307780549
4267
depends_on = [aws_internet_gateway.igw]
4368
}
4469

data/data/aws/cluster/vpc/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ variable "public_subnets" {
5959
variable "private_subnets" {
6060
type = list(string)
6161
description = "Existing private subnets into which the cluster should be installed."
62+
}
63+
64+
variable "public_ipv4_pool" {
65+
type = string
66+
description = "An Public IPv4 Pool"
6267
}

data/data/aws/cluster/vpc/vpc-public.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ resource "aws_eip" "nat_eip" {
9595
count = var.public_subnets == null ? length(var.availability_zones) : 0
9696
vpc = true
9797

98+
public_ipv4_pool = var.public_ipv4_pool == "" ? null : var.public_ipv4_pool
99+
98100
tags = merge(
99101
{
100102
"Name" = "${var.cluster_id}-eip-${var.availability_zones[count.index]}"

data/data/aws/variables-aws.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,16 @@ a Public Route Table and the default route entry pointing to the carrier gateway
226226
227227
Example: `{ "us-east-1-nyc-1a"=local-zone, "us-east-1-wl1-nyc-wlz-1"=wavelength-zone }`
228228
EOF
229-
}
229+
}
230+
231+
variable "aws_public_ipv4_pool" {
232+
type = string
233+
234+
description = <<EOF
235+
(optional) Indicates the installation process to use Public IPv4 address
236+
that you bring to your AWS account with BYOIP to create resources which consumes
237+
Elastic IPs when the publish strategy is External.
238+
EOF
239+
240+
default = ""
241+
}

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,11 @@ spec:
22872287
operators to include the specified user tags in the tags of
22882288
the AWS resources that the operators create.
22892289
type: boolean
2290+
publicIpv4Pool:
2291+
description: PublicIpv4Pool is an optional field that can be used
2292+
to tell the installation process to use Public IPv4 address
2293+
that you bring to your AWS account with BYOIP.
2294+
type: string
22902295
region:
22912296
description: Region specifies the AWS region where the cluster
22922297
will be created.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Install OpenShift on AWS using custom/owned Public IPv4 Pool
2+
3+
Steps to create a cluster on AWS using Public IPv4 address pool
4+
that you bring to your AWS account with BYOIP.
5+
6+
## Prerequisites
7+
8+
- Public IPv4 Pool Provisioned in the Account
9+
- Total of ( (Zones*3 ) + 1) of Public IPv4 available in the pool, where: Zones is the total numbber of AWS zones used to deploy the OpenShift cluster.
10+
- Example to query the IPv4 pools available in the account, which returns the `TotalAvailableAddressCount`:
11+
```
12+
aws ec2 describe-public-ipv4-pools --region us-east-1
13+
```
14+
15+
## Steps
16+
17+
- Create the install config setting the field `platform.aws.publicIpv4PoolId`, and create the cluster:
18+
19+
```yaml
20+
apiVersion: v1
21+
baseDomain: ${CLUSTER_BASE_DOMAIN}
22+
metadata:
23+
name: ocp-byoip
24+
platform:
25+
aws:
26+
region: ${REGION}
27+
publicIpv4Pool: ipv4pool-ec2-123456789abcde
28+
publish: External
29+
pullSecret: '...'
30+
sshKey: |
31+
'...'
32+
```
33+
34+
- Create the cluster
35+
36+
```sh
37+
openshift-install create cluster
38+
```

pkg/asset/cluster/tfvars/tfvars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
333333
Proxy: installConfig.Config.Proxy,
334334
PreserveBootstrapIgnition: installConfig.Config.AWS.PreserveBootstrapIgnition,
335335
MasterSecurityGroups: securityGroups,
336+
PublicIpv4Pool: installConfig.Config.AWS.PublicIpv4Pool,
336337
})
337338
if err != nil {
338339
return errors.Wrapf(err, "failed to get %s Terraform variables", platform)

pkg/asset/installconfig/aws/ec2.go

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

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

78
"github.com/aws/aws-sdk-go/aws"
@@ -28,3 +29,24 @@ func DescribeSecurityGroups(ctx context.Context, session *session.Session, secur
2829
}
2930
return sgOutput.SecurityGroups, nil
3031
}
32+
33+
// DescribePublicIpv4Pool returns the ec2 public IPv4 Pool attributes from the given ID.
34+
func DescribePublicIpv4Pool(ctx context.Context, session *session.Session, region string, poolID string) (*ec2.PublicIpv4Pool, error) {
35+
client := ec2.New(session, aws.NewConfig().WithRegion(region))
36+
37+
cctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
38+
defer cancel()
39+
40+
poolOutputs, err := client.DescribePublicIpv4PoolsWithContext(cctx, &ec2.DescribePublicIpv4PoolsInput{PoolIds: []*string{aws.String(poolID)}})
41+
if err != nil {
42+
return nil, err
43+
}
44+
if len(poolOutputs.PublicIpv4Pools) == 0 {
45+
return nil, fmt.Errorf("public IPv4 Pool not found: %s", poolID)
46+
}
47+
// it should not happen
48+
if len(poolOutputs.PublicIpv4Pools) > 1 {
49+
return nil, fmt.Errorf("more than one Public IPv4 Pool: %s", poolID)
50+
}
51+
return poolOutputs.PublicIpv4Pools[0], nil
52+
}

0 commit comments

Comments
 (0)