Skip to content

Commit 7e79b8b

Browse files
committed
✨ Add support to specify PlacementGroupPartition of placement group
1 parent 25a0086 commit 7e79b8b

11 files changed

+319
-0
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
5656
if restored.Status.Bastion != nil {
5757
dst.Status.Bastion.InstanceMetadataOptions = restored.Status.Bastion.InstanceMetadataOptions
5858
dst.Status.Bastion.PlacementGroupName = restored.Status.Bastion.PlacementGroupName
59+
dst.Status.Bastion.PlacementGroupPartition = restored.Status.Bastion.PlacementGroupPartition
5960
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
6061
}
6162
dst.Spec.Partition = restored.Spec.Partition

api/v1beta1/awsmachine_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
3838
dst.Spec.Ignition = restored.Spec.Ignition
3939
dst.Spec.InstanceMetadataOptions = restored.Spec.InstanceMetadataOptions
4040
dst.Spec.PlacementGroupName = restored.Spec.PlacementGroupName
41+
dst.Spec.PlacementGroupPartition = restored.Spec.PlacementGroupPartition
4142
dst.Spec.PrivateDNSName = restored.Spec.PrivateDNSName
4243
dst.Spec.SecurityGroupOverrides = restored.Spec.SecurityGroupOverrides
4344

@@ -87,6 +88,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
8788
dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
8889
dst.Spec.Template.Spec.InstanceMetadataOptions = restored.Spec.Template.Spec.InstanceMetadataOptions
8990
dst.Spec.Template.Spec.PlacementGroupName = restored.Spec.Template.Spec.PlacementGroupName
91+
dst.Spec.Template.Spec.PlacementGroupPartition = restored.Spec.Template.Spec.PlacementGroupPartition
9092
dst.Spec.Template.Spec.PrivateDNSName = restored.Spec.Template.Spec.PrivateDNSName
9193
dst.Spec.Template.Spec.SecurityGroupOverrides = restored.Spec.Template.Spec.SecurityGroupOverrides
9294

api/v1beta1/zz_generated.conversion.go

Lines changed: 2 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ type AWSMachineSpec struct {
172172
// +optional
173173
PlacementGroupName string `json:"placementGroupName,omitempty"`
174174

175+
// PlacementGroupPartition is the partition number within the placement group in which to launch the instance.
176+
// This value is only valid if the placement group, referred in `PlacementGroupName`, was created with
177+
// strategy set to partition.
178+
// +kubebuilder:validation:Minimum:=1
179+
// +kubebuilder:validation:Maximum:=7
180+
// +optional
181+
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`
182+
175183
// Tenancy indicates if instance should run on shared or single-tenant hardware.
176184
// +optional
177185
// +kubebuilder:validation:Enum:=default;dedicated;host

api/v1beta2/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ type Instance struct {
221221
// +optional
222222
PlacementGroupName string `json:"placementGroupName,omitempty"`
223223

224+
// PlacementGroupPartition is the partition number within the placement group in which to launch the instance.
225+
// This value is only valid if the placement group, referred in `PlacementGroupName`, was created with
226+
// strategy set to partition.
227+
// +kubebuilder:validation:Minimum:=1
228+
// +kubebuilder:validation:Maximum:=7
229+
// +optional
230+
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`
231+
224232
// Tenancy indicates if instance should run on shared or single-tenant hardware.
225233
// +optional
226234
Tenancy string `json:"tenancy,omitempty"`

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,15 @@ spec:
11091109
description: PlacementGroupName specifies the name of the placement
11101110
group in which to launch the instance.
11111111
type: string
1112+
placementGroupPartition:
1113+
description: PlacementGroupPartition is the partition number within
1114+
the placement group in which to launch the instance. This value
1115+
is only valid if the placement group, referred in `PlacementGroupName`,
1116+
was created with strategy set to partition.
1117+
format: int64
1118+
maximum: 7
1119+
minimum: 1
1120+
type: integer
11121121
privateDnsName:
11131122
description: PrivateDNSName is the options for the instance hostname.
11141123
properties:
@@ -2961,6 +2970,15 @@ spec:
29612970
description: PlacementGroupName specifies the name of the placement
29622971
group in which to launch the instance.
29632972
type: string
2973+
placementGroupPartition:
2974+
description: PlacementGroupPartition is the partition number within
2975+
the placement group in which to launch the instance. This value
2976+
is only valid if the placement group, referred in `PlacementGroupName`,
2977+
was created with strategy set to partition.
2978+
format: int64
2979+
maximum: 7
2980+
minimum: 1
2981+
type: integer
29642982
privateDnsName:
29652983
description: PrivateDNSName is the options for the instance hostname.
29662984
properties:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,15 @@ spec:
18841884
description: PlacementGroupName specifies the name of the placement
18851885
group in which to launch the instance.
18861886
type: string
1887+
placementGroupPartition:
1888+
description: PlacementGroupPartition is the partition number within
1889+
the placement group in which to launch the instance. This value
1890+
is only valid if the placement group, referred in `PlacementGroupName`,
1891+
was created with strategy set to partition.
1892+
format: int64
1893+
maximum: 7
1894+
minimum: 1
1895+
type: integer
18871896
privateDnsName:
18881897
description: PrivateDNSName is the options for the instance hostname.
18891898
properties:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,15 @@ spec:
802802
description: PlacementGroupName specifies the name of the placement
803803
group in which to launch the instance.
804804
type: string
805+
placementGroupPartition:
806+
description: PlacementGroupPartition is the partition number within
807+
the placement group in which to launch the instance. This value
808+
is only valid if the placement group, referred in `PlacementGroupName`,
809+
was created with strategy set to partition.
810+
format: int64
811+
maximum: 7
812+
minimum: 1
813+
type: integer
805814
privateDnsName:
806815
description: PrivateDNSName is the options for the instance hostname.
807816
properties:

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,16 @@ spec:
758758
description: PlacementGroupName specifies the name of the
759759
placement group in which to launch the instance.
760760
type: string
761+
placementGroupPartition:
762+
description: PlacementGroupPartition is the partition number
763+
within the placement group in which to launch the instance.
764+
This value is only valid if the placement group, referred
765+
in `PlacementGroupName`, was created with strategy set to
766+
partition.
767+
format: int64
768+
maximum: 7
769+
minimum: 1
770+
type: integer
761771
privateDnsName:
762772
description: PrivateDNSName is the options for the instance
763773
hostname.

pkg/cloud/services/ec2/instances.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
236236

237237
input.PlacementGroupName = scope.AWSMachine.Spec.PlacementGroupName
238238

239+
input.PlacementGroupPartition = scope.AWSMachine.Spec.PlacementGroupPartition
240+
239241
input.PrivateDNSName = scope.AWSMachine.Spec.PrivateDNSName
240242

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

615+
if i.PlacementGroupName == "" && i.PlacementGroupPartition != 0 {
616+
return nil, errors.Errorf("placementGroupPartition is set but placementGroupName is empty")
617+
}
618+
613619
if i.PlacementGroupName != "" {
614620
if input.Placement == nil {
615621
input.Placement = &ec2.Placement{}
616622
}
617623
input.Placement.GroupName = &i.PlacementGroupName
624+
if i.PlacementGroupPartition != 0 {
625+
input.Placement.PartitionNumber = &i.PlacementGroupPartition
626+
}
618627
}
619628

620629
out, err := s.EC2Client.RunInstancesWithContext(context.TODO(), input)

0 commit comments

Comments
 (0)