Skip to content

Commit 2ea5ce8

Browse files
faermanjrvanderp3
authored andcommitted
dedicated hosts implementation
1 parent 483f3a9 commit 2ea5ce8

19 files changed

+387
-0
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
6363
dst.Status.Bastion.NetworkInterfaceType = restored.Status.Bastion.NetworkInterfaceType
6464
dst.Status.Bastion.CapacityReservationID = restored.Status.Bastion.CapacityReservationID
6565
dst.Status.Bastion.MarketType = restored.Status.Bastion.MarketType
66+
dst.Status.Bastion.HostAffinity = restored.Status.Bastion.HostAffinity
67+
dst.Status.Bastion.HostID = restored.Status.Bastion.HostID
6668
}
6769
dst.Spec.Partition = restored.Spec.Partition
6870

api/v1beta1/awsmachine_conversion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
4444
dst.Spec.SecurityGroupOverrides = restored.Spec.SecurityGroupOverrides
4545
dst.Spec.CapacityReservationID = restored.Spec.CapacityReservationID
4646
dst.Spec.MarketType = restored.Spec.MarketType
47+
dst.Spec.HostID = restored.Spec.HostID
48+
dst.Spec.HostAffinity = restored.Spec.HostAffinity
4749
dst.Spec.NetworkInterfaceType = restored.Spec.NetworkInterfaceType
4850
if restored.Spec.ElasticIPPool != nil {
4951
if dst.Spec.ElasticIPPool == nil {
@@ -108,6 +110,8 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
108110
dst.Spec.Template.Spec.SecurityGroupOverrides = restored.Spec.Template.Spec.SecurityGroupOverrides
109111
dst.Spec.Template.Spec.CapacityReservationID = restored.Spec.Template.Spec.CapacityReservationID
110112
dst.Spec.Template.Spec.MarketType = restored.Spec.Template.Spec.MarketType
113+
dst.Spec.Template.Spec.HostID = restored.Spec.Template.Spec.HostID
114+
dst.Spec.Template.Spec.HostAffinity = restored.Spec.Template.Spec.HostAffinity
111115
dst.Spec.Template.Spec.NetworkInterfaceType = restored.Spec.Template.Spec.NetworkInterfaceType
112116
if restored.Spec.Template.Spec.ElasticIPPool != nil {
113117
if dst.Spec.Template.Spec.ElasticIPPool == nil {

api/v1beta1/zz_generated.conversion.go

Lines changed: 4 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ type AWSMachineSpec struct {
233233
// If marketType is not specified and spotMarketOptions is provided, the marketType defaults to "Spot".
234234
// +optional
235235
MarketType MarketType `json:"marketType,omitempty"`
236+
237+
// HostID specifies the Dedicated Host on which the instance must be started.
238+
// +optional
239+
HostID *string `json:"hostID,omitempty"`
240+
241+
// HostAffinity specifies the dedicated host affinity setting for the instance.
242+
// When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
243+
// When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
244+
// When HostAffinity is defined, HostID is required.
245+
// +optional
246+
// +kubebuilder:validation:Enum:=default;host
247+
HostAffinity *string `json:"hostAffinity,omitempty"`
236248
}
237249

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

api/v1beta2/awsmachine_webhook.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (*awsMachineWebhook) ValidateCreate(_ context.Context, obj runtime.Object)
7575
allErrs = append(allErrs, r.validateNonRootVolumes()...)
7676
allErrs = append(allErrs, r.validateSSHKeyName()...)
7777
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
78+
allErrs = append(allErrs, r.validateHostAffinity()...)
7879
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
7980
allErrs = append(allErrs, r.validateNetworkElasticIPPool()...)
8081
allErrs = append(allErrs, r.validateInstanceMarketType()...)
@@ -107,6 +108,7 @@ func (*awsMachineWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj run
107108
allErrs = append(allErrs, r.validateCloudInitSecret()...)
108109
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
109110
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
111+
allErrs = append(allErrs, r.validateHostAffinity()...)
110112

111113
newAWSMachineSpec := newAWSMachine["spec"].(map[string]interface{})
112114
oldAWSMachineSpec := oldAWSMachine["spec"].(map[string]interface{})
@@ -455,6 +457,17 @@ func (r *AWSMachine) validateAdditionalSecurityGroups() field.ErrorList {
455457
return allErrs
456458
}
457459

460+
func (r *AWSMachine) validateHostAffinity() field.ErrorList {
461+
var allErrs field.ErrorList
462+
463+
if r.Spec.HostAffinity != nil {
464+
if r.Spec.HostID == nil || len(*r.Spec.HostID) == 0 {
465+
allErrs = append(allErrs, field.Required(field.NewPath("spec.hostID"), "hostID must be set when hostAffinity is configured"))
466+
}
467+
}
468+
return allErrs
469+
}
470+
458471
func (r *AWSMachine) validateSSHKeyName() field.ErrorList {
459472
return validateSSHKeyName(r.Spec.SSHKeyName)
460473
}

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,37 @@ func TestAWSMachineCreate(t *testing.T) {
412412
},
413413
wantErr: true,
414414
},
415+
{
416+
name: "configure host affinity with Host ID",
417+
machine: &AWSMachine{
418+
Spec: AWSMachineSpec{
419+
InstanceType: "test",
420+
HostAffinity: ptr.To("default"),
421+
HostID: ptr.To("h-09dcf61cb388b0149"),
422+
},
423+
},
424+
wantErr: false,
425+
},
426+
{
427+
name: "configure host affinity with invalid affinity",
428+
machine: &AWSMachine{
429+
Spec: AWSMachineSpec{
430+
InstanceType: "test",
431+
HostAffinity: ptr.To("invalid"),
432+
},
433+
},
434+
wantErr: true,
435+
},
436+
{
437+
name: "configure host affinity without Host ID",
438+
machine: &AWSMachine{
439+
Spec: AWSMachineSpec{
440+
InstanceType: "test",
441+
HostAffinity: ptr.To("default"),
442+
},
443+
},
444+
wantErr: true,
445+
},
415446
{
416447
name: "create with valid BYOIPv4",
417448
machine: &AWSMachine{

api/v1beta2/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ type Instance struct {
273273
// If marketType is not specified and spotMarketOptions is provided, the marketType defaults to "Spot".
274274
// +optional
275275
MarketType MarketType `json:"marketType,omitempty"`
276+
277+
// HostAffinity specifies the dedicated host affinity setting for the instance.
278+
// When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
279+
// When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
280+
// When HostAffinity is defined, HostID is required.
281+
// +optional
282+
// +kubebuilder:validation:Enum:=default;host
283+
HostAffinity *string `json:"hostAffinity,omitempty"`
284+
285+
// HostID specifies the dedicated host on which the instance should be started.
286+
// +optional
287+
HostID *string `json:"hostID,omitempty"`
276288
}
277289

278290
// MarketType describes the market type of an Instance

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 20 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,20 @@ spec:
12221222
description: Specifies whether enhanced networking with ENA is
12231223
enabled.
12241224
type: boolean
1225+
hostAffinity:
1226+
description: |-
1227+
HostAffinity specifies the dedicated host affinity setting for the instance.
1228+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
1229+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
1230+
When HostAffinity is defined, HostID is required.
1231+
enum:
1232+
- default
1233+
- host
1234+
type: string
1235+
hostID:
1236+
description: HostID specifies the dedicated host on which the
1237+
instance should be started.
1238+
type: string
12251239
iamProfile:
12261240
description: The name of the IAM instance profile associated with
12271241
the instance, if applicable.
@@ -3403,6 +3417,20 @@ spec:
34033417
description: Specifies whether enhanced networking with ENA is
34043418
enabled.
34053419
type: boolean
3420+
hostAffinity:
3421+
description: |-
3422+
HostAffinity specifies the dedicated host affinity setting for the instance.
3423+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
3424+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
3425+
When HostAffinity is defined, HostID is required.
3426+
enum:
3427+
- default
3428+
- host
3429+
type: string
3430+
hostID:
3431+
description: HostID specifies the dedicated host on which the
3432+
instance should be started.
3433+
type: string
34063434
iamProfile:
34073435
description: The name of the IAM instance profile associated with
34083436
the instance, if applicable.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,20 @@ spec:
22052205
description: Specifies whether enhanced networking with ENA is
22062206
enabled.
22072207
type: boolean
2208+
hostAffinity:
2209+
description: |-
2210+
HostAffinity specifies the dedicated host affinity setting for the instance.
2211+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
2212+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
2213+
When HostAffinity is defined, HostID is required.
2214+
enum:
2215+
- default
2216+
- host
2217+
type: string
2218+
hostID:
2219+
description: HostID specifies the dedicated host on which the
2220+
instance should be started.
2221+
type: string
22082222
iamProfile:
22092223
description: The name of the IAM instance profile associated with
22102224
the instance, if applicable.

0 commit comments

Comments
 (0)