Skip to content

Commit 99f00ed

Browse files
committed
🐛 Launchtemplate needs to be updated if spot options are changed
1 parent 7b09356 commit 99f00ed

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

pkg/cloud/services/ec2/launchtemplate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, inc
777777
if !cmp.Equal(incoming.InstanceMetadataOptions, existing.InstanceMetadataOptions) {
778778
return true, nil
779779
}
780+
if !cmp.Equal(incoming.SpotMarketOptions, existing.SpotMarketOptions) {
781+
return true, nil
782+
}
780783

781784
incomingIDs, err := s.GetAdditionalSecurityGroupsIDs(incoming.AdditionalSecurityGroups)
782785
if err != nil {

pkg/cloud/services/ec2/launchtemplate_test.go

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,20 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
440440
want bool
441441
wantErr bool
442442
}{
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+
},
443457
{
444458
name: "the same security groups",
445459
incoming: &expinfrav1.AWSLaunchTemplate{
@@ -497,6 +511,10 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
497511
IamInstanceProfile: DefaultAmiNameFormat,
498512
},
499513
existing: &expinfrav1.AWSLaunchTemplate{
514+
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
515+
{ID: aws.String("sg-111")},
516+
{ID: aws.String("sg-222")},
517+
},
500518
IamInstanceProfile: "some-other-profile",
501519
},
502520
want: true,
@@ -507,6 +525,10 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
507525
InstanceType: "t3.micro",
508526
},
509527
existing: &expinfrav1.AWSLaunchTemplate{
528+
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
529+
{ID: aws.String("sg-111")},
530+
{ID: aws.String("sg-222")},
531+
},
510532
InstanceType: "t3.large",
511533
},
512534
want: true,
@@ -540,9 +562,14 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
540562
HTTPTokens: infrav1.HTTPTokensStateRequired,
541563
},
542564
},
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,
546573
},
547574
{
548575
name: "new launch template instance metadata options, removing IMDSv2 requirement",
@@ -556,6 +583,59 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
556583
want: true,
557584
wantErr: false,
558585
},
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+
},
559639
}
560640
for _, tt := range tests {
561641
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)