Skip to content

Commit ae14c50

Browse files
authored
Merge pull request #3471 from josh-ferrell/e2e_createnatgateway_fix
[E2E] Add retry and timeout to GetSubnetByName in CreateNatGateway
2 parents 913ee94 + e89315c commit ae14c50

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

test/e2e/shared/aws.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (i *AWSInfrastructure) AllocateAddress() AWSInfrastructure {
167167

168168
t := 0
169169
addr, _ := GetAddress(i.Context, *aa.AllocationId)
170-
for addr == nil || t < 180 {
170+
for addr == nil && t < 180 {
171171
time.Sleep(1 * time.Second)
172172
addr, _ = GetAddress(i.Context, *aa.AllocationId)
173173
t++
@@ -177,10 +177,19 @@ func (i *AWSInfrastructure) AllocateAddress() AWSInfrastructure {
177177
}
178178

179179
func (i *AWSInfrastructure) CreateNatGateway(ct string) AWSInfrastructure {
180+
t := 0
180181
s, serr := GetSubnetByName(i.Context, i.Spec.ClusterName+"-subnet-"+ct)
181182
if serr != nil {
182183
return *i
183184
}
185+
for s == nil && t < 180 {
186+
time.Sleep(1 * time.Second)
187+
s, _ = GetSubnetByName(i.Context, i.Spec.ClusterName+"-subnet-"+ct)
188+
t++
189+
}
190+
if s == nil {
191+
return *i
192+
}
184193
ngwC, ngwce := CreateNatGateway(i.Context, i.Spec.ClusterName+"-nat", ct, *i.ElasticIP.AllocationId, *s.SubnetId)
185194
if ngwce != nil {
186195
return *i
@@ -229,27 +238,45 @@ func (i *AWSInfrastructure) GetRouteTable(rtID string) AWSInfrastructure {
229238
// routes to their respective gateway.
230239
func (i *AWSInfrastructure) CreateInfrastructure() AWSInfrastructure {
231240
i.CreateVPC()
241+
Byf("Created VPC - %s", *i.VPC.VpcId)
232242
if i.VPC != nil {
233243
i.CreatePublicSubnet()
244+
if i.State.PublicSubnetID != nil {
245+
Byf("Created Public Subnet - %s", *i.State.PublicSubnetID)
246+
}
234247
i.CreatePrivateSubnet()
248+
if i.State.PrivateSubnetID != nil {
249+
Byf("Created Private Subnet - %s", *i.State.PrivateSubnetID)
250+
}
235251
for t := 0; t < 30; t++ {
236252
if *i.RefreshVPCState().State.VpcState == "available" {
237253
break
238254
}
239255
time.Sleep(1 * time.Second)
240256
}
241257
i.CreateInternetGateway()
258+
if i.InternetGateway != nil {
259+
Byf("Created Internet Gateway - %s", *i.InternetGateway.InternetGatewayId)
260+
}
242261
}
243262
i.AllocateAddress()
244263
if i.ElasticIP != nil && i.ElasticIP.AllocationId != nil {
264+
Byf("Created Elastic IP - %s", *i.ElasticIP.AllocationId)
245265
i.CreateNatGateway("public")
246266
if i.NatGateway != nil && i.NatGateway.NatGatewayId != nil {
247267
WaitForNatGatewayState(i.Context, *i.NatGateway.NatGatewayId, 180, "available")
268+
Byf("Created NAT Gateway - %s", *i.NatGateway.NatGatewayId)
248269
}
249270
}
250271
if len(i.Subnets) == 2 {
251272
i.CreateRouteTable("public")
273+
if i.State.PublicRouteTableID != nil {
274+
Byf("Created public route table - %s", *i.State.PublicRouteTableID)
275+
}
252276
i.CreateRouteTable("private")
277+
if i.State.PrivateRouteTableID != nil {
278+
Byf("Created private route table - %s", *i.State.PrivateRouteTableID)
279+
}
253280
if i.InternetGateway != nil && i.InternetGateway.InternetGatewayId != nil {
254281
CreateRoute(i.Context, *i.State.PublicRouteTableID, "0.0.0.0/0", nil, i.InternetGateway.InternetGatewayId, nil)
255282
}

0 commit comments

Comments
 (0)