@@ -165,36 +165,27 @@ func (i *AWSInfrastructure) AllocateAddress() AWSInfrastructure {
165
165
return * i
166
166
}
167
167
168
- t := 0
169
- addr , _ := GetAddress (i .Context , * aa .AllocationId )
170
- for addr == nil && t < 180 {
171
- time .Sleep (1 * time .Second )
168
+ var addr * ec2.Address
169
+ Eventually (func (gomega Gomega ) {
172
170
addr , _ = GetAddress (i .Context , * aa .AllocationId )
173
- t ++
174
- }
171
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed ())
175
172
i .ElasticIP = addr
176
173
return * i
177
174
}
178
175
179
176
func (i * AWSInfrastructure ) CreateNatGateway (ct string ) AWSInfrastructure {
180
- t := 0
181
- s , serr := GetSubnetByName (i .Context , i .Spec .ClusterName + "-subnet-" + ct )
182
- if serr != nil {
183
- return * i
184
- }
185
- for s == nil && t < 180 {
186
- time .Sleep (1 * time .Second )
177
+ var s * ec2.Subnet
178
+ Eventually (func (gomega Gomega ) {
187
179
s , _ = GetSubnetByName (i .Context , i .Spec .ClusterName + "-subnet-" + ct )
188
- t ++
189
- }
180
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed ())
190
181
if s == nil {
191
182
return * i
192
183
}
193
184
ngwC , ngwce := CreateNatGateway (i .Context , i .Spec .ClusterName + "-nat" , ct , * i .ElasticIP .AllocationId , * s .SubnetId )
194
185
if ngwce != nil {
195
186
return * i
196
187
}
197
- if WaitForNatGatewayState (i .Context , * ngwC .NatGatewayId , 180 , "available" ) {
188
+ if WaitForNatGatewayState (i .Context , * ngwC .NatGatewayId , "available" ) {
198
189
ngw , _ := GetNatGateway (i .Context , * ngwC .NatGatewayId )
199
190
i .NatGateway = ngw
200
191
i .State .NatGatewayState = ngw .State
@@ -238,6 +229,10 @@ func (i *AWSInfrastructure) GetRouteTable(rtID string) AWSInfrastructure {
238
229
// routes to their respective gateway.
239
230
func (i * AWSInfrastructure ) CreateInfrastructure () AWSInfrastructure {
240
231
i .CreateVPC ()
232
+ Eventually (func (gomega Gomega ) bool {
233
+ return * i .RefreshVPCState ().State .VpcState == "available"
234
+ }, 2 * time .Minute , 5 * time .Second ).Should (BeTrue ())
235
+
241
236
Byf ("Created VPC - %s" , * i .VPC .VpcId )
242
237
if i .VPC != nil {
243
238
i .CreatePublicSubnet ()
@@ -248,12 +243,6 @@ func (i *AWSInfrastructure) CreateInfrastructure() AWSInfrastructure {
248
243
if i .State .PrivateSubnetID != nil {
249
244
Byf ("Created Private Subnet - %s" , * i .State .PrivateSubnetID )
250
245
}
251
- for t := 0 ; t < 30 ; t ++ {
252
- if * i .RefreshVPCState ().State .VpcState == "available" {
253
- break
254
- }
255
- time .Sleep (1 * time .Second )
256
- }
257
246
i .CreateInternetGateway ()
258
247
if i .InternetGateway != nil {
259
248
Byf ("Created Internet Gateway - %s" , * i .InternetGateway .InternetGatewayId )
@@ -264,7 +253,7 @@ func (i *AWSInfrastructure) CreateInfrastructure() AWSInfrastructure {
264
253
Byf ("Created Elastic IP - %s" , * i .ElasticIP .AllocationId )
265
254
i .CreateNatGateway ("public" )
266
255
if i .NatGateway != nil && i .NatGateway .NatGatewayId != nil {
267
- WaitForNatGatewayState (i .Context , * i .NatGateway .NatGatewayId , 180 , "available" )
256
+ WaitForNatGatewayState (i .Context , * i .NatGateway .NatGatewayId , "available" )
268
257
Byf ("Created NAT Gateway - %s" , * i .NatGateway .NatGatewayId )
269
258
}
270
259
}
@@ -304,7 +293,7 @@ func (i *AWSInfrastructure) DeleteInfrastructure() {
304
293
Byf ("Deleting orphaned instance: %s - %v" , * instance .InstanceId , TerminateInstance (i .Context , * instance .InstanceId ))
305
294
}
306
295
}
307
- WaitForInstanceState (i .Context , i .Spec .ClusterName , 300 , "terminated" )
296
+ WaitForInstanceState (i .Context , i .Spec .ClusterName , "terminated" )
308
297
309
298
loadbalancers , _ := ListLoadBalancers (i .Context , i .Spec .ClusterName )
310
299
for _ , lb := range loadbalancers {
@@ -320,7 +309,7 @@ func (i *AWSInfrastructure) DeleteInfrastructure() {
320
309
321
310
if i .NatGateway != nil {
322
311
Byf ("Deleting NAT Gateway - %s - %v" , * i .NatGateway .NatGatewayId , DeleteNatGateway (i .Context , * i .NatGateway .NatGatewayId ))
323
- WaitForNatGatewayState (i .Context , * i .NatGateway .NatGatewayId , 180 , "deleted" )
312
+ WaitForNatGatewayState (i .Context , * i .NatGateway .NatGatewayId , "deleted" )
324
313
}
325
314
326
315
if i .ElasticIP != nil {
@@ -1010,9 +999,8 @@ func ListClusterEC2Instances(e2eCtx *E2EContext, clusterName string) ([]*ec2.Ins
1010
999
return instances , nil
1011
1000
}
1012
1001
1013
- func WaitForInstanceState (e2eCtx * E2EContext , clusterName string , timeout int , state string ) bool {
1014
- t := 0
1015
- for t < timeout {
1002
+ func WaitForInstanceState (e2eCtx * E2EContext , clusterName string , state string ) bool {
1003
+ Eventually (func (gomega Gomega ) bool {
1016
1004
st := map [string ]int {
1017
1005
"pending" : 0 ,
1018
1006
"running" : 0 ,
@@ -1027,9 +1015,9 @@ func WaitForInstanceState(e2eCtx *E2EContext, clusterName string, timeout int, s
1027
1015
if st [state ] == len (instances ) || len (instances ) == 0 {
1028
1016
return true
1029
1017
}
1030
- time . Sleep ( 1 * time . Second )
1031
- t ++
1032
- }
1018
+ return false
1019
+ }, 5 * time . Minute , 5 * time . Second ). Should ( BeTrue ())
1020
+
1033
1021
return false
1034
1022
}
1035
1023
@@ -1417,17 +1405,12 @@ func DeleteNatGateway(e2eCtx *E2EContext, gatewayID string) bool {
1417
1405
return true
1418
1406
}
1419
1407
1420
- func WaitForNatGatewayState (e2eCtx * E2EContext , gatewayID string , timeout int , state string ) bool {
1421
- t := 0
1422
- for t < timeout {
1408
+ func WaitForNatGatewayState (e2eCtx * E2EContext , gatewayID string , state string ) bool {
1409
+ Eventually (func (gomega Gomega ) bool {
1423
1410
gw , _ := GetNatGateway (e2eCtx , gatewayID )
1424
1411
gwState := * gw .State
1425
- if gwState == state {
1426
- return true
1427
- }
1428
- time .Sleep (1 * time .Second )
1429
- t ++
1430
- }
1412
+ return gwState == state
1413
+ }, 3 * time .Minute , 5 * time .Second ).Should (BeTrue ())
1431
1414
return false
1432
1415
}
1433
1416
0 commit comments