Skip to content

Commit 2f41cef

Browse files
authored
Merge pull request #5506 from giantswarm/capacityblock-change-launchtemplate
🐛 Update launch template if capacity-block reservation id changes
2 parents f5dca4c + 4997ec4 commit 2f41cef

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pkg/cloud/services/ec2/launchtemplate.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ func (s *Service) SDKToLaunchTemplate(d *ec2.LaunchTemplateVersion) (*expinfrav1
712712
VersionNumber: d.VersionNumber,
713713
}
714714

715+
if v.CapacityReservationSpecification != nil &&
716+
v.CapacityReservationSpecification.CapacityReservationTarget != nil &&
717+
v.CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationId != nil {
718+
i.CapacityReservationID = v.CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationId
719+
}
720+
715721
if v.MetadataOptions != nil {
716722
i.InstanceMetadataOptions = &infrav1.InstanceMetadataOptions{
717723
HTTPPutResponseHopLimit: aws.Int64Value(v.MetadataOptions.HttpPutResponseHopLimit),
@@ -802,6 +808,10 @@ func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, inc
802808
return true, nil
803809
}
804810

811+
if !cmp.Equal(incoming.CapacityReservationID, existing.CapacityReservationID) {
812+
return true, nil
813+
}
814+
805815
if !cmp.Equal(incoming.PrivateDNSName, existing.PrivateDNSName) {
806816
return true, nil
807817
}

pkg/cloud/services/ec2/launchtemplate_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,36 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
860860
want: true,
861861
wantErr: false,
862862
},
863+
{
864+
name: "Should return true if capacity reservation IDs are different",
865+
incoming: &expinfrav1.AWSLaunchTemplate{
866+
CapacityReservationID: aws.String("new-reservation"),
867+
},
868+
existing: &expinfrav1.AWSLaunchTemplate{
869+
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
870+
{ID: aws.String("sg-111")},
871+
{ID: aws.String("sg-222")},
872+
},
873+
CapacityReservationID: aws.String("old-reservation"),
874+
},
875+
want: true,
876+
wantErr: false,
877+
},
878+
{
879+
name: "Should return true if one has capacity reservation ID and other doesn't",
880+
incoming: &expinfrav1.AWSLaunchTemplate{
881+
CapacityReservationID: aws.String("new-reservation"),
882+
},
883+
existing: &expinfrav1.AWSLaunchTemplate{
884+
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
885+
{ID: aws.String("sg-111")},
886+
{ID: aws.String("sg-222")},
887+
},
888+
CapacityReservationID: nil,
889+
},
890+
want: true,
891+
wantErr: false,
892+
},
863893
}
864894
for _, tt := range tests {
865895
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)