networking/validation: add endport range validation

This commit is contained in:
Carlos Panato
2021-02-03 16:34:51 +01:00
parent 074a517720
commit e57ea32158
2 changed files with 33 additions and 2 deletions

View File

@@ -68,8 +68,13 @@ func ValidateNetworkPolicyPort(port *networking.NetworkPolicyPort, portPath *fie
for _, msg := range validation.IsValidPortNum(int(port.Port.IntVal)) {
allErrs = append(allErrs, field.Invalid(portPath.Child("port"), port.Port.IntVal, msg))
}
if port.EndPort != nil && *port.EndPort < port.Port.IntVal {
allErrs = append(allErrs, field.Invalid(portPath.Child("endPort"), port.Port.IntVal, "must be greater than or equal to `port`"))
if port.EndPort != nil {
if *port.EndPort < port.Port.IntVal {
allErrs = append(allErrs, field.Invalid(portPath.Child("endPort"), port.Port.IntVal, "must be greater than or equal to `port`"))
}
for _, msg := range validation.IsValidPortNum(int(*port.EndPort)) {
allErrs = append(allErrs, field.Invalid(portPath.Child("endPort"), *port.EndPort, msg))
}
}
} else {
if port.EndPort != nil {