Fix NetworkPolicy PolicyTypes validation

The validation had an excess nested loop and also caused wrong
error feedback that all policyTypes input will be reported as
unsupported if any of them is wrong.
This commit is contained in:
Quan Tian
2019-11-29 13:31:57 +08:00
parent cf16e4988f
commit d07dd4bbed

View File

@@ -123,10 +123,8 @@ func ValidateNetworkPolicySpec(spec *networking.NetworkPolicySpec, fldPath *fiel
}
for i, pType := range spec.PolicyTypes {
policyPath := fldPath.Child("policyTypes").Index(i)
for _, p := range spec.PolicyTypes {
if !allowed.Has(string(p)) {
allErrs = append(allErrs, field.NotSupported(policyPath, pType, []string{string(networking.PolicyTypeIngress), string(networking.PolicyTypeEgress)}))
}
if !allowed.Has(string(pType)) {
allErrs = append(allErrs, field.NotSupported(policyPath, pType, []string{string(networking.PolicyTypeIngress), string(networking.PolicyTypeEgress)}))
}
}
return allErrs