@@ -1122,7 +1122,7 @@ func TestValidateIngress(t *testing.T) {
1122
1122
if gv == nil {
1123
1123
gv = & networkingv1 .SchemeGroupVersion
1124
1124
}
1125
- errs := validateIngress (ingress , IngressValidationOptions {requireRegexPath : true }, * gv )
1125
+ errs := validateIngress (ingress , IngressValidationOptions {}, * gv )
1126
1126
if len (testCase .expectErrsOnFields ) != len (errs ) {
1127
1127
t .Fatalf ("Expected %d errors, got %d errors: %v" , len (testCase .expectErrsOnFields ), len (errs ), errs )
1128
1128
}
@@ -1138,10 +1138,9 @@ func TestValidateIngress(t *testing.T) {
1138
1138
func TestValidateIngressRuleValue (t * testing.T ) {
1139
1139
fldPath := field .NewPath ("testing.http.paths[0].path" )
1140
1140
testCases := map [string ]struct {
1141
- pathType networking.PathType
1142
- path string
1143
- requireRegexPath bool
1144
- expectedErrs field.ErrorList
1141
+ pathType networking.PathType
1142
+ path string
1143
+ expectedErrs field.ErrorList
1145
1144
}{
1146
1145
"implementation specific: no leading slash" : {
1147
1146
pathType : networking .PathTypeImplementationSpecific ,
@@ -1242,7 +1241,7 @@ func TestValidateIngressRuleValue(t *testing.T) {
1242
1241
},
1243
1242
}
1244
1243
1245
- errs := validateIngressRuleValue (irv , field .NewPath ("testing" ), IngressValidationOptions {requireRegexPath : true })
1244
+ errs := validateIngressRuleValue (irv , field .NewPath ("testing" ), IngressValidationOptions {})
1246
1245
1247
1246
if len (errs ) != len (testCase .expectedErrs ) {
1248
1247
t .Fatalf ("Expected %d errors, got %d (%+v)" , len (testCase .expectedErrs ), len (errs ), errs )
@@ -1335,16 +1334,16 @@ func TestValidateIngressCreate(t *testing.T) {
1335
1334
},
1336
1335
}}
1337
1336
},
1338
- expectedErrs : field.ErrorList {field . Invalid ( field . NewPath ( "spec.rules[0].http.paths[0].path" ), "/([a-z0-9]*)[" , "must be a valid regex" ) },
1337
+ expectedErrs : field.ErrorList {},
1339
1338
},
1340
- "Spec.Backend.Resource field not allowed on create" : {
1339
+ "Spec.Backend.Resource field allowed on create" : {
1341
1340
tweakIngress : func (ingress * networking.Ingress ) {
1342
1341
ingress .Spec .Backend = & networking.IngressBackend {
1343
1342
Resource : resourceBackend }
1344
1343
},
1345
- expectedErrs : field.ErrorList {field . Forbidden ( field . NewPath ( "spec.backend.resource" ), "not supported; only service backends are supported in this version" ) },
1344
+ expectedErrs : field.ErrorList {},
1346
1345
},
1347
- "Paths.Backend.Resource field not allowed on create" : {
1346
+ "Paths.Backend.Resource field allowed on create" : {
1348
1347
tweakIngress : func (ingress * networking.Ingress ) {
1349
1348
ingress .Spec .Rules = []networking.IngressRule {{
1350
1349
Host : "foo.bar.com" ,
@@ -1360,7 +1359,7 @@ func TestValidateIngressCreate(t *testing.T) {
1360
1359
},
1361
1360
}}
1362
1361
},
1363
- expectedErrs : field.ErrorList {field . Forbidden ( field . NewPath ( "spec.rules[0].http.paths[0].backend.resource" ), "not supported; only service backends are supported in this version" ) },
1362
+ expectedErrs : field.ErrorList {},
1364
1363
},
1365
1364
}
1366
1365
@@ -1484,7 +1483,7 @@ func TestValidateIngressUpdate(t *testing.T) {
1484
1483
},
1485
1484
}}
1486
1485
},
1487
- expectedErrs : field.ErrorList {field . Invalid ( field . NewPath ( "spec.rules[0].http.paths[0].path" ), "/bar[" , "must be a valid regex" ) },
1486
+ expectedErrs : field.ErrorList {},
1488
1487
},
1489
1488
"invalid regex path -> valid regex path" : {
1490
1489
tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
@@ -1544,13 +1543,13 @@ func TestValidateIngressUpdate(t *testing.T) {
1544
1543
},
1545
1544
expectedErrs : field.ErrorList {},
1546
1545
},
1547
- "new Backend.Resource not allowed on update" : {
1546
+ "new Backend.Resource allowed on update" : {
1548
1547
tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
1549
1548
oldIngress .Spec .Backend = & defaultBackend
1550
1549
newIngress .Spec .Backend = & networking.IngressBackend {
1551
1550
Resource : resourceBackend }
1552
1551
},
1553
- expectedErrs : field.ErrorList {field . Forbidden ( field . NewPath ( "spec.backend.resource" ), "not supported; only service backends are supported in this version" ) },
1552
+ expectedErrs : field.ErrorList {},
1554
1553
},
1555
1554
"old Backend.Resource allowed on update" : {
1556
1555
tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
@@ -1687,7 +1686,7 @@ func TestValidateIngressUpdate(t *testing.T) {
1687
1686
},
1688
1687
}}
1689
1688
},
1690
- expectedErrs : field.ErrorList {field . Forbidden ( field . NewPath ( "spec.rules[0].http.paths[0].backend.resource" ), "not supported; only service backends are supported in this version" ) },
1689
+ expectedErrs : field.ErrorList {},
1691
1690
},
1692
1691
}
1693
1692
@@ -1956,7 +1955,7 @@ func TestValidateIngressTLS(t *testing.T) {
1956
1955
errorCases [badWildcardTLSErr ] = badWildcardTLS
1957
1956
1958
1957
for k , v := range errorCases {
1959
- errs := validateIngress (& v , IngressValidationOptions {requireRegexPath : true }, networkingv1beta1 .SchemeGroupVersion )
1958
+ errs := validateIngress (& v , IngressValidationOptions {}, networkingv1beta1 .SchemeGroupVersion )
1960
1959
if len (errs ) == 0 {
1961
1960
t .Errorf ("expected failure for %q" , k )
1962
1961
} else {
@@ -1980,7 +1979,7 @@ func TestValidateIngressTLS(t *testing.T) {
1980
1979
}
1981
1980
validCases [fmt .Sprintf ("spec.tls[0].hosts: Valid value: '%v'" , wildHost )] = goodWildcardTLS
1982
1981
for k , v := range validCases {
1983
- errs := validateIngress (& v , IngressValidationOptions {requireRegexPath : true }, networkingv1beta1 .SchemeGroupVersion )
1982
+ errs := validateIngress (& v , IngressValidationOptions {}, networkingv1beta1 .SchemeGroupVersion )
1984
1983
if len (errs ) != 0 {
1985
1984
t .Errorf ("expected success for %q" , k )
1986
1985
}
@@ -2078,151 +2077,3 @@ func TestValidateIngressStatusUpdate(t *testing.T) {
2078
2077
}
2079
2078
}
2080
2079
}
2081
-
2082
- func TestValidateResourceBackendPresent (t * testing.T ) {
2083
- implementationPathType := networking .PathTypeImplementationSpecific
2084
- defaultBackend := networking.IngressBackend {
2085
- ServiceName : "default-backend" ,
2086
- ServicePort : intstr .FromInt (80 ),
2087
- }
2088
- resourceBackend := & api.TypedLocalObjectReference {
2089
- APIGroup : utilpointer .StringPtr ("example.com" ),
2090
- Kind : "foo" ,
2091
- Name : "bar" ,
2092
- }
2093
- baseIngress := networking.Ingress {
2094
- ObjectMeta : metav1.ObjectMeta {
2095
- Name : "foo" ,
2096
- Namespace : metav1 .NamespaceDefault ,
2097
- },
2098
- Spec : networking.IngressSpec {
2099
- Backend : & networking.IngressBackend {
2100
- ServiceName : "default-backend" ,
2101
- ServicePort : intstr .FromInt (80 ),
2102
- },
2103
- Rules : []networking.IngressRule {
2104
- {
2105
- Host : "foo.bar.com" ,
2106
- IngressRuleValue : networking.IngressRuleValue {
2107
- HTTP : & networking.HTTPIngressRuleValue {
2108
- Paths : []networking.HTTPIngressPath {
2109
- {
2110
- Path : "/foo" ,
2111
- PathType : & implementationPathType ,
2112
- Backend : defaultBackend ,
2113
- },
2114
- },
2115
- },
2116
- },
2117
- },
2118
- },
2119
- },
2120
- Status : networking.IngressStatus {
2121
- LoadBalancer : api.LoadBalancerStatus {
2122
- Ingress : []api.LoadBalancerIngress {
2123
- {IP : "127.0.0.1" },
2124
- },
2125
- },
2126
- },
2127
- }
2128
- testCases := map [string ]struct {
2129
- groupVersion * schema.GroupVersion
2130
- tweakIngress func (ing * networking.Ingress )
2131
- expectResourceBackend bool
2132
- }{
2133
- "nil spec.Backend and no paths" : {
2134
- tweakIngress : func (ing * networking.Ingress ) {
2135
- ing .Spec .Backend = nil
2136
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths [0 ].Path = ""
2137
- },
2138
- expectResourceBackend : false ,
2139
- },
2140
- "nil spec.Backend.Resource and no paths" : {
2141
- tweakIngress : func (ing * networking.Ingress ) {
2142
- ing .Spec .Backend = nil
2143
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths = []networking.HTTPIngressPath {}
2144
- },
2145
- expectResourceBackend : false ,
2146
- },
2147
- "non-nil spec.Backend.Resource and no paths" : {
2148
- tweakIngress : func (ing * networking.Ingress ) {
2149
- ing .Spec .Backend = & networking.IngressBackend {
2150
- Resource : resourceBackend ,
2151
- }
2152
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths [0 ].Path = ""
2153
- },
2154
- expectResourceBackend : true ,
2155
- },
2156
- "nil spec.Backend, one rule with nil HTTP " : {
2157
- tweakIngress : func (ing * networking.Ingress ) {
2158
- ing .Spec .Backend = nil
2159
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP = nil
2160
- },
2161
- expectResourceBackend : false ,
2162
- },
2163
- "nil spec.Backend, one rule with non-nil HTTP, no paths" : {
2164
- tweakIngress : func (ing * networking.Ingress ) {
2165
- ing .Spec .Backend = nil
2166
- ing .Spec .Rules [0 ].IngressRuleValue = networking.IngressRuleValue {
2167
- HTTP : & networking.HTTPIngressRuleValue {
2168
- Paths : []networking.HTTPIngressPath {},
2169
- },
2170
- }
2171
- },
2172
- expectResourceBackend : false ,
2173
- },
2174
- "nil spec.Backend, one rule with non-nil HTTP, one path with nil Backend.Resource" : {
2175
- tweakIngress : func (ing * networking.Ingress ) {
2176
- ing .Spec .Backend = nil
2177
- ing .Spec .Rules [0 ].IngressRuleValue = networking.IngressRuleValue {
2178
- HTTP : & networking.HTTPIngressRuleValue {
2179
- Paths : []networking.HTTPIngressPath {
2180
- {
2181
- Path : "/foo" ,
2182
- PathType : & implementationPathType ,
2183
- Backend : networking.IngressBackend {
2184
- Resource : nil ,
2185
- },
2186
- },
2187
- },
2188
- },
2189
- }
2190
- },
2191
- expectResourceBackend : false ,
2192
- },
2193
- "nil spec.Backend, one rule with non-nil HTTP, one path with non-nil Backend.Resource" : {
2194
- tweakIngress : func (ing * networking.Ingress ) {
2195
- ing .Spec .Backend = nil
2196
- ing .Spec .Rules [0 ].IngressRuleValue = networking.IngressRuleValue {
2197
- HTTP : & networking.HTTPIngressRuleValue {
2198
- Paths : []networking.HTTPIngressPath {
2199
- {
2200
- Path : "/foo" ,
2201
- PathType : & implementationPathType ,
2202
- Backend : networking.IngressBackend {
2203
- Resource : resourceBackend ,
2204
- },
2205
- },
2206
- },
2207
- },
2208
- }
2209
- },
2210
- expectResourceBackend : true ,
2211
- },
2212
- }
2213
-
2214
- for name , testCase := range testCases {
2215
- t .Run (name , func (t * testing.T ) {
2216
- ingress := baseIngress .DeepCopy ()
2217
- testCase .tweakIngress (ingress )
2218
- gv := testCase .groupVersion
2219
- if gv == nil {
2220
- gv = & networkingv1 .SchemeGroupVersion
2221
- }
2222
- isBackendAllowed := resourceBackendPresent (ingress )
2223
- if isBackendAllowed != testCase .expectResourceBackend {
2224
- t .Errorf ("Expected resourceBackendPresent to return: %v, got: %v" , testCase .expectResourceBackend , isBackendAllowed )
2225
- }
2226
- })
2227
- }
2228
- }
0 commit comments