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.
938
-
ifproviderSpec.HostPlacement!=nil {
939
-
klog.V(4).Infof("Validating AWS Host Placement")
940
-
placement:=*providerSpec.HostPlacement
941
-
ifplacement.Affinity==nil {
942
-
errs=append(errs, field.Required(field.NewPath("spec.hostPlacement.affinity"), "affinity is required and must be set to either AnyAvailable or DedicatedHost"))
943
-
} else {
944
-
switch*placement.Affinity {
945
-
casemachinev1beta1.HostAffinityAnyAvailable:
946
-
// Cannot have DedicatedHost set
947
-
ifplacement.DedicatedHost!=nil {
948
-
errs=append(errs, field.Forbidden(field.NewPath("spec.hostPlacement.dedicatedHost"), "dedicatedHost is required when affinity is DedicatedHost, and forbidden otherwise"))
949
-
}
950
-
casemachinev1beta1.HostAffinityDedicatedHost:
951
-
// We need to make sure DedicatedHost is set with a HostID
952
-
ifplacement.DedicatedHost==nil {
953
-
errs=append(errs, field.Required(field.NewPath("spec.hostPlacement.dedicatedHost"), "dedicatedHost is required when affinity is DedicatedHost, and forbidden otherwise"))
954
-
} else {
955
-
// If not set, return required error. If it does not match pattern, return pattern failure message.
956
-
ifplacement.DedicatedHost.ID=="" {
957
-
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)"))
924
+
iflen(errs) >0 {
925
+
returnfalse, warnings, errs
926
+
}
927
+
928
+
returntrue, warnings, nil
929
+
}
930
+
931
+
// processAWSPlacement analyzes the Placement field in relation to Tenancy and host placement. These are analyzed
932
+
// together based based on their relations to one another.
errs=append(errs, field.Forbidden(field.NewPath("spec.placement.host"), "host may only be specified when tenancy is 'host'"))
941
+
}
942
+
casemachinev1beta1.HostTenancy:
943
+
ifplacement.Host!=nil {
944
+
klog.V(4).Infof("Validating AWS Host Placement")
945
+
946
+
ifplacement.Host.Affinity==nil {
947
+
errs=append(errs, field.Required(field.NewPath("spec.placement.host.affinity"), "affinity is required and must be set to either AnyAvailable or DedicatedHost"))
948
+
} else {
949
+
switch*placement.Host.Affinity {
950
+
casemachinev1beta1.HostAffinityAnyAvailable:
951
+
// DedicatedHost is optional. If it is set, make sure it follows conventions
errs=append(errs, field.Invalid(field.NewPath("spec.placement.host.dedicatedHost.id"), placement.Host.DedicatedHost.ID, "id must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)"))
960
954
}
955
+
casemachinev1beta1.HostAffinityDedicatedHost:
956
+
// We need to make sure DedicatedHost is set with an ID
957
+
ifplacement.Host.DedicatedHost==nil {
958
+
errs=append(errs, field.Required(field.NewPath("spec.placement.host.dedicatedHost"), "dedicatedHost is required when hostAffinity is DedicatedHost, and optional otherwise"))
959
+
} else {
960
+
// If not set, return required error. If it does not match pattern, return pattern failure message.
961
+
ifplacement.Host.DedicatedHost.ID=="" {
962
+
errs=append(errs, field.Required(field.NewPath("spec.placement.host.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.placement.host.dedicatedHost.id"), placement.Host.DedicatedHost.ID, "id must start with 'h-' followed by 17 lowercase hexadecimal characters (0-9 and a-f)"))
965
+
}
966
+
}
967
+
default:
968
+
errs=append(errs, field.Invalid(field.NewPath("spec.placement.host.affinity"), placement.Host.Affinity, "hostAffinity must be either AnyAvailable or DedicatedHost"))
961
969
}
962
-
default:
963
-
errs=append(errs, field.Invalid(field.NewPath("spec.hostPlacement.affinity"), placement.Affinity, "affinity must be either AnyAvailable or DedicatedHost"))
964
970
}
965
971
}
972
+
default:
973
+
errs=append(
974
+
errs,
975
+
field.Invalid(
976
+
field.NewPath("providerSpec", "tenancy"),
977
+
placement.Tenancy,
978
+
fmt.Sprintf("Invalid providerSpec.tenancy, the only allowed options are: %s, %s, %s, or omitted", machinev1beta1.DefaultTenancy, machinev1beta1.DedicatedTenancy, machinev1beta1.HostTenancy),
979
+
),
980
+
)
966
981
}
967
982
968
-
iflen(errs) >0 {
969
-
returnfalse, warnings, errs
970
-
}
971
-
972
-
returntrue, warnings, nil
983
+
returnerrs
973
984
}
974
985
975
986
// getDuplicatedTags iterates through the AWS TagSpecifications
0 commit comments