You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Check if host placement is configured. If so, then we need to determine placement affinity and validate configs.
907
+
ifproviderSpec.HostPlacement!=nil {
908
+
klog.V(4).Infof("Validating AWS Host Placement")
909
+
placement:=*providerSpec.HostPlacement
910
+
ifplacement.Affinity==nil {
911
+
errs=append(errs, field.Required(field.NewPath("spec.hostPlacement.affinity"), "affinity is required and must be set to either AnyAvailable or DedicatedHost"))
912
+
} else {
913
+
switch*placement.Affinity {
914
+
casemachinev1beta1.HostAffinityAnyAvailable:
915
+
// Cannot have DedicatedHost set
916
+
ifplacement.DedicatedHost!=nil {
917
+
errs=append(errs, field.Forbidden(field.NewPath("spec.hostPlacement.dedicatedHost"), "dedicatedHost is required when affinity is DedicatedHost, and forbidden otherwise"))
918
+
}
919
+
casemachinev1beta1.HostAffinityDedicatedHost:
920
+
// We need to make sure DedicatedHost is set with a HostID
921
+
ifplacement.DedicatedHost==nil {
922
+
errs=append(errs, field.Required(field.NewPath("spec.hostPlacement.dedicatedHost"), "dedicatedHost is required when affinity is DedicatedHost, and forbidden otherwise"))
923
+
} else {
924
+
// If not set, return required error. If it does not match pattern, return pattern failure message.
925
+
ifplacement.DedicatedHost.ID=="" {
926
+
errs=append(errs, field.Required(field.NewPath("spec.hostPlacement.dedicatedHost.id"), "id is required and must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)"))
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)"))
929
+
}
930
+
}
931
+
default:
932
+
errs=append(errs, field.Invalid(field.NewPath("spec.hostPlacement.affinity"), placement.Affinity, "affinity must be either AnyAvailable or DedicatedHost"))
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostPlacement.affinity: Invalid value: \"invalid\": affinity must be either AnyAvailable or DedicatedHost",
352
+
},
353
+
{
354
+
name: "configure host placement dedicatedHost without dedicatedHost",
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostPlacement.dedicatedHost: Required value: dedicatedHost is required when affinity is DedicatedHost",
369
+
},
370
+
{
371
+
name: "configure host placement dedicatedHost with valid ID",
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostPlacement.dedicatedHost: Forbidden: dedicatedHost is required when affinity is DedicatedHost, and forbidden otherwise",
403
+
},
404
+
{
405
+
name: "configure host placement dedicatedHost with empty ID",
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostPlacement.dedicatedHost.id: Required value: id is required and must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)",
419
+
},
420
+
{
421
+
name: "configure host placement dedicatedHost with ID not set",
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostPlacement.dedicatedHost.id: Required value: id is required and must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)",
435
+
},
436
+
{
437
+
name: "configure host placement dedicatedHost with invalid ID",
expectedError: "admission webhook \"validation.machine.machine.openshift.io\" denied the request: spec.hostPlacement.dedicatedHost.id: Invalid value: \"invalid\": id must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)",
0 commit comments