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

[release-4.16] OCPBUGS-39522: UPSTREAM: <carry>: Add support to specify PlacementGroupPartition of placement group, Ensure Volumes and Network Interfaces are also tagged when created as part of instance creation #521

Open
wants to merge 1 commit into
base: release-4.16
Choose a base branch
from
Open
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
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
dst.Status.Bastion.PublicIPOnLaunch = restored.Status.Bastion.PublicIPOnLaunch
}
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"`

// 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 @@ -222,6 +222,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 @@ -2965,6 +2974,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 @@ -854,6 +854,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 @@ -813,6 +813,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
41 changes: 27 additions & 14 deletions pkg/cloud/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,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 @@ -611,21 +613,25 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
}

if len(i.Tags) > 0 {
spec := &ec2.TagSpecification{ResourceType: aws.String(ec2.ResourceTypeInstance)}
// We need to sort keys for tests to work
keys := make([]string, 0, len(i.Tags))
for k := range i.Tags {
keys = append(keys, k)
}
sort.Strings(keys)
for _, key := range keys {
spec.Tags = append(spec.Tags, &ec2.Tag{
Key: aws.String(key),
Value: aws.String(i.Tags[key]),
})
}
resources := []string{ec2.ResourceTypeInstance, ec2.ResourceTypeVolume, ec2.ResourceTypeNetworkInterface}
for _, r := range resources {
spec := &ec2.TagSpecification{ResourceType: aws.String(r)}

// We need to sort keys for tests to work
keys := make([]string, 0, len(i.Tags))
for k := range i.Tags {
keys = append(keys, k)
}
sort.Strings(keys)
for _, key := range keys {
spec.Tags = append(spec.Tags, &ec2.Tag{
Key: aws.String(key),
Value: aws.String(i.Tags[key]),
})
}

input.TagSpecifications = append(input.TagSpecifications, spec)
input.TagSpecifications = append(input.TagSpecifications, spec)
}
}

input.InstanceMarketOptions = getInstanceMarketOptionsRequest(i.SpotMarketOptions)
Expand All @@ -638,11 +644,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