Skip to content

Commit c2cee83

Browse files
faermanjrvanderp3
authored andcommitted
Draft dedicated hosts implementation
1 parent b925771 commit c2cee83

19 files changed

+384
-0
lines changed

api/v1beta1/awscluster_conversion.go

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

api/v1beta1/awsmachine_conversion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
4343
dst.Spec.SecurityGroupOverrides = restored.Spec.SecurityGroupOverrides
4444
dst.Spec.CapacityReservationID = restored.Spec.CapacityReservationID
4545
dst.Spec.MarketType = restored.Spec.MarketType
46+
dst.Spec.HostID = restored.Spec.HostID
47+
dst.Spec.HostAffinity = restored.Spec.HostAffinity
4648
dst.Spec.NetworkInterfaceType = restored.Spec.NetworkInterfaceType
4749
if restored.Spec.ElasticIPPool != nil {
4850
if dst.Spec.ElasticIPPool == nil {
@@ -107,6 +109,8 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
107109
dst.Spec.Template.Spec.SecurityGroupOverrides = restored.Spec.Template.Spec.SecurityGroupOverrides
108110
dst.Spec.Template.Spec.CapacityReservationID = restored.Spec.Template.Spec.CapacityReservationID
109111
dst.Spec.Template.Spec.MarketType = restored.Spec.Template.Spec.MarketType
112+
dst.Spec.Template.Spec.HostID = restored.Spec.Template.Spec.HostID
113+
dst.Spec.Template.Spec.HostAffinity = restored.Spec.Template.Spec.HostAffinity
110114
dst.Spec.Template.Spec.NetworkInterfaceType = restored.Spec.Template.Spec.NetworkInterfaceType
111115
if restored.Spec.Template.Spec.ElasticIPPool != nil {
112116
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
@@ -223,6 +223,18 @@ type AWSMachineSpec struct {
223223
// If marketType is not specified and spotMarketOptions is provided, the marketType defaults to "Spot".
224224
// +optional
225225
MarketType MarketType `json:"marketType,omitempty"`
226+
227+
// HostID specifies the Dedicated Host on which the instance must be started.
228+
// +optional
229+
HostID *string `json:"hostID,omitempty"`
230+
231+
// HostAffinity specifies the dedicated host affinity setting for the instance.
232+
// When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
233+
// When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
234+
// When HostAffinity is defined, HostID is required.
235+
// +optional
236+
// +kubebuilder:validation:Enum:=default;host
237+
HostAffinity *string `json:"hostAffinity,omitempty"`
226238
}
227239

228240
// 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
@@ -64,6 +64,7 @@ func (r *AWSMachine) ValidateCreate() (admission.Warnings, error) {
6464
allErrs = append(allErrs, r.validateNonRootVolumes()...)
6565
allErrs = append(allErrs, r.validateSSHKeyName()...)
6666
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
67+
allErrs = append(allErrs, r.validateHostAffinity()...)
6768
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
6869
allErrs = append(allErrs, r.validateNetworkElasticIPPool()...)
6970
allErrs = append(allErrs, r.validateInstanceMarketType()...)
@@ -91,6 +92,7 @@ func (r *AWSMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, err
9192
allErrs = append(allErrs, r.validateCloudInitSecret()...)
9293
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
9394
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
95+
allErrs = append(allErrs, r.validateHostAffinity()...)
9496

9597
newAWSMachineSpec := newAWSMachine["spec"].(map[string]interface{})
9698
oldAWSMachineSpec := oldAWSMachine["spec"].(map[string]interface{})
@@ -433,6 +435,17 @@ func (r *AWSMachine) validateAdditionalSecurityGroups() field.ErrorList {
433435
return allErrs
434436
}
435437

438+
func (r *AWSMachine) validateHostAffinity() field.ErrorList {
439+
var allErrs field.ErrorList
440+
441+
if r.Spec.HostAffinity != nil {
442+
if r.Spec.HostID == nil || len(*r.Spec.HostID) == 0 {
443+
allErrs = append(allErrs, field.Required(field.NewPath("spec.hostID"), "hostID must be set when hostAffinity is configured"))
444+
}
445+
}
446+
return allErrs
447+
}
448+
436449
func (r *AWSMachine) validateSSHKeyName() field.ErrorList {
437450
return validateSSHKeyName(r.Spec.SSHKeyName)
438451
}

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,37 @@ func TestAWSMachineCreate(t *testing.T) {
411411
},
412412
wantErr: true,
413413
},
414+
{
415+
name: "configure host affinity with Host ID",
416+
machine: &AWSMachine{
417+
Spec: AWSMachineSpec{
418+
InstanceType: "test",
419+
HostAffinity: ptr.To("default"),
420+
HostID: ptr.To("h-09dcf61cb388b0149"),
421+
},
422+
},
423+
wantErr: false,
424+
},
425+
{
426+
name: "configure host affinity with invalid affinity",
427+
machine: &AWSMachine{
428+
Spec: AWSMachineSpec{
429+
InstanceType: "test",
430+
HostAffinity: ptr.To("invalid"),
431+
},
432+
},
433+
wantErr: true,
434+
},
435+
{
436+
name: "configure host affinity without Host ID",
437+
machine: &AWSMachine{
438+
Spec: AWSMachineSpec{
439+
InstanceType: "test",
440+
HostAffinity: ptr.To("default"),
441+
},
442+
},
443+
wantErr: true,
444+
},
414445
{
415446
name: "create with valid BYOIPv4",
416447
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
@@ -1213,6 +1213,20 @@ spec:
12131213
description: Specifies whether enhanced networking with ENA is
12141214
enabled.
12151215
type: boolean
1216+
hostAffinity:
1217+
description: |-
1218+
HostAffinity specifies the dedicated host affinity setting for the instance.
1219+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
1220+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
1221+
When HostAffinity is defined, HostID is required.
1222+
enum:
1223+
- default
1224+
- host
1225+
type: string
1226+
hostID:
1227+
description: HostID specifies the dedicated host on which the
1228+
instance should be started.
1229+
type: string
12161230
iamProfile:
12171231
description: The name of the IAM instance profile associated with
12181232
the instance, if applicable.
@@ -3378,6 +3392,20 @@ spec:
33783392
description: Specifies whether enhanced networking with ENA is
33793393
enabled.
33803394
type: boolean
3395+
hostAffinity:
3396+
description: |-
3397+
HostAffinity specifies the dedicated host affinity setting for the instance.
3398+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
3399+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
3400+
When HostAffinity is defined, HostID is required.
3401+
enum:
3402+
- default
3403+
- host
3404+
type: string
3405+
hostID:
3406+
description: HostID specifies the dedicated host on which the
3407+
instance should be started.
3408+
type: string
33813409
iamProfile:
33823410
description: The name of the IAM instance profile associated with
33833411
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
@@ -2180,6 +2180,20 @@ spec:
21802180
description: Specifies whether enhanced networking with ENA is
21812181
enabled.
21822182
type: boolean
2183+
hostAffinity:
2184+
description: |-
2185+
HostAffinity specifies the dedicated host affinity setting for the instance.
2186+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
2187+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
2188+
When HostAffinity is defined, HostID is required.
2189+
enum:
2190+
- default
2191+
- host
2192+
type: string
2193+
hostID:
2194+
description: HostID specifies the dedicated host on which the
2195+
instance should be started.
2196+
type: string
21832197
iamProfile:
21842198
description: The name of the IAM instance profile associated with
21852199
the instance, if applicable.

0 commit comments

Comments
 (0)