@@ -258,6 +258,8 @@ func (s *Service) CreateInstance(ctx context.Context, scope *scope.MachineScope,
258
258
259
259
input .MarketType = scope .AWSMachine .Spec .MarketType
260
260
261
+ input .CapacityReservationPreference = scope .AWSMachine .Spec .CapacityReservationPreference
262
+
261
263
s .scope .Debug ("Running instance" , "machine-role" , scope .Role ())
262
264
s .scope .Debug ("Running instance with instance metadata options" , "metadata options" , input .InstanceMetadataOptions )
263
265
out , err := s .runInstance (scope .Role (), input )
@@ -655,7 +657,7 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
655
657
}
656
658
input .MetadataOptions = getInstanceMetadataOptionsRequest (i .InstanceMetadataOptions )
657
659
input .PrivateDnsNameOptions = getPrivateDNSNameOptionsRequest (i .PrivateDNSName )
658
- input .CapacityReservationSpecification = getCapacityReservationSpecification (i .CapacityReservationID )
660
+ input .CapacityReservationSpecification = getCapacityReservationSpecification (i .CapacityReservationID , i . CapacityReservationPreference )
659
661
660
662
if i .Tenancy != "" {
661
663
input .Placement = & types.Placement {
@@ -1144,17 +1146,25 @@ func filterGroups(list []string, strToFilter string) (newList []string) {
1144
1146
return
1145
1147
}
1146
1148
1147
- func getCapacityReservationSpecification (capacityReservationID * string ) * types.CapacityReservationSpecification {
1148
- if capacityReservationID == nil {
1149
- // Not targeting any specific Capacity Reservation
1149
+ func getCapacityReservationSpecification (capacityReservationID * string , capacityReservationPreference infrav1.CapacityReservationPreference ) * types.CapacityReservationSpecification {
1150
+ if capacityReservationID == nil && capacityReservationPreference == "" {
1150
1151
return nil
1151
1152
}
1152
-
1153
- return & types. CapacityReservationSpecification {
1154
- CapacityReservationTarget : & types.CapacityReservationTarget {
1153
+ var spec types. CapacityReservationSpecification
1154
+ if capacityReservationID != nil {
1155
+ spec . CapacityReservationTarget = & types.CapacityReservationTarget {
1155
1156
CapacityReservationId : capacityReservationID ,
1156
- },
1157
+ }
1158
+ }
1159
+ switch capacityReservationPreference {
1160
+ case infrav1 .CapacityReservationPreferenceNone :
1161
+ spec .CapacityReservationPreference = types .CapacityReservationPreferenceNone
1162
+ case infrav1 .CapacityReservationPreferenceOnly :
1163
+ spec .CapacityReservationPreference = types .CapacityReservationPreferenceCapacityReservationsOnly
1164
+ case infrav1 .CapacityReservationPreferenceOpen :
1165
+ spec .CapacityReservationPreference = types .CapacityReservationPreferenceOpen
1157
1166
}
1167
+ return & spec
1158
1168
}
1159
1169
1160
1170
func getInstanceMarketOptionsRequest (i * infrav1.Instance ) (* types.InstanceMarketOptionsRequest , error ) {
0 commit comments