Skip to content

Commit

Permalink
new API field marketType
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma committed Dec 12, 2024
1 parent 6c1c6bd commit 7a2948f
Show file tree
Hide file tree
Showing 25 changed files with 220 additions and 142 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
dst.Status.Bastion.PublicIPOnLaunch = restored.Status.Bastion.PublicIPOnLaunch
dst.Status.Bastion.CapacityReservationID = restored.Status.Bastion.CapacityReservationID
dst.Status.Bastion.UseCapacityBlock = restored.Status.Bastion.UseCapacityBlock
dst.Status.Bastion.MarketType = restored.Status.Bastion.MarketType
}
dst.Spec.Partition = restored.Spec.Partition

Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.PrivateDNSName = restored.Spec.PrivateDNSName
dst.Spec.SecurityGroupOverrides = restored.Spec.SecurityGroupOverrides
dst.Spec.CapacityReservationID = restored.Spec.CapacityReservationID
dst.Spec.UseCapacityBlock = restored.Spec.UseCapacityBlock
dst.Spec.MarketType = restored.Spec.MarketType
if restored.Spec.ElasticIPPool != nil {
if dst.Spec.ElasticIPPool == nil {
dst.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.PrivateDNSName = restored.Spec.Template.Spec.PrivateDNSName
dst.Spec.Template.Spec.SecurityGroupOverrides = restored.Spec.Template.Spec.SecurityGroupOverrides
dst.Spec.Template.Spec.CapacityReservationID = restored.Spec.Template.Spec.CapacityReservationID
dst.Spec.Template.Spec.UseCapacityBlock = restored.Spec.Template.Spec.UseCapacityBlock
dst.Spec.Template.Spec.MarketType = restored.Spec.Template.Spec.MarketType
if restored.Spec.Template.Spec.ElasticIPPool != nil {
if dst.Spec.Template.Spec.ElasticIPPool == nil {
dst.Spec.Template.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions api/v1beta2/awsmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,13 @@ type AWSMachineSpec struct {
// +optional
CapacityReservationID *string `json:"capacityReservationId,omitempty"`

// UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
// If enabled, CapacityReservationID must be specified to identify the target reservation.
// MarketType specifies the type of market for the EC2 instance. Valid values include:
// "spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
// "capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
// If this value is selected, CapacityReservationID must be specified to identify the target reservation.
// If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
// +optional
UseCapacityBlock *bool `json:"useCapacityBlock,omitempty"`
MarketType *MarketType `json:"marketType,omitempty"`
}

// CloudInit defines options related to the bootstrapping systems where
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta2/awsmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ func (r *AWSMachine) validateNetworkElasticIPPool() field.ErrorList {

func (r *AWSMachine) validateInstanceMarketType() field.ErrorList {
var allErrs field.ErrorList
if r.Spec.UseCapacityBlock != nil && r.Spec.SpotMarketOptions != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "useCapacityBlock"), "useCapacityBlock and spotMarketOptions cannot be used together"))
if ptr.Deref(r.Spec.MarketType, "") == MarketTypeCapacityBlock && r.Spec.SpotMarketOptions != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "MarketType"), "MarketType set to capacity-block and spotMarketOptions cannot be used together"))
}
return allErrs
}
Expand Down
10 changes: 5 additions & 5 deletions api/v1beta2/awsmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,22 @@ func TestAWSMachineCreate(t *testing.T) {
wantErr: false,
},
{
name: "invalid useCapacityBlock and spotMarketOptions are specified",
name: "invalid case, MarketType set to MarketTypeCapacityBlock and spotMarketOptions are specified",
machine: &AWSMachine{
Spec: AWSMachineSpec{
UseCapacityBlock: aws.Bool(true),
MarketType: ptr.To(MarketTypeCapacityBlock),
SpotMarketOptions: &SpotMarketOptions{},
InstanceType: "test",
},
},
wantErr: true,
},
{
name: "valid useCapacityBlock is specified",
name: "valid MarketType set to MarketTypeCapacityBlock is specified",
machine: &AWSMachine{
Spec: AWSMachineSpec{
UseCapacityBlock: aws.Bool(true),
InstanceType: "test",
MarketType: ptr.To(MarketTypeCapacityBlock),
InstanceType: "test",
},
},
wantErr: false,
Expand Down
24 changes: 21 additions & 3 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,30 @@ type Instance struct {
// +optional
CapacityReservationID *string `json:"capacityReservationId,omitempty"`

// UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
// If enabled, CapacityReservationID must be specified to identify the target reservation.
// MarketType specifies the type of market for the EC2 instance. Valid values include:
// "on-demand" (default): The instance runs as a standard On-Demand instance.
// "spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
// "capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
// If this value is selected, CapacityReservationID must be specified to identify the target reservation.
// If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
// +optional
UseCapacityBlock *bool `json:"useCapacityBlock,omitempty"`
MarketType *MarketType `json:"marketType,omitempty"`
}

// MarketType describes the market type of an Instance
type MarketType string

const (
// MarketTypeOnDemand is a MarketType enum value
MarketTypeOnDemand MarketType = "on-demand"

// MarketTypeSpot is a MarketType enum value
MarketTypeSpot MarketType = "spot"

// MarketTypeCapacityBlock is a MarketType enum value
MarketTypeCapacityBlock MarketType = "capacity-block"
)

// InstanceMetadataState describes the state of InstanceMetadataOptions.HttpEndpoint and InstanceMetadataOptions.InstanceMetadataTags
type InstanceMetadataState string

Expand Down
12 changes: 6 additions & 6 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,15 @@ spec:
instanceState:
description: The current state of the instance.
type: string
marketType:
description: |-
MarketType specifies the type of market for the EC2 instance. Valid values include:
"on-demand" (default): The instance runs as a standard On-Demand instance.
"spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
"capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If this value is selected, CapacityReservationID must be specified to identify the target reservation.
If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
type: string
networkInterfaces:
description: Specifies ENIs attached to instance
items:
Expand Down Expand Up @@ -1376,11 +1385,6 @@ spec:
type:
description: The instance type.
type: string
useCapacityBlock:
description: |-
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If enabled, CapacityReservationID must be specified to identify the target reservation.
type: boolean
userData:
description: |-
UserData is the raw data script passed to the instance which is run upon bootstrap.
Expand Down Expand Up @@ -3255,6 +3259,15 @@ spec:
instanceState:
description: The current state of the instance.
type: string
marketType:
description: |-
MarketType specifies the type of market for the EC2 instance. Valid values include:
"on-demand" (default): The instance runs as a standard On-Demand instance.
"spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
"capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If this value is selected, CapacityReservationID must be specified to identify the target reservation.
If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
type: string
networkInterfaces:
description: Specifies ENIs attached to instance
items:
Expand Down Expand Up @@ -3421,11 +3434,6 @@ spec:
type:
description: The instance type.
type: string
useCapacityBlock:
description: |-
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If enabled, CapacityReservationID must be specified to identify the target reservation.
type: boolean
userData:
description: |-
UserData is the raw data script passed to the instance which is run upon bootstrap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,15 @@ spec:
instanceState:
description: The current state of the instance.
type: string
marketType:
description: |-
MarketType specifies the type of market for the EC2 instance. Valid values include:
"on-demand" (default): The instance runs as a standard On-Demand instance.
"spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
"capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If this value is selected, CapacityReservationID must be specified to identify the target reservation.
If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
type: string
networkInterfaces:
description: Specifies ENIs attached to instance
items:
Expand Down Expand Up @@ -2343,11 +2352,6 @@ spec:
type:
description: The instance type.
type: string
useCapacityBlock:
description: |-
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If enabled, CapacityReservationID must be specified to identify the target reservation.
type: boolean
userData:
description: |-
UserData is the raw data script passed to the instance which is run upon bootstrap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ spec:
description: 'InstanceType is the type of instance to create.
Example: m4.xlarge'
type: string
marketType:
description: |-
MarketType specifies the type of market for the EC2 instance. Valid values include:
"spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
"capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If this value is selected, CapacityReservationID must be specified to identify the target reservation.
If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
type: string
name:
description: The name of the launch template.
type: string
Expand Down Expand Up @@ -850,11 +858,6 @@ spec:
SSHKeyName is the name of the ssh key to attach to the instance. Valid values are empty string
(do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
type: string
useCapacityBlock:
description: |-
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If enabled, CapacityReservationID must be specified to identify the target reservation.
type: boolean
versionNumber:
description: |-
VersionNumber is the version of the launch template that is applied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,14 @@ spec:
m4.xlarge'
minLength: 2
type: string
marketType:
description: |-
MarketType specifies the type of market for the EC2 instance. Valid values include:
"spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
"capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If this value is selected, CapacityReservationID must be specified to identify the target reservation.
If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
type: string
networkInterfaces:
description: |-
NetworkInterfaces is a list of ENIs to associate with the instance.
Expand Down Expand Up @@ -1080,11 +1088,6 @@ spec:
cloud-init has built-in support for gzip-compressed user data
user data stored in aws secret manager is always gzip-compressed.
type: boolean
useCapacityBlock:
description: |-
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If enabled, CapacityReservationID must be specified to identify the target reservation.
type: boolean
required:
- instanceType
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@ spec:
Example: m4.xlarge'
minLength: 2
type: string
marketType:
description: |-
MarketType specifies the type of market for the EC2 instance. Valid values include:
"spot": The instance runs as a Spot instance. When SpotMarketOptions is provided, the MarketType defaults to "spot".
"capacity-block": The instance utilizes pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If this value is selected, CapacityReservationID must be specified to identify the target reservation.
If MarketType is not specified and SpotMarketOptions is provided, the MarketType defaults to "spot".
type: string
networkInterfaces:
description: |-
NetworkInterfaces is a list of ENIs to associate with the instance.
Expand Down Expand Up @@ -1021,11 +1029,6 @@ spec:
cloud-init has built-in support for gzip-compressed user data
user data stored in aws secret manager is always gzip-compressed.
type: boolean
useCapacityBlock:
description: |-
UseCapacityBlock enables usage of pre-purchased compute capacity (capacity blocks) with AWS Capacity Reservations.
If enabled, CapacityReservationID must be specified to identify the target reservation.
type: boolean
required:
- instanceType
type: object
Expand Down
Loading

0 comments on commit 7a2948f

Please sign in to comment.