mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
add invaild scope test case
Signed-off-by: mouuii <49775493+mouuii@users.noreply.github.com>
This commit is contained in:
parent
c3e7eca7fd
commit
becf73a82b
@ -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'"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1652,6 +1652,14 @@ func TestValidateIngressClass(t *testing.T) {
|
||||
),
|
||||
expectedErrs: field.ErrorList{},
|
||||
},
|
||||
"valid name, valid controller, invalid scope": {
|
||||
ingressClass: makeValidIngressClass("test123", "foo.co/bar",
|
||||
setParams(makeIngressClassParams(nil, "foo", "bar", nil, utilpointer.String("foo_ns"))),
|
||||
),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Required(field.NewPath("spec.parameters.scope"), ""),
|
||||
},
|
||||
},
|
||||
"namespace not set when scope is Namespace": {
|
||||
ingressClass: makeValidIngressClass("test123", "foo.co/bar",
|
||||
setParams(makeIngressClassParams(nil, "foo", "bar", utilpointer.String("Namespace"), nil)),
|
||||
|
Loading…
Reference in New Issue
Block a user