diff --git a/pkg/webhooks/machine_webhook.go b/pkg/webhooks/machine_webhook.go index 089311a7b..07d0edbe5 100644 --- a/pkg/webhooks/machine_webhook.go +++ b/pkg/webhooks/machine_webhook.go @@ -953,6 +953,14 @@ func processAWSPlacementTenancy(m *machinev1beta1.Machine, placement machinev1be case machinev1beta1.HostAffinityAnyAvailable: // DedicatedHost is optional. If it is set, make sure it follows conventions if placement.Host.DedicatedHost != nil { + // Dynamic Host Allocation (DHA) requires DedicatedHost affinity + strategy := machinev1beta1.AllocationStrategyUserProvided + if placement.Host.DedicatedHost.AllocationStrategy != nil { + strategy = *placement.Host.DedicatedHost.AllocationStrategy + } + if strategy == machinev1beta1.AllocationStrategyDynamic { + errs = append(errs, field.Forbidden(field.NewPath("spec.placement.host.affinity"), "hostAffinity must be DedicatedHost when using dynamic host allocation")) + } errs = append(errs, validateDedicatedHost(placement.Host.DedicatedHost)...) } case machinev1beta1.HostAffinityDedicatedHost: diff --git a/pkg/webhooks/machine_webhook_test.go b/pkg/webhooks/machine_webhook_test.go index 035d87729..52b9538cd 100644 --- a/pkg/webhooks/machine_webhook_test.go +++ b/pkg/webhooks/machine_webhook_test.go @@ -1008,7 +1008,7 @@ func TestMachineCreation(t *testing.T) { }, }, }, - expectedError: "", + expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.placement.host.affinity: Forbidden: hostAffinity must be DedicatedHost when using dynamic host allocation", }, { name: "configure Affinity AnyAvailable with AllocationStrategy Dynamic and DynamicHostAllocation", @@ -1032,7 +1032,7 @@ func TestMachineCreation(t *testing.T) { }, }, }, - expectedError: "", + expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.placement.host.affinity: Forbidden: hostAffinity must be DedicatedHost when using dynamic host allocation", }, { name: "control plane machine with dedicated host should fail",