Skip to content

Commit eb27e35

Browse files
author
Thirumalesh Aaraveti
committed
Added the suport for capacity blocks
1 parent df09e6c commit eb27e35

23 files changed

+696
-49
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
6060
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
6161
dst.Status.Bastion.PublicIPOnLaunch = restored.Status.Bastion.PublicIPOnLaunch
6262
dst.Status.Bastion.CapacityReservationID = restored.Status.Bastion.CapacityReservationID
63+
dst.Status.Bastion.UseCapacityBlock = restored.Status.Bastion.UseCapacityBlock
6364
}
6465
dst.Spec.Partition = restored.Spec.Partition
6566

api/v1beta1/awsmachine_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
4242
dst.Spec.PrivateDNSName = restored.Spec.PrivateDNSName
4343
dst.Spec.SecurityGroupOverrides = restored.Spec.SecurityGroupOverrides
4444
dst.Spec.CapacityReservationID = restored.Spec.CapacityReservationID
45+
dst.Spec.UseCapacityBlock = restored.Spec.UseCapacityBlock
4546
if restored.Spec.ElasticIPPool != nil {
4647
if dst.Spec.ElasticIPPool == nil {
4748
dst.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}
@@ -104,6 +105,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
104105
dst.Spec.Template.Spec.PrivateDNSName = restored.Spec.Template.Spec.PrivateDNSName
105106
dst.Spec.Template.Spec.SecurityGroupOverrides = restored.Spec.Template.Spec.SecurityGroupOverrides
106107
dst.Spec.Template.Spec.CapacityReservationID = restored.Spec.Template.Spec.CapacityReservationID
108+
dst.Spec.Template.Spec.UseCapacityBlock = restored.Spec.Template.Spec.UseCapacityBlock
107109
if restored.Spec.Template.Spec.ElasticIPPool != nil {
108110
if dst.Spec.Template.Spec.ElasticIPPool == nil {
109111
dst.Spec.Template.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}

api/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awsmachine_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ type AWSMachineSpec struct {
197197
// CapacityReservationID specifies the target Capacity Reservation into which the instance should be launched.
198198
// +optional
199199
CapacityReservationID *string `json:"capacityReservationId,omitempty"`
200+
201+
// UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
202+
// If enabled, CapacityReservationID must be specified to identify the target reservation.
203+
// +optional
204+
UseCapacityBlock *bool `json:"useCapacityBlock,omitempty"`
200205
}
201206

202207
// CloudInit defines options related to the bootstrapping systems where

api/v1beta2/awsmachine_webhook.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (r *AWSMachine) ValidateCreate() (admission.Warnings, error) {
6666
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
6767
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
6868
allErrs = append(allErrs, r.validateNetworkElasticIPPool()...)
69+
allErrs = append(allErrs, r.validateInstanceMarketType()...)
6970

7071
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
7172
}
@@ -361,6 +362,14 @@ func (r *AWSMachine) validateNetworkElasticIPPool() field.ErrorList {
361362
return allErrs
362363
}
363364

365+
func (r *AWSMachine) validateInstanceMarketType() field.ErrorList {
366+
var allErrs field.ErrorList
367+
if r.Spec.UseCapacityBlock != nil && r.Spec.SpotMarketOptions != nil {
368+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.UseCapacityBlock"), "to launch capacityBlocks use UseCapacityBlock, specifying SpotMarketOptions is forbidden"))
369+
}
370+
return allErrs
371+
}
372+
364373
func (r *AWSMachine) validateNonRootVolumes() field.ErrorList {
365374
var allErrs field.ErrorList
366375

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ func TestAWSMachineCreate(t *testing.T) {
217217
},
218218
wantErr: false,
219219
},
220+
{
221+
name: "invalid useCapacityBlock and spotMarketOptions are specified",
222+
machine: &AWSMachine{
223+
Spec: AWSMachineSpec{
224+
UseCapacityBlock: aws.Bool(true),
225+
SpotMarketOptions: &SpotMarketOptions{},
226+
InstanceType: "test",
227+
},
228+
},
229+
wantErr: true,
230+
},
231+
{
232+
name: "valid useCapacityBlock is specified",
233+
machine: &AWSMachine{
234+
Spec: AWSMachineSpec{
235+
UseCapacityBlock: aws.Bool(true),
236+
InstanceType: "test",
237+
},
238+
},
239+
wantErr: false,
240+
},
220241
{
221242
name: "empty instance type not allowed",
222243
machine: &AWSMachine{

api/v1beta2/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ type Instance struct {
261261
// CapacityReservationID specifies the target Capacity Reservation into which the instance should be launched.
262262
// +optional
263263
CapacityReservationID *string `json:"capacityReservationId,omitempty"`
264+
265+
// UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
266+
// If enabled, CapacityReservationID must be specified to identify the target reservation.
267+
// +optional
268+
UseCapacityBlock *bool `json:"useCapacityBlock,omitempty"`
264269
}
265270

266271
// InstanceMetadataState describes the state of InstanceMetadataOptions.HttpEndpoint and InstanceMetadataOptions.InstanceMetadataTags

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,11 @@ spec:
13971397
type:
13981398
description: The instance type.
13991399
type: string
1400+
useCapacityBlock:
1401+
description: |-
1402+
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
1403+
If enabled, CapacityReservationID must be specified to identify the target reservation.
1404+
type: boolean
14001405
userData:
14011406
description: |-
14021407
UserData is the raw data script passed to the instance which is run upon bootstrap.
@@ -3458,6 +3463,11 @@ spec:
34583463
type:
34593464
description: The instance type.
34603465
type: string
3466+
useCapacityBlock:
3467+
description: |-
3468+
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
3469+
If enabled, CapacityReservationID must be specified to identify the target reservation.
3470+
type: boolean
34613471
userData:
34623472
description: |-
34633473
UserData is the raw data script passed to the instance which is run upon bootstrap.

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,11 @@ spec:
23722372
type:
23732373
description: The instance type.
23742374
type: string
2375+
useCapacityBlock:
2376+
description: |-
2377+
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
2378+
If enabled, CapacityReservationID must be specified to identify the target reservation.
2379+
type: boolean
23752380
userData:
23762381
description: |-
23772382
UserData is the raw data script passed to the instance which is run upon bootstrap.

0 commit comments

Comments
 (0)