loosen check rules for ingress creation
This commit is contained in:
@@ -276,9 +276,9 @@ func ValidateIngressCreate(ingress *networking.Ingress) field.ErrorList {
|
||||
}
|
||||
allErrs = append(allErrs, validateIngress(ingress, opts)...)
|
||||
annotationVal, annotationIsSet := ingress.Annotations[annotationIngressClass]
|
||||
if annotationIsSet && ingress.Spec.IngressClassName != nil {
|
||||
if annotationIsSet && ingress.Spec.IngressClassName != nil && annotationVal != *ingress.Spec.IngressClassName {
|
||||
annotationPath := field.NewPath("annotations").Child(annotationIngressClass)
|
||||
allErrs = append(allErrs, field.Invalid(annotationPath, annotationVal, "can not be set when the class field is also set"))
|
||||
allErrs = append(allErrs, field.Invalid(annotationPath, annotationVal, "ingressClass annotation and IngressClassName should have the same value"))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
@@ -993,12 +993,19 @@ func TestValidateIngressCreate(t *testing.T) {
|
||||
},
|
||||
expectedErrs: field.ErrorList{},
|
||||
},
|
||||
"class field and annotation set": {
|
||||
"class field and annotation set with same value": {
|
||||
tweakIngress: func(ingress *networking.Ingress) {
|
||||
ingress.Spec.IngressClassName = utilpointer.String("foo")
|
||||
ingress.Annotations = map[string]string{annotationIngressClass: "foo"}
|
||||
},
|
||||
expectedErrs: field.ErrorList{},
|
||||
},
|
||||
"class field and annotation set with different value": {
|
||||
tweakIngress: func(ingress *networking.Ingress) {
|
||||
ingress.Spec.IngressClassName = utilpointer.String("bar")
|
||||
ingress.Annotations = map[string]string{annotationIngressClass: "foo"}
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(field.NewPath("annotations").Child(annotationIngressClass), "foo", "can not be set when the class field is also set")},
|
||||
expectedErrs: field.ErrorList{field.Invalid(field.NewPath("annotations").Child(annotationIngressClass), "foo", "ingressClass annotation and IngressClassName should have the same value")},
|
||||
},
|
||||
"valid regex path": {
|
||||
tweakIngress: func(ingress *networking.Ingress) {
|
||||
|
Reference in New Issue
Block a user