proxy: validate each CIDR config seperately and check for errors
This commit revises validateProxyNodePortAddress and validateExcludeCIDRS to report on the exact CIDR that is invalid within the array of strings. Previously we would just return the whole block of addresses and now we identify the exact address within the block to eliminate confusion. I also removed the break from validateProxyNodeAddress so that we can report on all addresses that may not be valid. The tests for each function have also been revised to check the errors explicitly upon validating. This also will properly catch occasions where we should be returning multiple errors if more than one CIDR is invalid. Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
This commit is contained in:
@@ -276,8 +276,7 @@ func validateKubeProxyNodePortAddress(nodePortAddresses []string, fldPath *field
|
||||
|
||||
for i := range nodePortAddresses {
|
||||
if _, _, err := net.ParseCIDR(nodePortAddresses[i]); err != nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath, nodePortAddresses, "must be a valid IP block"))
|
||||
break
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Index(i), nodePortAddresses[i], "must be a valid CIDR"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +306,7 @@ func validateIPVSExcludeCIDRs(excludeCIDRs []string, fldPath *field.Path) field.
|
||||
|
||||
for i := range excludeCIDRs {
|
||||
if _, _, err := net.ParseCIDR(excludeCIDRs[i]); err != nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath, excludeCIDRs, "must be a valid IP block"))
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Index(i), excludeCIDRs[i], "must be a valid CIDR"))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
|
Reference in New Issue
Block a user