Skip to content

Commit 9396f03

Browse files
Merge pull request #1484 from vr4manta/SPLAT-2680
SPLAT-2680: Changed DHA to require hostAffinity=host
2 parents 221c405 + 453cf66 commit 9396f03

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

pkg/webhooks/machine_webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,14 @@ func processAWSPlacementTenancy(m *machinev1beta1.Machine, placement machinev1be
953953
case machinev1beta1.HostAffinityAnyAvailable:
954954
// DedicatedHost is optional. If it is set, make sure it follows conventions
955955
if placement.Host.DedicatedHost != nil {
956+
// Dynamic Host Allocation (DHA) requires DedicatedHost affinity
957+
strategy := machinev1beta1.AllocationStrategyUserProvided
958+
if placement.Host.DedicatedHost.AllocationStrategy != nil {
959+
strategy = *placement.Host.DedicatedHost.AllocationStrategy
960+
}
961+
if strategy == machinev1beta1.AllocationStrategyDynamic {
962+
errs = append(errs, field.Forbidden(field.NewPath("spec.placement.host.affinity"), "hostAffinity must be DedicatedHost when using dynamic host allocation"))
963+
}
956964
errs = append(errs, validateDedicatedHost(placement.Host.DedicatedHost)...)
957965
}
958966
case machinev1beta1.HostAffinityDedicatedHost:

pkg/webhooks/machine_webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ func TestMachineCreation(t *testing.T) {
10081008
},
10091009
},
10101010
},
1011-
expectedError: "",
1011+
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",
10121012
},
10131013
{
10141014
name: "configure Affinity AnyAvailable with AllocationStrategy Dynamic and DynamicHostAllocation",
@@ -1032,7 +1032,7 @@ func TestMachineCreation(t *testing.T) {
10321032
},
10331033
},
10341034
},
1035-
expectedError: "",
1035+
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",
10361036
},
10371037
{
10381038
name: "control plane machine with dedicated host should fail",

0 commit comments

Comments
 (0)