Skip to content

Commit 022d46f

Browse files
author
Thirumalesh Aaraveti
committed
Updated the comments
1 parent 6123a1a commit 022d46f

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

api/v1beta2/awsmachine_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const (
6565

6666
// AWSMachineSpec defines the desired state of an Amazon EC2 instance.
6767
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.marketType) || self.marketType != 'Spot'",message="capacityReservationId may not be set when marketType is Spot"
68+
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.spotMarketOptions)",message="cannot be set to 'Spot' when CapacityReservationID is specified"
6869
type AWSMachineSpec struct {
6970
// ProviderID is the unique identifier as specified by the cloud provider.
7071
ProviderID *string `json:"providerID,omitempty"`

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,8 @@ spec:
11081108
- message: capacityReservationId may not be set when marketType is Spot
11091109
rule: '!has(self.capacityReservationId) || !has(self.marketType) ||
11101110
self.marketType != ''Spot'''
1111+
- message: cannot be set to 'Spot' when CapacityReservationID is specified
1112+
rule: '!has(self.capacityReservationId) || !has(self.spotMarketOptions)'
11111113
status:
11121114
description: AWSMachineStatus defines the observed state of AWSMachine.
11131115
properties:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,9 @@ spec:
10501050
is Spot
10511051
rule: '!has(self.capacityReservationId) || !has(self.marketType)
10521052
|| self.marketType != ''Spot'''
1053+
- message: cannot be set to 'Spot' when CapacityReservationID
1054+
is specified
1055+
rule: '!has(self.capacityReservationId) || !has(self.spotMarketOptions)'
10531056
required:
10541057
- spec
10551058
type: object

exp/api/v1beta2/awsmachinepool_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ func (r *AWSMachinePool) validateInstanceMarketType() field.ErrorList {
208208
allErrs = append(allErrs, field.Invalid(field.NewPath("spec.awsLaunchTemplate.MarketType"), r.Spec.AWSLaunchTemplate.MarketType, fmt.Sprintf("Valid values are: %s, %s, %s and omitted", v1beta2.MarketTypeOnDemand, v1beta2.MarketTypeSpot, v1beta2.MarketTypeCapacityBlock)))
209209
}
210210
if r.Spec.AWSLaunchTemplate.MarketType == v1beta2.MarketTypeSpot && r.Spec.AWSLaunchTemplate.CapacityReservationID != nil {
211-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.awsLaunchTemplate.marketType"), "setting marketType to Spot and CapacityReservationID cannot be used together"))
211+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.awsLaunchTemplate.marketType"), "cannot be set to 'Spot' when CapacityReservationID is specified"))
212212
}
213213

214214
if r.Spec.AWSLaunchTemplate.CapacityReservationID != nil && r.Spec.AWSLaunchTemplate.SpotMarketOptions != nil {
215-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.awsLaunchTemplate.spotMarketOptions"), "setting spotMarketOptions and CapacityReservationID cannot be used together"))
215+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.awsLaunchTemplate.spotMarketOptions"), "cannot be set to when CapacityReservationID is specified"))
216216
}
217217

218218
return allErrs

exp/api/v1beta2/awsmachinepool_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestAWSMachinePoolValidateCreate(t *testing.T) {
197197
wantErr: false,
198198
},
199199
{
200-
name: "with MarketType Spot and CapacityReservationID value provided",
200+
name: "with MarketType Spot and CapacityReservationID value provided",
201201
pool: &AWSMachinePool{
202202
Spec: AWSMachinePoolSpec{
203203
AWSLaunchTemplate: AWSLaunchTemplate{

pkg/cloud/services/ec2/instances.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ func getInstanceMarketOptionsRequest(i *infrav1.Instance) (*ec2.InstanceMarketOp
11551155
}
11561156

11571157
if (i.MarketType == infrav1.MarketTypeSpot || i.SpotMarketOptions != nil) && i.CapacityReservationID != nil {
1158-
return nil, errors.New("can't create spot capacity-blocks, remove capacityReservationID or remove spot requests")
1158+
return nil, errors.New("unable to generate marketOptions for spot instance, capacityReservationID is incompatible with marketType spot and spotMarketOptions")
11591159
}
11601160

11611161
// Infer MarketType if not explicitly set

pkg/cloud/services/ec2/instances_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,7 +5771,7 @@ func TestGetInstanceMarketOptionsRequest(t *testing.T) {
57715771
expectedError: nil,
57725772
},
57735773
{
5774-
name: "with an marketType Spot options specified",
5774+
name: "with marketType Spot specified",
57755775
instance: &infrav1.Instance{
57765776
MarketType: infrav1.MarketTypeSpot,
57775777
},
@@ -5784,15 +5784,15 @@ func TestGetInstanceMarketOptionsRequest(t *testing.T) {
57845784
},
57855785
},
57865786
{
5787-
name: "with an marketType Spot and CapacityRerservationID specified",
5787+
name: "with marketType Spot and capacityRerservationID specified",
57885788
instance: &infrav1.Instance{
57895789
MarketType: infrav1.MarketTypeSpot,
57905790
CapacityReservationID: mockCapacityReservationID,
57915791
},
5792-
expectedError: errors.Errorf("can't create spot capacity-blocks, remove capacityReservationID or remove spot requests"),
5792+
expectedError: errors.Errorf("unable to generate marketOptions for spot instance, capacityReservationID is incompatible with marketType spot and spotMarketOptions"),
57935793
},
57945794
{
5795-
name: "with an spotMarketOptions and CapacityRerservationID specified",
5795+
name: "with spotMarketOptions and capacityRerservationID specified",
57965796
instance: &infrav1.Instance{
57975797
SpotMarketOptions: &infrav1.SpotMarketOptions{},
57985798
CapacityReservationID: mockCapacityReservationID,

0 commit comments

Comments
 (0)