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 4, 2024
1 parent abe918c commit 544d83b
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 7 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.DedicatedHostPlacement = restored.Status.Bastion.DedicatedHostPlacement
}
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.DedicatedHostPlacement = restored.Spec.DedicatedHostPlacement

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.DedicatedHostPlacement = restored.Spec.Template.Spec.DedicatedHostPlacement

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.

30 changes: 29 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 @@ -188,7 +200,11 @@ type AWSMachineSpec struct {
// Tenancy indicates if instance should run on shared or single-tenant hardware.
// +optional
// +kubebuilder:validation:Enum:=default;dedicated;host
Tenancy string `json:"tenancy,omitempty"`
Tenancy Tenancy `json:"tenancy,omitempty"`

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

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

// DedicatedHostPlacement denotes the placement settings for the instance when tenancy=host
type DedicatedHostPlacement 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.
// +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"`

// DedicatedHostPlacement denotes the placement settings for the instance when tenancy=host
// +optional
DedicatedHostPlacement *DedicatedHostPlacement `json:"dedicatedHostPlacment,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 @@ -1125,6 +1125,22 @@ spec:
description: CapacityReservationID specifies the target Capacity
Reservation into which the instance should be launched.
type: string
dedicatedHostPlacment:
description: DedicatedHostPlacement 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.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
ebsOptimized:
description: Indicates whether the instance is optimized for Amazon
EBS I/O.
Expand Down Expand Up @@ -3169,6 +3185,22 @@ spec:
description: CapacityReservationID specifies the target Capacity
Reservation into which the instance should be launched.
type: string
dedicatedHostPlacment:
description: DedicatedHostPlacement 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.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
ebsOptimized:
description: Indicates whether the instance is optimized for Amazon
EBS I/O.
Expand Down
16 changes: 16 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 @@ -2110,6 +2110,22 @@ spec:
description: CapacityReservationID specifies the target Capacity
Reservation into which the instance should be launched.
type: string
dedicatedHostPlacment:
description: DedicatedHostPlacement 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.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
ebsOptimized:
description: Indicates whether the instance is optimized for Amazon
EBS I/O.
Expand Down
16 changes: 16 additions & 0 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,22 @@ spec:
- ssm-parameter-store
type: string
type: object
dedicatedHostPlacment:
description: DedicatedHostPlacement 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.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
elasticIpPool:
description: ElasticIPPool is the configuration to allocate Public
IPv4 address (Elastic IP/EIP) from user-defined pool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,22 @@ spec:
- ssm-parameter-store
type: string
type: object
dedicatedHostPlacment:
description: DedicatedHostPlacement 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.
enum:
- default
- host
type: string
hostID:
description: HostID pins the instance to a sepcific Dedicated
Host.
type: string
type: object
elasticIpPool:
description: ElasticIPPool is the configuration to allocate
Public IPv4 address (Elastic IP/EIP) from user-defined pool.
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.DedicatedHostPlacement = scope.AWSMachine.Spec.DedicatedHostPlacement

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.DedicatedHostPlacement != nil {
input.Placement.Affinity = i.DedicatedHostPlacement.Affinity
input.Placement.HostId = i.DedicatedHostPlacement.HostID
}
}

Expand Down

0 comments on commit 544d83b

Please sign in to comment.