@@ -472,15 +472,15 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
472
472
})
473
473
474
474
t .Run ("ReconcileLaunchTemplate not mocked" , func (t * testing.T ) {
475
- g := NewWithT (t )
476
- setup (t , g )
477
- reconciler .reconcileServiceFactory = nil // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`)
478
- reconSvc = nil // not used
479
- defer teardown (t , g )
480
-
481
475
launchTemplateIDExisting := "lt-existing"
482
476
483
477
t .Run ("nothing exists, so launch template and ASG must be created" , func (t * testing.T ) {
478
+ g := NewWithT (t )
479
+ setup (t , g )
480
+ reconciler .reconcileServiceFactory = nil // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`)
481
+ reconSvc = nil // not used
482
+ defer teardown (t , g )
483
+
484
484
ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Eq ("test" )).Return (nil , "" , nil , nil )
485
485
ec2Svc .EXPECT ().DiscoverLaunchTemplateAMI (gomock .Any ()).Return (ptr.To [string ]("ami-abcdef123" ), nil )
486
486
ec2Svc .EXPECT ().CreateLaunchTemplate (gomock .Any (), gomock .Eq (ptr.To [string ]("ami-abcdef123" )), gomock .Eq (userDataSecretKey ), gomock .Eq ([]byte ("shell-script" ))).Return ("lt-ghijkl456" , nil )
@@ -497,6 +497,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
497
497
})
498
498
499
499
t .Run ("launch template and ASG exist and need no update" , func (t * testing.T ) {
500
+ g := NewWithT (t )
501
+ setup (t , g )
502
+ reconciler .reconcileServiceFactory = nil // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`)
503
+ reconSvc = nil // not used
504
+ defer teardown (t , g )
505
+
500
506
// Latest ID and version already stored, no need to retrieve it
501
507
ms .AWSMachinePool .Status .LaunchTemplateID = launchTemplateIDExisting
502
508
ms .AWSMachinePool .Status .LaunchTemplateVersion = ptr.To [string ]("1" )
@@ -538,6 +544,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
538
544
})
539
545
540
546
t .Run ("launch template and ASG exist and only AMI ID changed" , func (t * testing.T ) {
547
+ g := NewWithT (t )
548
+ setup (t , g )
549
+ reconciler .reconcileServiceFactory = nil // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`)
550
+ reconSvc = nil // not used
551
+ defer teardown (t , g )
552
+
541
553
// Latest ID and version already stored, no need to retrieve it
542
554
ms .AWSMachinePool .Status .LaunchTemplateID = launchTemplateIDExisting
543
555
ms .AWSMachinePool .Status .LaunchTemplateVersion = ptr.To [string ]("1" )
@@ -585,6 +597,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
585
597
})
586
598
587
599
t .Run ("launch template and ASG exist and only bootstrap data secret name changed" , func (t * testing.T ) {
600
+ g := NewWithT (t )
601
+ setup (t , g )
602
+ reconciler .reconcileServiceFactory = nil // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`)
603
+ reconSvc = nil // not used
604
+ defer teardown (t , g )
605
+
588
606
// Latest ID and version already stored, no need to retrieve it
589
607
ms .AWSMachinePool .Status .LaunchTemplateID = launchTemplateIDExisting
590
608
ms .AWSMachinePool .Status .LaunchTemplateVersion = ptr.To [string ]("1" )
@@ -635,6 +653,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
635
653
})
636
654
637
655
t .Run ("launch template and ASG created from zero, then bootstrap config reference changes" , func (t * testing.T ) {
656
+ g := NewWithT (t )
657
+ setup (t , g )
658
+ reconciler .reconcileServiceFactory = nil // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`)
659
+ reconSvc = nil // not used
660
+ defer teardown (t , g )
661
+
638
662
ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Eq ("test" )).Return (nil , "" , nil , nil )
639
663
ec2Svc .EXPECT ().DiscoverLaunchTemplateAMI (gomock .Any ()).Return (ptr.To [string ]("ami-abcdef123" ), nil )
640
664
ec2Svc .EXPECT ().CreateLaunchTemplate (gomock .Any (), gomock .Eq (ptr.To [string ]("ami-abcdef123" )), gomock .Eq (userDataSecretKey ), gomock .Eq ([]byte ("shell-script" ))).Return ("lt-ghijkl456" , nil )
@@ -650,7 +674,6 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
650
674
g .Expect (err ).To (Succeed ())
651
675
652
676
g .Expect (ms .AWSMachinePool .Status .LaunchTemplateID ).ToNot (BeEmpty ())
653
- g .Expect (ptr .Deref [string ](ms .AWSMachinePool .Status .LaunchTemplateVersion , "" )).ToNot (BeEmpty ())
654
677
655
678
// Data secret name changes
656
679
newBootstrapSecret := & corev1.Secret {
@@ -665,6 +688,10 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
665
688
g .Expect (testEnv .Create (ctx , newBootstrapSecret )).To (Succeed ())
666
689
ms .MachinePool .Spec .Template .Spec .Bootstrap .DataSecretName = ptr.To [string ](newBootstrapSecret .Name )
667
690
691
+ // Since `AWSMachinePool.status.launchTemplateVersion` isn't set yet,
692
+ // the controller will ask for the current version and then set the status.
693
+ ec2Svc .EXPECT ().GetLaunchTemplateLatestVersion (gomock .Any ()).Return ("1" , nil )
694
+
668
695
ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Eq ("test" )).Return (
669
696
& expinfrav1.AWSLaunchTemplate {
670
697
Name : "test" ,
0 commit comments