Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/cloud/services/ec2/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,12 @@ func (s *Service) SDKToLaunchTemplate(d *ec2.LaunchTemplateVersion) (*expinfrav1
VersionNumber: d.VersionNumber,
}

if v.CapacityReservationSpecification != nil &&
v.CapacityReservationSpecification.CapacityReservationTarget != nil &&
v.CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationId != nil {
i.CapacityReservationID = v.CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationId
}

if v.MetadataOptions != nil {
i.InstanceMetadataOptions = &infrav1.InstanceMetadataOptions{
HTTPPutResponseHopLimit: aws.Int64Value(v.MetadataOptions.HttpPutResponseHopLimit),
Expand Down Expand Up @@ -802,6 +808,10 @@ func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, inc
return true, nil
}

if !cmp.Equal(incoming.CapacityReservationID, existing.CapacityReservationID) {
return true, nil
}

if !cmp.Equal(incoming.PrivateDNSName, existing.PrivateDNSName) {
return true, nil
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/cloud/services/ec2/launchtemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,36 @@ func TestServiceLaunchTemplateNeedsUpdate(t *testing.T) {
want: true,
wantErr: false,
},
{
name: "Should return true if capacity reservation IDs are different",
incoming: &expinfrav1.AWSLaunchTemplate{
CapacityReservationID: aws.String("new-reservation"),
},
existing: &expinfrav1.AWSLaunchTemplate{
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
{ID: aws.String("sg-111")},
{ID: aws.String("sg-222")},
},
CapacityReservationID: aws.String("old-reservation"),
},
want: true,
wantErr: false,
},
{
name: "Should return true if one has capacity reservation ID and other doesn't",
incoming: &expinfrav1.AWSLaunchTemplate{
CapacityReservationID: aws.String("new-reservation"),
},
existing: &expinfrav1.AWSLaunchTemplate{
AdditionalSecurityGroups: []infrav1.AWSResourceReference{
{ID: aws.String("sg-111")},
{ID: aws.String("sg-222")},
},
CapacityReservationID: nil,
},
want: true,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading