Skip to content

Commit 7862de6

Browse files
authored
Merge pull request #4273 from vincepri/add-placement-group-name
✨ Add support to specify PlacementGroup Name in instances
2 parents c18c8d3 + 26ef70a commit 7862de6

11 files changed

+202
-2
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
4646
dst.Spec.S3Bucket = restored.Spec.S3Bucket
4747
if restored.Status.Bastion != nil {
4848
dst.Status.Bastion.InstanceMetadataOptions = restored.Status.Bastion.InstanceMetadataOptions
49+
dst.Status.Bastion.PlacementGroupName = restored.Status.Bastion.PlacementGroupName
4950
}
5051
dst.Spec.Partition = restored.Spec.Partition
5152

api/v1beta1/awsmachine_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
3737

3838
dst.Spec.Ignition = restored.Spec.Ignition
3939
dst.Spec.InstanceMetadataOptions = restored.Spec.InstanceMetadataOptions
40+
dst.Spec.PlacementGroupName = restored.Spec.PlacementGroupName
4041

4142
return nil
4243
}
@@ -83,6 +84,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
8384
dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta
8485
dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
8586
dst.Spec.Template.Spec.InstanceMetadataOptions = restored.Spec.Template.Spec.InstanceMetadataOptions
87+
dst.Spec.Template.Spec.PlacementGroupName = restored.Spec.Template.Spec.PlacementGroupName
8688

8789
return nil
8890
}

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ type AWSMachineSpec struct {
152152
// +optional
153153
SpotMarketOptions *SpotMarketOptions `json:"spotMarketOptions,omitempty"`
154154

155+
// PlacementGroupName specifies the name of the placement group in which to launch the instance.
156+
// +optional
157+
PlacementGroupName string `json:"placementGroupName,omitempty"`
158+
155159
// Tenancy indicates if instance should run on shared or single-tenant hardware.
156160
// +optional
157161
// +kubebuilder:validation:Enum:=default;dedicated;host

api/v1beta2/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ type Instance struct {
194194
// SpotMarketOptions option for configuring instances to be run using AWS Spot instances.
195195
SpotMarketOptions *SpotMarketOptions `json:"spotMarketOptions,omitempty"`
196196

197+
// PlacementGroupName specifies the name of the placement group in which to launch the instance.
198+
// +optional
199+
PlacementGroupName string `json:"placementGroupName,omitempty"`
200+
197201
// Tenancy indicates if instance should run on shared or single-tenant hardware.
198202
// +optional
199203
Tenancy string `json:"tenancy,omitempty"`

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,10 @@ spec:
949949
- size
950950
type: object
951951
type: array
952+
placementGroupName:
953+
description: PlacementGroupName specifies the name of the placement
954+
group in which to launch the instance.
955+
type: string
952956
privateIp:
953957
description: The private IPv4 address assigned to the instance.
954958
type: string
@@ -2371,6 +2375,10 @@ spec:
23712375
- size
23722376
type: object
23732377
type: array
2378+
placementGroupName:
2379+
description: PlacementGroupName specifies the name of the placement
2380+
group in which to launch the instance.
2381+
type: string
23742382
privateIp:
23752383
description: The private IPv4 address assigned to the instance.
23762384
type: string

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,10 @@ spec:
14411441
- size
14421442
type: object
14431443
type: array
1444+
placementGroupName:
1445+
description: PlacementGroupName specifies the name of the placement
1446+
group in which to launch the instance.
1447+
type: string
14441448
privateIp:
14451449
description: The private IPv4 address assigned to the instance.
14461450
type: string

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ spec:
772772
- size
773773
type: object
774774
type: array
775+
placementGroupName:
776+
description: PlacementGroupName specifies the name of the placement
777+
group in which to launch the instance.
778+
type: string
775779
providerID:
776780
description: ProviderID is the unique identifier as specified by the
777781
cloud provider.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ spec:
726726
- size
727727
type: object
728728
type: array
729+
placementGroupName:
730+
description: PlacementGroupName specifies the name of the
731+
placement group in which to launch the instance.
732+
type: string
729733
providerID:
730734
description: ProviderID is the unique identifier as specified
731735
by the cloud provider.

pkg/cloud/services/ec2/instances.go

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

236236
input.Tenancy = scope.AWSMachine.Spec.Tenancy
237237

238+
input.PlacementGroupName = scope.AWSMachine.Spec.PlacementGroupName
239+
238240
s.scope.Debug("Running instance", "machine-role", scope.Role())
239241
s.scope.Debug("Running instance with instance metadata options", "metadata options", input.InstanceMetadataOptions)
240242
out, err := s.runInstance(scope.Role(), input)
@@ -588,6 +590,13 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
588590
}
589591
}
590592

593+
if i.PlacementGroupName != "" {
594+
if input.Placement == nil {
595+
input.Placement = &ec2.Placement{}
596+
}
597+
input.Placement.GroupName = &i.PlacementGroupName
598+
}
599+
591600
out, err := s.EC2Client.RunInstances(input)
592601
if err != nil {
593602
return nil, errors.Wrap(err, "failed to run instance")

0 commit comments

Comments
 (0)