diff --git a/pkg/actuators/machine/instances.go b/pkg/actuators/machine/instances.go index 84c519328..d66e51953 100644 --- a/pkg/actuators/machine/instances.go +++ b/pkg/actuators/machine/instances.go @@ -592,6 +592,10 @@ func constructInstancePlacement(machine *machinev1beta1.Machine, machineProvider if machineProviderConfig.PlacementGroupName != "" { placement.GroupName = &machineProviderConfig.PlacementGroupName + + if machineProviderConfig.PlacementGroupPartition != 0 { + placement.PartitionNumber = aws.Int64(int64(machineProviderConfig.PlacementGroupPartition)) + } } instanceTenancy := machineProviderConfig.Placement.Tenancy diff --git a/pkg/actuators/machine/instances_test.go b/pkg/actuators/machine/instances_test.go index d45ec317b..cd9e3440a 100644 --- a/pkg/actuators/machine/instances_test.go +++ b/pkg/actuators/machine/instances_test.go @@ -1029,6 +1029,42 @@ func TestLaunchInstance(t *testing.T) { }, }, }, + { + name: "With custom placement group name and partition number", + providerConfig: stubInstancePlacementGroupPartition("placement-group1", 4), + subnetOutput: stubDescribeSubnetsOutputProvided(aws.StringValue(providerConfig.Subnet.ID)), + zonesOutput: stubDescribeAvailabilityZonesOutputDefault(), + runInstancesInput: &ec2.RunInstancesInput{ + IamInstanceProfile: &ec2.IamInstanceProfileSpecification{ + Name: aws.String(*providerConfig.IAMInstanceProfile.ID), + }, + ImageId: aws.String(*providerConfig.AMI.ID), + InstanceType: &providerConfig.InstanceType, + MinCount: aws.Int64(1), + MaxCount: aws.Int64(1), + KeyName: providerConfig.KeyName, + TagSpecifications: []*ec2.TagSpecification{{ + ResourceType: aws.String("instance"), + Tags: stubTagList, + }, { + ResourceType: aws.String("volume"), + Tags: stubTagList, + }}, + NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{ + { + DeviceIndex: aws.Int64(providerConfig.DeviceIndex), + AssociatePublicIpAddress: providerConfig.PublicIP, + SubnetId: providerConfig.Subnet.ID, + Groups: stubSecurityGroupsDefault, + }, + }, + UserData: aws.String(""), + Placement: &ec2.Placement{ + GroupName: aws.String("placement-group1"), + PartitionNumber: aws.Int64(4), + }, + }, + }, { name: "Wavelength Zone with Public IP", providerConfig: stubProviderConfigCustomized(&stubInput{ diff --git a/pkg/actuators/machine/stubs.go b/pkg/actuators/machine/stubs.go index f2d8e5448..23c134342 100644 --- a/pkg/actuators/machine/stubs.go +++ b/pkg/actuators/machine/stubs.go @@ -360,6 +360,13 @@ func stubInstancePlacementGroupName(placementGroupName string) *machinev1beta1.A return pc } +func stubInstancePlacementGroupPartition(placementGroupName string, partitionNumber int32) *machinev1beta1.AWSMachineProviderConfig { + pc := stubProviderConfig() + pc.PlacementGroupName = placementGroupName + pc.PlacementGroupPartition = partitionNumber + return pc +} + func stubEFANetworkInterfaceType() *machinev1beta1.AWSMachineProviderConfig { pc := stubProviderConfig() pc.NetworkInterfaceType = machinev1beta1.AWSEFANetworkInterfaceType