Skip to content

Commit e5cbce2

Browse files
committed
Added dedicated host support for AWS
1 parent ff62d8d commit e5cbce2

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

manifests/0000_30_cluster-api_01_credentials-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ spec:
2525
- ec2:DescribeDhcpOptions
2626
- ec2:DescribeImages
2727
- ec2:DescribeInstances
28+
- ec2:DescribeInstanceTypes
2829
- ec2:DescribeInternetGateways
2930
- ec2:DescribeSecurityGroups
3031
- ec2:DescribeSubnets

pkg/conversion/capi2mapi/aws.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ var (
4141
)
4242

4343
const (
44-
errUnsupportedCAPATenancy = "unable to convert tenancy, unknown value"
45-
errUnsupportedCAPAMarketType = "unable to convert market type, unknown value"
46-
errUnsupportedHTTPTokensState = "unable to convert httpTokens state, unknown value" //nolint:gosec // This is an error message, not a credential
47-
defaultIdentityName = "default"
48-
defaultCredentialsSecretName = "aws-cloud-credentials" //#nosec G101 -- False positive, not actually a credential.
44+
errUnsupportedCAPATenancy = "unable to convert tenancy, unknown value"
45+
errUnsupportedCAPAMarketType = "unable to convert market type, unknown value"
46+
errUnsupportedHTTPTokensState = "unable to convert httpTokens state, unknown value" //nolint:gosec // This is an error message, not a credential
47+
defaultIdentityName = "default"
48+
defaultCredentialsSecretName = "aws-cloud-credentials" //#nosec G101 -- False positive, not actually a credential.
49+
errUnsupportedHostAffinityType = "unable to convert hostAffinity, unknown value"
4950
)
5051

5152
// machineAndAWSMachineAndAWSCluster stores the details of a Cluster API Machine and AWSMachine and AWSCluster.
@@ -167,6 +168,25 @@ func (m machineAndAWSMachineAndAWSCluster) toProviderSpec() (*mapiv1beta1.AWSMac
167168
MarketType: mapiAWSMarketType,
168169
}
169170

171+
// Dedicated host support
172+
if m.awsMachine.Spec.HostAffinity != nil {
173+
switch *m.awsMachine.Spec.HostAffinity {
174+
case "host":
175+
mapaProviderConfig.HostPlacement = &mapiv1beta1.HostPlacement{
176+
Affinity: ptr.To(mapiv1beta1.HostAffinityDedicatedHost),
177+
DedicatedHost: &mapiv1beta1.DedicatedHost{
178+
ID: *m.awsMachine.Spec.HostID,
179+
},
180+
}
181+
case "default":
182+
mapaProviderConfig.HostPlacement = &mapiv1beta1.HostPlacement{
183+
Affinity: ptr.To(mapiv1beta1.HostAffinityAnyAvailable),
184+
}
185+
default:
186+
errors = append(errors, field.Invalid(fldPath.Child("hostAffinity"), m.awsMachine.Spec.HostAffinity, errUnsupportedHostAffinityType))
187+
}
188+
}
189+
170190
secretRef, errs := handleAWSIdentityRef(fldPath.Child("identityRef"), m.awsCluster.Spec.IdentityRef)
171191

172192
if len(errs) > 0 {

pkg/conversion/mapi2capi/aws.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ func (m *awsMachineAndInfra) toAWSMachine(providerSpec mapiv1beta1.AWSMachinePro
285285
MarketType: capiAWSMarketType,
286286
}
287287

288+
// Dedicated host support
289+
if providerSpec.HostPlacement != nil {
290+
dhPath := fldPath.Child("hostPlacement")
291+
placement := providerSpec.HostPlacement
292+
switch *placement.Affinity {
293+
case mapiv1beta1.HostAffinityAnyAvailable:
294+
spec.HostAffinity = ptr.To("default")
295+
case mapiv1beta1.HostAffinityDedicatedHost:
296+
if placement.DedicatedHost != nil {
297+
spec.HostAffinity = ptr.To("host")
298+
spec.HostID = ptr.To(placement.DedicatedHost.ID)
299+
} else {
300+
errs = append(errs, field.Required(dhPath.Child("dedicatedHost"), "affinity DedicatedHost requires dedicatedHost field to be set"))
301+
}
302+
default:
303+
}
304+
}
305+
288306
if providerSpec.CapacityReservationID != "" {
289307
spec.CapacityReservationID = &providerSpec.CapacityReservationID
290308
}

0 commit comments

Comments
 (0)