Skip to content

Commit eab634d

Browse files
committed
Added dedicated hosts support for AWS
1 parent 178bb01 commit eab634d

File tree

3 files changed

+93
-4
lines changed

3 files changed

+93
-4
lines changed

pkg/operator/operator_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ var (
4545
{Name: apifeatures.FeatureGateAzureWorkloadIdentity},
4646
{Name: apifeatures.FeatureGateVSphereMultiDisk},
4747
{Name: apifeatures.FeatureGateVSphereHostVMGroupZonal},
48+
{Name: apifeatures.FeatureGateAWSDedicatedHosts},
4849
}
4950

5051
enabledFeatureMap = map[string]bool{
51-
"MachineAPIMigration": true,
52-
"AzureWorkloadIdentity": true,
53-
"VSphereMultiDisk": true,
54-
"VSphereHostVMGroupZonal": true,
52+
"MachineAPIMigration": true,
53+
"AzureWorkloadIdentity": true,
54+
"VSphereMultiDisk": true,
55+
"VSphereHostVMGroupZonal": true,
56+
"FeatureGateAWSDedicatedHosts": true,
5557
}
5658
)
5759

pkg/webhooks/machine_webhook.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,32 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st
897897
}
898898
}
899899

900+
// Dedicated host support.
901+
// Check if host placement is configured. If so, then we need to determine placement affinity and validate configs.
902+
if providerSpec.HostPlacement != nil {
903+
placement := *providerSpec.HostPlacement
904+
if placement.Affinity == nil {
905+
errs = append(errs, field.Required(field.NewPath("spec.hostPlacement.affinity"), "affinity is required and must be set"))
906+
} else {
907+
switch *placement.Affinity {
908+
case machinev1beta1.HostAffinityAnyAvailable:
909+
// Cannot have DedicatedHost set
910+
if placement.DedicatedHost != nil {
911+
errs = append(errs, field.Forbidden(field.NewPath("spec.hostPlacement.dedicatedHost"), "dedicatedHost is not allowed when affinity is AnyAvailable"))
912+
}
913+
case machinev1beta1.HostAffinityDedicatedHost:
914+
// We need to make sure DedicatedHost is set with a HostID
915+
if placement.DedicatedHost == nil {
916+
errs = append(errs, field.Required(field.NewPath("spec.hostPlacement.dedicatedHost"), "dedicatedHost is required when affinity is DedicatedHost"))
917+
} else if placement.DedicatedHost.ID == "" {
918+
errs = append(errs, field.Invalid(field.NewPath("spec.hostPlacement.dedicatedHost.id"), placement.DedicatedHost.ID, "id must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)"))
919+
}
920+
default:
921+
errs = append(errs, field.Invalid(field.NewPath("spec.hostPlacement.affinity"), placement.Affinity, "affinity is required and must be set to an allowed value"))
922+
}
923+
}
924+
}
925+
900926
if len(errs) > 0 {
901927
return false, warnings, errs
902928
}

pkg/webhooks/machine_webhook_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,67 @@ func TestMachineCreation(t *testing.T) {
316316
},
317317
expectedError: "",
318318
},
319+
{
320+
name: "configure host affinity with Host ID",
321+
platformType: osconfigv1.AWSPlatformType,
322+
clusterID: "aws-cluster",
323+
providerSpecValue: &kruntime.RawExtension{
324+
Object: &machinev1beta1.AWSMachineProviderConfig{
325+
AMI: machinev1beta1.AWSResourceReference{
326+
ID: ptr.To[string]("ami"),
327+
},
328+
InstanceType: "test",
329+
HostAffinity: ptr.To(machinev1beta1.HostAffinityAnyAvailable),
330+
HostID: ptr.To("h-09dcf61cb388b0149"),
331+
},
332+
},
333+
expectedError: "",
334+
},
335+
{
336+
name: "configure host affinity with invalid affinity",
337+
platformType: osconfigv1.AWSPlatformType,
338+
clusterID: "aws-cluster",
339+
providerSpecValue: &kruntime.RawExtension{
340+
Object: &machinev1beta1.AWSMachineProviderConfig{
341+
AMI: machinev1beta1.AWSResourceReference{
342+
ID: ptr.To[string]("ami"),
343+
},
344+
InstanceType: "test",
345+
HostAffinity: ptr.To(machinev1beta1.HostAffinity("invalid")),
346+
},
347+
},
348+
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostID: Required value: hostID must be set when hostAffinity is configured", // true
349+
},
350+
{
351+
name: "configure host affinity without Host ID",
352+
platformType: osconfigv1.AWSPlatformType,
353+
clusterID: "aws-cluster",
354+
providerSpecValue: &kruntime.RawExtension{
355+
Object: &machinev1beta1.AWSMachineProviderConfig{
356+
AMI: machinev1beta1.AWSResourceReference{
357+
ID: ptr.To[string]("ami"),
358+
},
359+
InstanceType: "test",
360+
HostAffinity: ptr.To(machinev1beta1.HostAffinityHost),
361+
},
362+
},
363+
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostID: Required value: hostID must be set when hostAffinity is configured", // true
364+
},
365+
{
366+
name: "hostID alone is valid",
367+
platformType: osconfigv1.AWSPlatformType,
368+
clusterID: "aws-cluster",
369+
providerSpecValue: &kruntime.RawExtension{
370+
Object: &machinev1beta1.AWSMachineProviderConfig{
371+
AMI: machinev1beta1.AWSResourceReference{
372+
ID: ptr.To[string]("ami"),
373+
},
374+
InstanceType: "test",
375+
HostID: ptr.To("h-1234567890abcdef0"),
376+
},
377+
},
378+
expectedError: "",
379+
},
319380
{
320381
name: "with Azure and a nil provider spec value",
321382
platformType: osconfigv1.AzurePlatformType,

0 commit comments

Comments
 (0)