@@ -1336,14 +1336,14 @@ func TestValidateIngressCreate(t *testing.T) {
1336
1336
},
1337
1337
expectedErrs : field.ErrorList {},
1338
1338
},
1339
- "Spec.Backend.Resource field not allowed on create" : {
1339
+ "Spec.Backend.Resource field allowed on create" : {
1340
1340
tweakIngress : func (ingress * networking.Ingress ) {
1341
1341
ingress .Spec .Backend = & networking.IngressBackend {
1342
1342
Resource : resourceBackend }
1343
1343
},
1344
- expectedErrs : field.ErrorList {field . Forbidden ( field . NewPath ( "spec.backend.resource" ), "not supported; only service backends are supported in this version" ) },
1344
+ expectedErrs : field.ErrorList {},
1345
1345
},
1346
- "Paths.Backend.Resource field not allowed on create" : {
1346
+ "Paths.Backend.Resource field allowed on create" : {
1347
1347
tweakIngress : func (ingress * networking.Ingress ) {
1348
1348
ingress .Spec .Rules = []networking.IngressRule {{
1349
1349
Host : "foo.bar.com" ,
@@ -1359,7 +1359,7 @@ func TestValidateIngressCreate(t *testing.T) {
1359
1359
},
1360
1360
}}
1361
1361
},
1362
- 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 {},
1363
1363
},
1364
1364
}
1365
1365
@@ -1543,13 +1543,13 @@ func TestValidateIngressUpdate(t *testing.T) {
1543
1543
},
1544
1544
expectedErrs : field.ErrorList {},
1545
1545
},
1546
- "new Backend.Resource not allowed on update" : {
1546
+ "new Backend.Resource allowed on update" : {
1547
1547
tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
1548
1548
oldIngress .Spec .Backend = & defaultBackend
1549
1549
newIngress .Spec .Backend = & networking.IngressBackend {
1550
1550
Resource : resourceBackend }
1551
1551
},
1552
- expectedErrs : field.ErrorList {field . Forbidden ( field . NewPath ( "spec.backend.resource" ), "not supported; only service backends are supported in this version" ) },
1552
+ expectedErrs : field.ErrorList {},
1553
1553
},
1554
1554
"old Backend.Resource allowed on update" : {
1555
1555
tweakIngresses : func (newIngress , oldIngress * networking.Ingress ) {
@@ -1686,7 +1686,7 @@ func TestValidateIngressUpdate(t *testing.T) {
1686
1686
},
1687
1687
}}
1688
1688
},
1689
- 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 {},
1690
1690
},
1691
1691
}
1692
1692
@@ -2077,151 +2077,3 @@ func TestValidateIngressStatusUpdate(t *testing.T) {
2077
2077
}
2078
2078
}
2079
2079
}
2080
-
2081
- func TestValidateResourceBackendPresent (t * testing.T ) {
2082
- implementationPathType := networking .PathTypeImplementationSpecific
2083
- defaultBackend := networking.IngressBackend {
2084
- ServiceName : "default-backend" ,
2085
- ServicePort : intstr .FromInt (80 ),
2086
- }
2087
- resourceBackend := & api.TypedLocalObjectReference {
2088
- APIGroup : utilpointer .StringPtr ("example.com" ),
2089
- Kind : "foo" ,
2090
- Name : "bar" ,
2091
- }
2092
- baseIngress := networking.Ingress {
2093
- ObjectMeta : metav1.ObjectMeta {
2094
- Name : "foo" ,
2095
- Namespace : metav1 .NamespaceDefault ,
2096
- },
2097
- Spec : networking.IngressSpec {
2098
- Backend : & networking.IngressBackend {
2099
- ServiceName : "default-backend" ,
2100
- ServicePort : intstr .FromInt (80 ),
2101
- },
2102
- Rules : []networking.IngressRule {
2103
- {
2104
- Host : "foo.bar.com" ,
2105
- IngressRuleValue : networking.IngressRuleValue {
2106
- HTTP : & networking.HTTPIngressRuleValue {
2107
- Paths : []networking.HTTPIngressPath {
2108
- {
2109
- Path : "/foo" ,
2110
- PathType : & implementationPathType ,
2111
- Backend : defaultBackend ,
2112
- },
2113
- },
2114
- },
2115
- },
2116
- },
2117
- },
2118
- },
2119
- Status : networking.IngressStatus {
2120
- LoadBalancer : api.LoadBalancerStatus {
2121
- Ingress : []api.LoadBalancerIngress {
2122
- {IP : "127.0.0.1" },
2123
- },
2124
- },
2125
- },
2126
- }
2127
- testCases := map [string ]struct {
2128
- groupVersion * schema.GroupVersion
2129
- tweakIngress func (ing * networking.Ingress )
2130
- expectResourceBackend bool
2131
- }{
2132
- "nil spec.Backend and no paths" : {
2133
- tweakIngress : func (ing * networking.Ingress ) {
2134
- ing .Spec .Backend = nil
2135
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths [0 ].Path = ""
2136
- },
2137
- expectResourceBackend : false ,
2138
- },
2139
- "nil spec.Backend.Resource and no paths" : {
2140
- tweakIngress : func (ing * networking.Ingress ) {
2141
- ing .Spec .Backend = nil
2142
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths = []networking.HTTPIngressPath {}
2143
- },
2144
- expectResourceBackend : false ,
2145
- },
2146
- "non-nil spec.Backend.Resource and no paths" : {
2147
- tweakIngress : func (ing * networking.Ingress ) {
2148
- ing .Spec .Backend = & networking.IngressBackend {
2149
- Resource : resourceBackend ,
2150
- }
2151
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths [0 ].Path = ""
2152
- },
2153
- expectResourceBackend : true ,
2154
- },
2155
- "nil spec.Backend, one rule with nil HTTP " : {
2156
- tweakIngress : func (ing * networking.Ingress ) {
2157
- ing .Spec .Backend = nil
2158
- ing .Spec .Rules [0 ].IngressRuleValue .HTTP = nil
2159
- },
2160
- expectResourceBackend : false ,
2161
- },
2162
- "nil spec.Backend, one rule with non-nil HTTP, no paths" : {
2163
- tweakIngress : func (ing * networking.Ingress ) {
2164
- ing .Spec .Backend = nil
2165
- ing .Spec .Rules [0 ].IngressRuleValue = networking.IngressRuleValue {
2166
- HTTP : & networking.HTTPIngressRuleValue {
2167
- Paths : []networking.HTTPIngressPath {},
2168
- },
2169
- }
2170
- },
2171
- expectResourceBackend : false ,
2172
- },
2173
- "nil spec.Backend, one rule with non-nil HTTP, one path with nil Backend.Resource" : {
2174
- tweakIngress : func (ing * networking.Ingress ) {
2175
- ing .Spec .Backend = nil
2176
- ing .Spec .Rules [0 ].IngressRuleValue = networking.IngressRuleValue {
2177
- HTTP : & networking.HTTPIngressRuleValue {
2178
- Paths : []networking.HTTPIngressPath {
2179
- {
2180
- Path : "/foo" ,
2181
- PathType : & implementationPathType ,
2182
- Backend : networking.IngressBackend {
2183
- Resource : nil ,
2184
- },
2185
- },
2186
- },
2187
- },
2188
- }
2189
- },
2190
- expectResourceBackend : false ,
2191
- },
2192
- "nil spec.Backend, one rule with non-nil HTTP, one path with non-nil Backend.Resource" : {
2193
- tweakIngress : func (ing * networking.Ingress ) {
2194
- ing .Spec .Backend = nil
2195
- ing .Spec .Rules [0 ].IngressRuleValue = networking.IngressRuleValue {
2196
- HTTP : & networking.HTTPIngressRuleValue {
2197
- Paths : []networking.HTTPIngressPath {
2198
- {
2199
- Path : "/foo" ,
2200
- PathType : & implementationPathType ,
2201
- Backend : networking.IngressBackend {
2202
- Resource : resourceBackend ,
2203
- },
2204
- },
2205
- },
2206
- },
2207
- }
2208
- },
2209
- expectResourceBackend : true ,
2210
- },
2211
- }
2212
-
2213
- for name , testCase := range testCases {
2214
- t .Run (name , func (t * testing.T ) {
2215
- ingress := baseIngress .DeepCopy ()
2216
- testCase .tweakIngress (ingress )
2217
- gv := testCase .groupVersion
2218
- if gv == nil {
2219
- gv = & networkingv1 .SchemeGroupVersion
2220
- }
2221
- isBackendAllowed := resourceBackendPresent (ingress )
2222
- if isBackendAllowed != testCase .expectResourceBackend {
2223
- t .Errorf ("Expected resourceBackendPresent to return: %v, got: %v" , testCase .expectResourceBackend , isBackendAllowed )
2224
- }
2225
- })
2226
- }
2227
- }
0 commit comments