@@ -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 {
@@ -1009,9 +998,8 @@ func ListClusterEC2Instances(e2eCtx *E2EContext, clusterName string) ([]*ec2.Ins
1009
998
return instances , nil
1010
999
}
1011
1000
1012
- func WaitForInstanceState (e2eCtx * E2EContext , clusterName string , timeout int , state string ) bool {
1013
- t := 0
1014
- for t < timeout {
1001
+ func WaitForInstanceState (e2eCtx * E2EContext , clusterName string , state string ) bool {
1002
+ Eventually (func (gomega Gomega ) bool {
1015
1003
st := map [string ]int {
1016
1004
"pending" : 0 ,
1017
1005
"running" : 0 ,
@@ -1026,9 +1014,9 @@ func WaitForInstanceState(e2eCtx *E2EContext, clusterName string, timeout int, s
1026
1014
if st [state ] == len (instances ) || len (instances ) == 0 {
1027
1015
return true
1028
1016
}
1029
- time . Sleep ( 1 * time . Second )
1030
- t ++
1031
- }
1017
+ return false
1018
+ }, 5 * time . Minute , 5 * time . Second ). Should ( BeTrue ())
1019
+
1032
1020
return false
1033
1021
}
1034
1022
@@ -1416,17 +1404,12 @@ func DeleteNatGateway(e2eCtx *E2EContext, gatewayID string) bool {
1416
1404
return true
1417
1405
}
1418
1406
1419
- func WaitForNatGatewayState (e2eCtx * E2EContext , gatewayID string , timeout int , state string ) bool {
1420
- t := 0
1421
- for t < timeout {
1407
+ func WaitForNatGatewayState (e2eCtx * E2EContext , gatewayID string , state string ) bool {
1408
+ Eventually (func (gomega Gomega ) bool {
1422
1409
gw , _ := GetNatGateway (e2eCtx , gatewayID )
1423
1410
gwState := * gw .State
1424
- if gwState == state {
1425
- return true
1426
- }
1427
- time .Sleep (1 * time .Second )
1428
- t ++
1429
- }
1411
+ return gwState == state
1412
+ }, 3 * time .Minute , 5 * time .Second ).Should (BeTrue ())
1430
1413
return false
1431
1414
}
1432
1415
0 commit comments