Skip to content

Commit

Permalink
✨ Add support to specify PlacementGroupPartition of placement group
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragkyal committed Mar 28, 2024
1 parent 25a0086 commit 7e79b8b
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1beta1/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
if restored.Status.Bastion != nil {
dst.Status.Bastion.InstanceMetadataOptions = restored.Status.Bastion.InstanceMetadataOptions
dst.Status.Bastion.PlacementGroupName = restored.Status.Bastion.PlacementGroupName
dst.Status.Bastion.PlacementGroupPartition = restored.Status.Bastion.PlacementGroupPartition
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
}
dst.Spec.Partition = restored.Spec.Partition
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Ignition = restored.Spec.Ignition
dst.Spec.InstanceMetadataOptions = restored.Spec.InstanceMetadataOptions
dst.Spec.PlacementGroupName = restored.Spec.PlacementGroupName
dst.Spec.PlacementGroupPartition = restored.Spec.PlacementGroupPartition
dst.Spec.PrivateDNSName = restored.Spec.PrivateDNSName
dst.Spec.SecurityGroupOverrides = restored.Spec.SecurityGroupOverrides

Expand Down Expand Up @@ -87,6 +88,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
dst.Spec.Template.Spec.InstanceMetadataOptions = restored.Spec.Template.Spec.InstanceMetadataOptions
dst.Spec.Template.Spec.PlacementGroupName = restored.Spec.Template.Spec.PlacementGroupName
dst.Spec.Template.Spec.PlacementGroupPartition = restored.Spec.Template.Spec.PlacementGroupPartition
dst.Spec.Template.Spec.PrivateDNSName = restored.Spec.Template.Spec.PrivateDNSName
dst.Spec.Template.Spec.SecurityGroupOverrides = restored.Spec.Template.Spec.SecurityGroupOverrides

Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/zz_generated.conversion.go

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

8 changes: 8 additions & 0 deletions api/v1beta2/awsmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ type AWSMachineSpec struct {
// +optional
PlacementGroupName string `json:"placementGroupName,omitempty"`

// PlacementGroupPartition is the partition number within the placement group in which to launch the instance.
// This value is only valid if the placement group, referred in `PlacementGroupName`, was created with
// strategy set to partition.
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:validation:Maximum:=7
// +optional
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`

// Tenancy indicates if instance should run on shared or single-tenant hardware.
// +optional
// +kubebuilder:validation:Enum:=default;dedicated;host
Expand Down
8 changes: 8 additions & 0 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ type Instance struct {
// +optional
PlacementGroupName string `json:"placementGroupName,omitempty"`

// PlacementGroupPartition is the partition number within the placement group in which to launch the instance.
// This value is only valid if the placement group, referred in `PlacementGroupName`, was created with
// strategy set to partition.
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:validation:Maximum:=7
// +optional
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`

// Tenancy indicates if instance should run on shared or single-tenant hardware.
// +optional
Tenancy string `json:"tenancy,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,15 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
placementGroupPartition:
description: PlacementGroupPartition is the partition number within
the placement group in which to launch the instance. This value
is only valid if the placement group, referred in `PlacementGroupName`,
was created with strategy set to partition.
format: int64
maximum: 7
minimum: 1
type: integer
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
Expand Down Expand Up @@ -2961,6 +2970,15 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
placementGroupPartition:
description: PlacementGroupPartition is the partition number within
the placement group in which to launch the instance. This value
is only valid if the placement group, referred in `PlacementGroupName`,
was created with strategy set to partition.
format: int64
maximum: 7
minimum: 1
type: integer
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,15 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
placementGroupPartition:
description: PlacementGroupPartition is the partition number within
the placement group in which to launch the instance. This value
is only valid if the placement group, referred in `PlacementGroupName`,
was created with strategy set to partition.
format: int64
maximum: 7
minimum: 1
type: integer
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,15 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
placementGroupPartition:
description: PlacementGroupPartition is the partition number within
the placement group in which to launch the instance. This value
is only valid if the placement group, referred in `PlacementGroupName`,
was created with strategy set to partition.
format: int64
maximum: 7
minimum: 1
type: integer
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,16 @@ spec:
description: PlacementGroupName specifies the name of the
placement group in which to launch the instance.
type: string
placementGroupPartition:
description: PlacementGroupPartition is the partition number
within the placement group in which to launch the instance.
This value is only valid if the placement group, referred
in `PlacementGroupName`, was created with strategy set to
partition.
format: int64
maximum: 7
minimum: 1
type: integer
privateDnsName:
description: PrivateDNSName is the options for the instance
hostname.
Expand Down
9 changes: 9 additions & 0 deletions pkg/cloud/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use

input.PlacementGroupName = scope.AWSMachine.Spec.PlacementGroupName

input.PlacementGroupPartition = scope.AWSMachine.Spec.PlacementGroupPartition

input.PrivateDNSName = scope.AWSMachine.Spec.PrivateDNSName

s.scope.Debug("Running instance", "machine-role", scope.Role())
Expand Down Expand Up @@ -610,11 +612,18 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
}
}

if i.PlacementGroupName == "" && i.PlacementGroupPartition != 0 {
return nil, errors.Errorf("placementGroupPartition is set but placementGroupName is empty")
}

if i.PlacementGroupName != "" {
if input.Placement == nil {
input.Placement = &ec2.Placement{}
}
input.Placement.GroupName = &i.PlacementGroupName
if i.PlacementGroupPartition != 0 {
input.Placement.PartitionNumber = &i.PlacementGroupPartition
}
}

out, err := s.EC2Client.RunInstancesWithContext(context.TODO(), input)
Expand Down
Loading

0 comments on commit 7e79b8b

Please sign in to comment.