@@ -440,6 +440,20 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
440
440
want bool
441
441
wantErr bool
442
442
}{
443
+ {
444
+ name : "only core security groups, order shouldn't matter" ,
445
+ incoming : & expinfrav1.AWSLaunchTemplate {
446
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {},
447
+ },
448
+ existing : & expinfrav1.AWSLaunchTemplate {
449
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
450
+ {ID : aws .String ("sg-222" )},
451
+ {ID : aws .String ("sg-111" )},
452
+ },
453
+ },
454
+ want : false ,
455
+ wantErr : false ,
456
+ },
443
457
{
444
458
name : "the same security groups" ,
445
459
incoming : & expinfrav1.AWSLaunchTemplate {
@@ -497,6 +511,10 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
497
511
IamInstanceProfile : DefaultAmiNameFormat ,
498
512
},
499
513
existing : & expinfrav1.AWSLaunchTemplate {
514
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
515
+ {ID : aws .String ("sg-111" )},
516
+ {ID : aws .String ("sg-222" )},
517
+ },
500
518
IamInstanceProfile : "some-other-profile" ,
501
519
},
502
520
want : true ,
@@ -507,6 +525,10 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
507
525
InstanceType : "t3.micro" ,
508
526
},
509
527
existing : & expinfrav1.AWSLaunchTemplate {
528
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
529
+ {ID : aws .String ("sg-111" )},
530
+ {ID : aws .String ("sg-222" )},
531
+ },
510
532
InstanceType : "t3.large" ,
511
533
},
512
534
want : true ,
@@ -540,9 +562,14 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
540
562
HTTPTokens : infrav1 .HTTPTokensStateRequired ,
541
563
},
542
564
},
543
- existing : & expinfrav1.AWSLaunchTemplate {},
544
- want : true ,
545
- wantErr : false ,
565
+ existing : & expinfrav1.AWSLaunchTemplate {
566
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
567
+ {ID : aws .String ("sg-111" )},
568
+ {ID : aws .String ("sg-222" )},
569
+ },
570
+ },
571
+ want : true ,
572
+ wantErr : false ,
546
573
},
547
574
{
548
575
name : "new launch template instance metadata options, removing IMDSv2 requirement" ,
@@ -556,6 +583,59 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
556
583
want : true ,
557
584
wantErr : false ,
558
585
},
586
+ {
587
+ name : "Should return true if incoming SpotMarketOptions is different from existing SpotMarketOptions" ,
588
+ incoming : & expinfrav1.AWSLaunchTemplate {
589
+ SpotMarketOptions : & infrav1.SpotMarketOptions {
590
+ MaxPrice : aws .String ("0.10" ),
591
+ },
592
+ },
593
+ existing : & expinfrav1.AWSLaunchTemplate {
594
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
595
+ {ID : aws .String ("sg-111" )},
596
+ {ID : aws .String ("sg-222" )},
597
+ },
598
+ SpotMarketOptions : & infrav1.SpotMarketOptions {
599
+ MaxPrice : aws .String ("0.05" ),
600
+ },
601
+ },
602
+ want : true ,
603
+ wantErr : false ,
604
+ },
605
+ {
606
+ name : "Should return true if incoming adds SpotMarketOptions and existing has none" ,
607
+ incoming : & expinfrav1.AWSLaunchTemplate {
608
+ SpotMarketOptions : & infrav1.SpotMarketOptions {
609
+ MaxPrice : aws .String ("0.10" ),
610
+ },
611
+ },
612
+ existing : & expinfrav1.AWSLaunchTemplate {
613
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
614
+ {ID : aws .String ("sg-111" )},
615
+ {ID : aws .String ("sg-222" )},
616
+ },
617
+ SpotMarketOptions : nil ,
618
+ },
619
+ want : true ,
620
+ wantErr : false ,
621
+ },
622
+ {
623
+ name : "Should return true if incoming removes SpotMarketOptions and existing has some" ,
624
+ incoming : & expinfrav1.AWSLaunchTemplate {
625
+ SpotMarketOptions : nil ,
626
+ },
627
+ existing : & expinfrav1.AWSLaunchTemplate {
628
+ AdditionalSecurityGroups : []infrav1.AWSResourceReference {
629
+ {ID : aws .String ("sg-111" )},
630
+ {ID : aws .String ("sg-222" )},
631
+ },
632
+ SpotMarketOptions : & infrav1.SpotMarketOptions {
633
+ MaxPrice : aws .String ("0.05" ),
634
+ },
635
+ },
636
+ want : true ,
637
+ wantErr : false ,
638
+ },
559
639
}
560
640
for _ , tt := range tests {
561
641
t .Run (tt .name , func (t * testing.T ) {
0 commit comments