Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support to specify PlacementGroupPartition of placement group #4883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add this new filed in v1beta1 as we would be going to deprecate that soon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that makes sense. I'm wondering if CI tests would complain if I remove the conversion. If that's not the case, then we can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failed after I removed the conversion. Can you please suggest what should be the correct approach here?

--- FAIL: TestFuzzyConversion (59.20s)
    --- FAIL: TestFuzzyConversion/for_AWSCluster (18.80s)
        --- PASS: TestFuzzyConversion/for_AWSCluster/spoke-hub-spoke (18.79s)
        --- FAIL: TestFuzzyConversion/for_AWSCluster/hub-spoke-hub (0.01s)
    --- FAIL: TestFuzzyConversion/for_AWSMachine (17.20s)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just leave this generated conversion in place if it is causing issues? I guess if we deprecate v1beta1, it won't matter either way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be better, since it's causing the CI tests failure. I've added back the conversion.

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"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should have been int32


// 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