Skip to content

Commit 60f648d

Browse files
committed
Added dedicated host support for AWS
1 parent 5ae2d9c commit 60f648d

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

pkg/conversion/capi2mapi/aws.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ var (
3737
)
3838

3939
const (
40-
errUnsupportedCAPATenancy = "unable to convert tenancy, unknown value"
41-
errUnsupportedCAPAMarketType = "unable to convert market type, unknown value"
42-
errUnsupportedHTTPTokensState = "unable to convert httpTokens state, unknown value" //nolint:gosec // This is an error message, not a credential
43-
defaultIdentityName = "default"
44-
defaultCredentialsSecretName = "aws-cloud-credentials" //#nosec G101 -- False positive, not actually a credential.
40+
errUnsupportedCAPATenancy = "unable to convert tenancy, unknown value"
41+
errUnsupportedCAPAMarketType = "unable to convert market type, unknown value"
42+
errUnsupportedHTTPTokensState = "unable to convert httpTokens state, unknown value" //nolint:gosec // This is an error message, not a credential
43+
defaultIdentityName = "default"
44+
defaultCredentialsSecretName = "aws-cloud-credentials" //#nosec G101 -- False positive, not actually a credential.
45+
errUnsupportedHostAffinityType = "unable to convert hostAffinity, unknown value"
4546
)
4647

4748
// machineAndAWSMachineAndAWSCluster stores the details of a Cluster API Machine and AWSMachine and AWSCluster.
@@ -156,6 +157,21 @@ func (m machineAndAWSMachineAndAWSCluster) toProviderSpec() (*mapiv1.AWSMachineP
156157
MarketType: mapiAWSMarketType,
157158
}
158159

160+
// Dedicated host support
161+
if m.awsMachine.Spec.HostID != nil {
162+
mapaProviderConfig.HostID = m.awsMachine.Spec.HostID
163+
}
164+
if m.awsMachine.Spec.HostAffinity != nil {
165+
switch *m.awsMachine.Spec.HostAffinity {
166+
case "host":
167+
*mapaProviderConfig.HostAffinity = mapiv1.HostAffinityHost
168+
case "default":
169+
*mapaProviderConfig.HostAffinity = mapiv1.HostAffinityAnyAvailable
170+
default:
171+
errors = append(errors, field.Invalid(fldPath.Child("hostAffinity"), m.awsMachine.Spec.HostAffinity, errUnsupportedHostAffinityType))
172+
}
173+
}
174+
159175
secretRef, errs := handleAWSIdentityRef(fldPath.Child("identityRef"), m.awsCluster.Spec.IdentityRef)
160176

161177
if len(errs) > 0 {
@@ -525,6 +541,15 @@ func handleUnsupportedAWSMachineFields(fldPath *field.Path, spec awsv1.AWSMachin
525541
errs = append(errs, field.Invalid(fldPath.Child("privateDNSName"), spec.PrivateDNSName, "privateDNSName is not supported"))
526542
}
527543

544+
// Unsupported new fields in newer CAPA versions
545+
if spec.ElasticIPPool != nil {
546+
errs = append(errs, field.Invalid(fldPath.Child("elasticIpPool"), spec.ElasticIPPool, "elasticIpPool is not supported"))
547+
}
548+
549+
if spec.CapacityReservationPreference != "" {
550+
errs = append(errs, field.Invalid(fldPath.Child("capacityReservationPreference"), spec.CapacityReservationPreference, "capacityReservationPreference is not supported"))
551+
}
552+
528553
if spec.Ignition != nil {
529554
if spec.Ignition.Proxy != nil {
530555
// Ignition proxy is not configurable in MAPI. Not required for our use case.

pkg/conversion/mapi2capi/aws.go

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

288+
// Dedicated host support
289+
if providerSpec.HostID != nil {
290+
spec.HostID = providerSpec.HostID
291+
}
292+
if providerSpec.HostAffinity != nil {
293+
spec.HostAffinity = ptr.To(string(*providerSpec.HostAffinity))
294+
}
295+
if providerSpec.HostAffinity != nil && providerSpec.HostID == nil {
296+
errs = append(errs, field.Invalid(fldPath.Child("hostAffinity"), providerSpec.HostAffinity, "hostAffinity requires hostID to be set"))
297+
}
298+
288299
if providerSpec.CapacityReservationID != "" {
289300
spec.CapacityReservationID = &providerSpec.CapacityReservationID
290301
}

0 commit comments

Comments
 (0)