add invaild scope test case

Signed-off-by: mouuii <49775493+mouuii@users.noreply.github.com>
This commit is contained in:
mouuii
2023-04-01 01:49:57 +08:00
parent c3e7eca7fd
commit becf73a82b
2 changed files with 22 additions and 17 deletions

View File

@@ -599,27 +599,24 @@ func validateIngressClassParametersReference(params *networking.IngressClassPara
return allErrs
}
if params.Scope != nil || params.Namespace != nil {
scope := utilpointer.StringDeref(params.Scope, "")
scope := utilpointer.StringDeref(params.Scope, "")
if !supportedIngressClassParametersReferenceScopes.Has(scope) {
allErrs = append(allErrs, field.NotSupported(fldPath.Child("scope"), scope,
supportedIngressClassParametersReferenceScopes.List()))
} else {
if scope == networking.IngressClassParametersReferenceScopeNamespace {
if params.Namespace == nil {
allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), "`parameters.scope` is set to 'Namespace'"))
} else {
for _, msg := range apivalidation.ValidateNamespaceName(*params.Namespace, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("namespace"), *params.Namespace, msg))
}
if !supportedIngressClassParametersReferenceScopes.Has(scope) {
allErrs = append(allErrs, field.NotSupported(fldPath.Child("scope"), scope,
supportedIngressClassParametersReferenceScopes.List()))
} else {
if scope == networking.IngressClassParametersReferenceScopeNamespace {
if params.Namespace == nil {
allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), "`parameters.scope` is set to 'Namespace'"))
} else {
for _, msg := range apivalidation.ValidateNamespaceName(*params.Namespace, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("namespace"), *params.Namespace, msg))
}
}
}
if scope == networking.IngressClassParametersReferenceScopeCluster && params.Namespace != nil {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("namespace"), "`parameters.scope` is set to 'Cluster'"))
}
if scope == networking.IngressClassParametersReferenceScopeCluster && params.Namespace != nil {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("namespace"), "`parameters.scope` is set to 'Cluster'"))
}
}