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
2 changes: 1 addition & 1 deletion api/v1beta2/awsmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ type AWSMachineSpec struct {
// CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
// "Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
// "None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
// "CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
// "CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
// +kubebuilder:validation:Enum="";None;CapacityReservationsOnly;Open
// +optional
CapacityReservationPreference CapacityReservationPreference `json:"capacityReservationPreference,omitempty"`
Expand Down
8 changes: 7 additions & 1 deletion api/v1beta2/awsmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,13 @@ func (r *AWSMachine) validateNetworkElasticIPPool() field.ErrorList {
func (r *AWSMachine) validateCapacityReservation() field.ErrorList {
var allErrs field.ErrorList
if r.Spec.CapacityReservationID != nil && r.Spec.CapacityReservationPreference != CapacityReservationPreferenceOnly && r.Spec.CapacityReservationPreference != "" {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "capacityReservationPreference"), "when a reservation ID is specified, capacityReservationPreference may only be `capacity-reservations-only` or empty"))
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "capacityReservationPreference"), "when a reservation ID is specified, capacityReservationPreference may only be 'CapacityReservationsOnly' or empty"))
}
if r.Spec.CapacityReservationPreference == CapacityReservationPreferenceOnly && r.Spec.MarketType == MarketTypeSpot {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "capacityReservationPreference"), "when MarketType is set to 'Spot', capacityReservationPreference cannot be set to 'CapacityReservationsOnly'"))
}
if r.Spec.CapacityReservationPreference == CapacityReservationPreferenceOnly && r.Spec.SpotMarketOptions != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "capacityReservationPreference"), "when capacityReservationPreference is 'CapacityReservationsOnly', SpotMarketOptions cannot be set (which implies MarketType: 'Spot')"))
}
return allErrs
}
Expand Down
26 changes: 25 additions & 1 deletion api/v1beta2/awsmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestAWSMachineCreate(t *testing.T) {
wantErr: true,
},
{
name: "valid MarketType set to MarketTypeCapacityBlock is specified and CapacityReservationId is not provided",
name: "invalid MarketType set to MarketTypeCapacityBlock is specified and CapacityReservationId is not provided",
machine: &AWSMachine{
Spec: AWSMachineSpec{
MarketType: MarketTypeCapacityBlock,
Expand Down Expand Up @@ -293,6 +293,30 @@ func TestAWSMachineCreate(t *testing.T) {
},
wantErr: false,
},
{
name: "invalid CapacityReservationPreference is `CapacityReservationsOnly` and MarketType is `Spot`",
machine: &AWSMachine{
Spec: AWSMachineSpec{
InstanceType: "test",
CapacityReservationID: aws.String("cr-12345678901234567"),
CapacityReservationPreference: CapacityReservationPreferenceOnly,
MarketType: MarketTypeSpot,
},
},
wantErr: true,
},
{
name: "invalid CapacityReservationPreference is `CapacityReservationsOnly` and SpotMarketOptions is non-nil",
machine: &AWSMachine{
Spec: AWSMachineSpec{
InstanceType: "test",
CapacityReservationID: aws.String("cr-12345678901234567"),
CapacityReservationPreference: CapacityReservationPreferenceOnly,
SpotMarketOptions: &SpotMarketOptions{},
},
},
wantErr: true,
},
{
name: "empty instance type not allowed",
machine: &AWSMachine{
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ type Instance struct {
// CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
// "Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
// "None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
// "CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
// "CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
// +kubebuilder:validation:Enum="";None;CapacityReservationsOnly;Open
// +optional
CapacityReservationPreference CapacityReservationPreference `json:"capacityReservationPreference,omitempty"`
Expand All @@ -304,7 +304,7 @@ const (
// CapacityReservationPreferenceNone the instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
CapacityReservationPreferenceNone CapacityReservationPreference = "None"

// CapacityReservationPreferenceOnly the instance will only run if matched or targeted to a Capacity Reservation
// CapacityReservationPreferenceOnly the instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
CapacityReservationPreferenceOnly CapacityReservationPreference = "CapacityReservationsOnly"

// CapacityReservationPreferenceOpen the instance may make use of open Capacity Reservations that match its AZ and InstanceType.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ spec:
CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
"Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
"None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
type: string
ebsOptimized:
description: Indicates whether the instance is optimized for Amazon
Expand Down Expand Up @@ -3444,7 +3444,7 @@ spec:
CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
"Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
"None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
type: string
ebsOptimized:
description: Indicates whether the instance is optimized for Amazon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,7 @@ spec:
CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
"Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
"None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
type: string
ebsOptimized:
description: Indicates whether the instance is optimized for Amazon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ spec:
CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
"Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
"None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
type: string
cloudInit:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ spec:
CapacityReservationPreference specifies the preference for use of Capacity Reservations by the instance. Valid values include:
"Open": The instance may make use of open Capacity Reservations that match its AZ and InstanceType
"None": The instance may not make use of any Capacity Reservations. This is to conserve open reservations for desired workloads
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation
"CapacityReservationsOnly": The instance will only run if matched or targeted to a Capacity Reservation. Note that this is incompatible with a MarketType of `Spot`
type: string
cloudInit:
description: |-
Expand Down