Skip to content

Commit

Permalink
Add support to specifiy dedicated host ID and Affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
muraee committed Sep 11, 2024
1 parent abe918c commit bcf63a2
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/v1beta1/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +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.HostPlacement = restored.Status.Bastion.HostPlacement
}
dst.Spec.Partition = restored.Spec.Partition

Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ 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.HostPlacement = restored.Spec.HostPlacement

if restored.Spec.ElasticIPPool != nil {
if dst.Spec.ElasticIPPool == nil {
dst.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}
Expand Down Expand Up @@ -104,6 +106,8 @@ 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.HostPlacement = restored.Spec.Template.Spec.HostPlacement

if restored.Spec.Template.Spec.ElasticIPPool != nil {
if dst.Spec.Template.Spec.ElasticIPPool == nil {
dst.Spec.Template.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}
Expand Down
10 changes: 6 additions & 4 deletions api/v1beta1/zz_generated.conversion.go

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

32 changes: 31 additions & 1 deletion api/v1beta2/awsmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ const (
IgnitionStorageTypeOptionUnencryptedUserData = IgnitionStorageTypeOption("UnencryptedUserData")
)

// Tenancy defines the different tenancy options for EC2 instance.
type Tenancy string

const (
// TenancyDefault means that the EC2 instance will be launched into a shared host.
TenancyDefault = Tenancy("default")
// TenancyDedicated means that AWS will create and allocate a physical host for the EC2 instance (1 instance per host).
TenancyDedicated = Tenancy("dedicated")
// TenancyHost means that the EC2 instance will be launched into one of the user's pre-allocated physical hosts (multiple instances per host).
TenancyHost = Tenancy("host")
)

// AWSMachineSpec defines the desired state of an Amazon EC2 instance.
type AWSMachineSpec struct {
// ProviderID is the unique identifier as specified by the cloud provider.
Expand Down Expand Up @@ -186,9 +198,14 @@ type AWSMachineSpec struct {
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`

// Tenancy indicates if instance should run on shared or single-tenant hardware.
// If host tenancy is used and auto-placement is disabled for the Dedicated Host, It is required to set '.spec.hostPlacment.hostID'.
// +optional
// +kubebuilder:validation:Enum:=default;dedicated;host
Tenancy string `json:"tenancy,omitempty"`
Tenancy Tenancy `json:"tenancy,omitempty"`

// HostPlacement denotes the placement settings for the instance when tenancy=host.
// +optional
HostPlacement *HostPlacement `json:"hostPlacment,omitempty"`

// PrivateDNSName is the options for the instance hostname.
// +optional
Expand All @@ -199,6 +216,19 @@ type AWSMachineSpec struct {
CapacityReservationID *string `json:"capacityReservationId,omitempty"`
}

// HostPlacement denotes the placement settings for the instance when tenancy=host.
type HostPlacement struct {
// HostID pins the instance to a sepcific Dedicated Host.
// +optional
HostID *string `json:"hostID,omitempty"`

// Affinity indicates the affinity setting between the instance and a Dedicated Host.
// When affinity is set to host, an instance launched onto a specific host always restarts on the same host if stopped. This applies to both targeted and untargeted launches.
// +optional
// +kubebuilder:validation:Enum:=default;host
Affinity *string `json:"affinity,omitempty"`
}

// CloudInit defines options related to the bootstrapping systems where
// CloudInit is used.
type CloudInit struct {
Expand Down
6 changes: 5 additions & 1 deletion api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ type Instance struct {

// Tenancy indicates if instance should run on shared or single-tenant hardware.
// +optional
Tenancy string `json:"tenancy,omitempty"`
Tenancy Tenancy `json:"tenancy,omitempty"`

// HostPlacement denotes the placement settings for the instance when tenancy=host.
// +optional
HostPlacement *HostPlacement `json:"hostPlacment,omitempty"`

// IDs of the instance's volumes
// +optional
Expand Down
35 changes: 35 additions & 0 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 @@ -1133,6 +1133,23 @@ spec:
description: Specifies whether enhanced networking with ENA is
enabled.
type: boolean
hostPlacment:
description: HostPlacement denotes the placement settings for
the instance when tenancy=host.
properties:
affinity:
description: |-
Affinity indicates the affinity setting between the instance and a Dedicated Host.
When affinity is set to host, an instance launched onto a specific host always restarts on the same host if stopped. This applies to both targeted and untargeted launches.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
iamProfile:
description: The name of the IAM instance profile associated with
the instance, if applicable.
Expand Down Expand Up @@ -3177,6 +3194,23 @@ spec:
description: Specifies whether enhanced networking with ENA is
enabled.
type: boolean
hostPlacment:
description: HostPlacement denotes the placement settings for
the instance when tenancy=host.
properties:
affinity:
description: |-
Affinity indicates the affinity setting between the instance and a Dedicated Host.
When affinity is set to host, an instance launched onto a specific host always restarts on the same host if stopped. This applies to both targeted and untargeted launches.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
iamProfile:
description: The name of the IAM instance profile associated with
the instance, if applicable.
Expand Down
17 changes: 17 additions & 0 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,23 @@ spec:
description: Specifies whether enhanced networking with ENA is
enabled.
type: boolean
hostPlacment:
description: HostPlacement denotes the placement settings for
the instance when tenancy=host.
properties:
affinity:
description: |-
Affinity indicates the affinity setting between the instance and a Dedicated Host.
When affinity is set to host, an instance launched onto a specific host always restarts on the same host if stopped. This applies to both targeted and untargeted launches.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
iamProfile:
description: The name of the IAM instance profile associated with
the instance, if applicable.
Expand Down
22 changes: 20 additions & 2 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,23 @@ spec:
- message: allowed values are 'none' and 'amazon-pool'
rule: self in ['none','amazon-pool']
type: object
hostPlacment:
description: HostPlacement denotes the placement settings for the
instance when tenancy=host.
properties:
affinity:
description: |-
Affinity indicates the affinity setting between the instance and a Dedicated Host.
When affinity is set to host, an instance launched onto a specific host always restarts on the same host if stopped. This applies to both targeted and untargeted launches.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
iamInstanceProfile:
description: IAMInstanceProfile is a name of an IAM instance profile
to assign to the instance
Expand Down Expand Up @@ -1085,8 +1102,9 @@ spec:
type: string
type: object
tenancy:
description: Tenancy indicates if instance should run on shared or
single-tenant hardware.
description: |-
Tenancy indicates if instance should run on shared or single-tenant hardware.
If host tenancy is used and auto-placement is disabled for the Dedicated Host, It is required to set '.spec.hostPlacment.hostID'.
enum:
- default
- dedicated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,23 @@ spec:
- message: allowed values are 'none' and 'amazon-pool'
rule: self in ['none','amazon-pool']
type: object
hostPlacment:
description: HostPlacement denotes the placement settings
for the instance when tenancy=host.
properties:
affinity:
description: |-
Affinity indicates the affinity setting between the instance and a Dedicated Host.
When affinity is set to host, an instance launched onto a specific host always restarts on the same host if stopped. This applies to both targeted and untargeted launches.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
iamInstanceProfile:
description: IAMInstanceProfile is a name of an IAM instance
profile to assign to the instance
Expand Down Expand Up @@ -1022,8 +1039,9 @@ spec:
type: string
type: object
tenancy:
description: Tenancy indicates if instance should run on shared
or single-tenant hardware.
description: |-
Tenancy indicates if instance should run on shared or single-tenant hardware.
If host tenancy is used and auto-placement is disabled for the Dedicated Host, It is required to set '.spec.hostPlacment.hostID'.
enum:
- default
- dedicated
Expand Down
8 changes: 7 additions & 1 deletion pkg/cloud/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
input.InstanceMetadataOptions = scope.AWSMachine.Spec.InstanceMetadataOptions

input.Tenancy = scope.AWSMachine.Spec.Tenancy
input.HostPlacement = scope.AWSMachine.Spec.HostPlacement

input.PlacementGroupName = scope.AWSMachine.Spec.PlacementGroupName

Expand Down Expand Up @@ -653,7 +654,12 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan

if i.Tenancy != "" {
input.Placement = &ec2.Placement{
Tenancy: &i.Tenancy,
Tenancy: ptr.To(string(i.Tenancy)),
}

if i.Tenancy == infrav1.TenancyHost && i.HostPlacement != nil {
input.Placement.Affinity = i.HostPlacement.Affinity
input.Placement.HostId = i.HostPlacement.HostID
}
}

Expand Down

0 comments on commit bcf63a2

Please sign in to comment.