@@ -301,6 +301,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
301
301
asgSvc .EXPECT ().GetASGByName (gomock .Any ()).Return (& expinfrav1.AutoScalingGroup {
302
302
Name : "name" ,
303
303
}, nil )
304
+ asgSvc .EXPECT ().SubnetIDs (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
304
305
asgSvc .EXPECT ().UpdateASG (gomock .Any ()).Return (nil ).AnyTimes ()
305
306
asgSvc .EXPECT ().SuspendProcesses ("name" , gomock .InAnyOrder ([]string {
306
307
"ScheduledActions" ,
@@ -341,6 +342,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
341
342
Name : "name" ,
342
343
CurrentlySuspendProcesses : []string {"Launch" , "process3" },
343
344
}, nil )
345
+ asgSvc .EXPECT ().SubnetIDs (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
344
346
asgSvc .EXPECT ().UpdateASG (gomock .Any ()).Return (nil ).AnyTimes ()
345
347
asgSvc .EXPECT ().SuspendProcesses ("name" , []string {"Terminate" }).Return (nil ).AnyTimes ().Times (1 )
346
348
asgSvc .EXPECT ().ResumeProcesses ("name" , []string {"process3" }).Return (nil ).AnyTimes ().Times (1 )
@@ -360,6 +362,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
360
362
DesiredCapacity : pointer .Int32 (1 ),
361
363
}
362
364
asgSvc .EXPECT ().GetASGByName (gomock .Any ()).Return (& asg , nil ).AnyTimes ()
365
+ asgSvc .EXPECT ().SubnetIDs (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
363
366
asgSvc .EXPECT ().UpdateASG (gomock .Any ()).Return (nil ).AnyTimes ()
364
367
ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Any ()).Return (nil , "" , nil ).AnyTimes ()
365
368
ec2Svc .EXPECT ().DiscoverLaunchTemplateAMI (gomock .Any ()).Return (nil , nil ).AnyTimes ()
@@ -377,6 +380,60 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
377
380
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs )
378
381
g .Expect (* ms .MachinePool .Spec .Replicas ).To (Equal (int32 (1 )))
379
382
})
383
+ t .Run ("No need to update Asg because asgNeedsUpdates is false and no subnets change" , func (t * testing.T ) {
384
+ g := NewWithT (t )
385
+ setup (t , g )
386
+ defer teardown (t , g )
387
+
388
+ asg := expinfrav1.AutoScalingGroup {
389
+ MinSize : int32 (0 ),
390
+ MaxSize : int32 (1 ),
391
+ Subnets : []string {"subnet1" , "subnet2" }}
392
+ ec2Svc .EXPECT ().ReconcileLaunchTemplate (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
393
+ ec2Svc .EXPECT ().ReconcileTags (gomock .Any (), gomock .Any ()).Return (nil )
394
+ asgSvc .EXPECT ().GetASGByName (gomock .Any ()).Return (& asg , nil ).AnyTimes ()
395
+ asgSvc .EXPECT ().SubnetIDs (gomock .Any ()).Return ([]string {"subnet2" , "subnet1" }, nil ).Times (1 )
396
+ asgSvc .EXPECT ().UpdateASG (gomock .Any ()).Return (nil ).Times (0 )
397
+
398
+ _ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs )
399
+ g .Expect (err ).To (Succeed ())
400
+ })
401
+ t .Run ("update Asg due to subnet changes" , func (t * testing.T ) {
402
+ g := NewWithT (t )
403
+ setup (t , g )
404
+ defer teardown (t , g )
405
+
406
+ asg := expinfrav1.AutoScalingGroup {
407
+ MinSize : int32 (0 ),
408
+ MaxSize : int32 (1 ),
409
+ Subnets : []string {"subnet1" , "subnet2" }}
410
+ ec2Svc .EXPECT ().ReconcileLaunchTemplate (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
411
+ ec2Svc .EXPECT ().ReconcileTags (gomock .Any (), gomock .Any ()).Return (nil )
412
+ asgSvc .EXPECT ().GetASGByName (gomock .Any ()).Return (& asg , nil ).AnyTimes ()
413
+ asgSvc .EXPECT ().SubnetIDs (gomock .Any ()).Return ([]string {"subnet1" }, nil ).Times (1 )
414
+ asgSvc .EXPECT ().UpdateASG (gomock .Any ()).Return (nil ).Times (1 )
415
+
416
+ _ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs )
417
+ g .Expect (err ).To (Succeed ())
418
+ })
419
+ t .Run ("update Asg due to asgNeedsUpdates returns true" , func (t * testing.T ) {
420
+ g := NewWithT (t )
421
+ setup (t , g )
422
+ defer teardown (t , g )
423
+
424
+ asg := expinfrav1.AutoScalingGroup {
425
+ MinSize : int32 (0 ),
426
+ MaxSize : int32 (2 ),
427
+ Subnets : []string {}}
428
+ ec2Svc .EXPECT ().ReconcileLaunchTemplate (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
429
+ ec2Svc .EXPECT ().ReconcileTags (gomock .Any (), gomock .Any ()).Return (nil )
430
+ asgSvc .EXPECT ().GetASGByName (gomock .Any ()).Return (& asg , nil ).AnyTimes ()
431
+ asgSvc .EXPECT ().SubnetIDs (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
432
+ asgSvc .EXPECT ().UpdateASG (gomock .Any ()).Return (nil ).Times (1 )
433
+
434
+ _ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs )
435
+ g .Expect (err ).To (Succeed ())
436
+ })
380
437
})
381
438
382
439
t .Run ("Deleting an AWSMachinePool" , func (t * testing.T ) {
0 commit comments