Skip to content

Commit ea9394f

Browse files
committed
Added dedicated hosts support for AWS
1 parent 4e40c58 commit ea9394f

File tree

3 files changed

+115
-4
lines changed

3 files changed

+115
-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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,13 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st
868868
)
869869
}
870870

871+
// Check if host affinity is set. If so, we expect a Host ID to be set
872+
if providerSpec.HostAffinity != nil {
873+
if providerSpec.HostID == nil || len(*providerSpec.HostID) == 0 {
874+
errs = append(errs, field.Required(field.NewPath("spec.hostID"), "hostID must be set when hostAffinity is configured"))
875+
}
876+
}
877+
871878
if len(errs) > 0 {
872879
return false, warnings, errs
873880
}

pkg/webhooks/machine_webhook_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,108 @@ 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("default"),
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("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("default"),
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 and dynamicHostAllocation are mutually exclusive",
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+
DynamicHostAllocation: &machinev1beta1.DynamicHostAllocationSpec{
377+
Release: machinev1beta1.DedicatedHostReleaseStrategyOnMachineDeletion,
378+
Tags: map[string]string{
379+
"Environment": "test",
380+
},
381+
},
382+
},
383+
},
384+
expectedError: "validation.machine.machine.openshift.io\" denied the request: [spec.hostID: Forbidden: hostID and dynamicHostAllocation are mutually exclusive, spec.dynamicHostAllocation: Forbidden: hostID and dynamicHostAllocation are mutually exclusive]",
385+
},
386+
{
387+
name: "hostID alone is valid",
388+
platformType: osconfigv1.AWSPlatformType,
389+
clusterID: "aws-cluster",
390+
providerSpecValue: &kruntime.RawExtension{
391+
Object: &machinev1beta1.AWSMachineProviderConfig{
392+
AMI: machinev1beta1.AWSResourceReference{
393+
ID: ptr.To[string]("ami"),
394+
},
395+
InstanceType: "test",
396+
HostID: ptr.To("h-1234567890abcdef0"),
397+
},
398+
},
399+
expectedError: "",
400+
},
401+
{
402+
name: "dynamicHostAllocation alone is valid",
403+
platformType: osconfigv1.AWSPlatformType,
404+
clusterID: "aws-cluster",
405+
providerSpecValue: &kruntime.RawExtension{
406+
Object: &machinev1beta1.AWSMachineProviderConfig{
407+
AMI: machinev1beta1.AWSResourceReference{
408+
ID: ptr.To[string]("ami"),
409+
},
410+
InstanceType: "test",
411+
DynamicHostAllocation: &machinev1beta1.DynamicHostAllocationSpec{
412+
Release: machinev1beta1.DedicatedHostReleaseStrategyOnMachineDeletion,
413+
Tags: map[string]string{
414+
"Environment": "test",
415+
},
416+
},
417+
},
418+
},
419+
expectedError: "",
420+
},
319421
{
320422
name: "with Azure and a nil provider spec value",
321423
platformType: osconfigv1.AzurePlatformType,

0 commit comments

Comments
 (0)