Skip to content

Commit 4b3f416

Browse files
authored
Merge pull request #4883 from chiragkyal/feature/add-partition-number
✨ Add support to specify PlacementGroupPartition of placement group
2 parents 240df04 + 7e79b8b commit 4b3f416

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
dst.Status.Bastion.PublicIPOnLaunch = restored.Status.Bastion.PublicIPOnLaunch
6162
}

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
@@ -222,6 +222,14 @@ type Instance struct {
222222
// +optional
223223
PlacementGroupName string `json:"placementGroupName,omitempty"`
224224

225+
// PlacementGroupPartition is the partition number within the placement group in which to launch the instance.
226+
// This value is only valid if the placement group, referred in `PlacementGroupName`, was created with
227+
// strategy set to partition.
228+
// +kubebuilder:validation:Minimum:=1
229+
// +kubebuilder:validation:Maximum:=7
230+
// +optional
231+
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`
232+
225233
// Tenancy indicates if instance should run on shared or single-tenant hardware.
226234
// +optional
227235
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:
@@ -2965,6 +2974,15 @@ spec:
29652974
description: PlacementGroupName specifies the name of the placement
29662975
group in which to launch the instance.
29672976
type: string
2977+
placementGroupPartition:
2978+
description: PlacementGroupPartition is the partition number within
2979+
the placement group in which to launch the instance. This value
2980+
is only valid if the placement group, referred in `PlacementGroupName`,
2981+
was created with strategy set to partition.
2982+
format: int64
2983+
maximum: 7
2984+
minimum: 1
2985+
type: integer
29682986
privateDnsName:
29692987
description: PrivateDNSName is the options for the instance hostname.
29702988
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
@@ -854,6 +854,15 @@ spec:
854854
description: PlacementGroupName specifies the name of the placement
855855
group in which to launch the instance.
856856
type: string
857+
placementGroupPartition:
858+
description: PlacementGroupPartition is the partition number within
859+
the placement group in which to launch the instance. This value
860+
is only valid if the placement group, referred in `PlacementGroupName`,
861+
was created with strategy set to partition.
862+
format: int64
863+
maximum: 7
864+
minimum: 1
865+
type: integer
857866
privateDnsName:
858867
description: PrivateDNSName is the options for the instance hostname.
859868
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
@@ -813,6 +813,16 @@ spec:
813813
description: PlacementGroupName specifies the name of the
814814
placement group in which to launch the instance.
815815
type: string
816+
placementGroupPartition:
817+
description: PlacementGroupPartition is the partition number
818+
within the placement group in which to launch the instance.
819+
This value is only valid if the placement group, referred
820+
in `PlacementGroupName`, was created with strategy set to
821+
partition.
822+
format: int64
823+
maximum: 7
824+
minimum: 1
825+
type: integer
816826
privateDnsName:
817827
description: PrivateDNSName is the options for the instance
818828
hostname.

pkg/cloud/services/ec2/instances.go

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

253253
input.PlacementGroupName = scope.AWSMachine.Spec.PlacementGroupName
254254

255+
input.PlacementGroupPartition = scope.AWSMachine.Spec.PlacementGroupPartition
256+
255257
input.PrivateDNSName = scope.AWSMachine.Spec.PrivateDNSName
256258

257259
s.scope.Debug("Running instance", "machine-role", scope.Role())
@@ -638,11 +640,18 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
638640
}
639641
}
640642

643+
if i.PlacementGroupName == "" && i.PlacementGroupPartition != 0 {
644+
return nil, errors.Errorf("placementGroupPartition is set but placementGroupName is empty")
645+
}
646+
641647
if i.PlacementGroupName != "" {
642648
if input.Placement == nil {
643649
input.Placement = &ec2.Placement{}
644650
}
645651
input.Placement.GroupName = &i.PlacementGroupName
652+
if i.PlacementGroupPartition != 0 {
653+
input.Placement.PartitionNumber = &i.PlacementGroupPartition
654+
}
646655
}
647656

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

0 commit comments

Comments
 (0)