@@ -155,11 +155,16 @@ func (p *HostAdmitter) SetLastSyncProcessed(processed bool) error {
155
155
// addRoute admits routes based on subdomain ownership - returns errors if the route is not admitted.
156
156
func (p * HostAdmitter ) addRoute (route * routeapi.Route ) error {
157
157
// Find displaced routes (or error if an existing route displaces us)
158
- displacedRoutes , err := p .displacedRoutes (route )
158
+ displacedRoutes , err , ownerNamespace := p .displacedRoutes (route )
159
159
if err != nil {
160
160
msg := fmt .Sprintf ("a route in another namespace holds host %s" , route .Spec .Host )
161
+ if ownerNamespace == route .Namespace {
162
+ // Use the full error details if we got bumped by a
163
+ // route in our namespace.
164
+ msg = err .Error ()
165
+ }
161
166
p .recorder .RecordRouteRejection (route , "HostAlreadyClaimed" , msg )
162
- return fmt . Errorf ( "%s (%s)" , msg , err )
167
+ return err
163
168
}
164
169
165
170
// Remove displaced routes
@@ -169,7 +174,17 @@ func (p *HostAdmitter) addRoute(route *routeapi.Route) error {
169
174
p .blockedWildcards .RemoveRoute (wildcardKey , displacedRoute )
170
175
p .claimedWildcards .RemoveRoute (wildcardKey , displacedRoute )
171
176
172
- msg := fmt .Sprintf ("a route in another namespace holds host %s" , displacedRoute .Spec .Host )
177
+ msg := ""
178
+ if route .Namespace == displacedRoute .Namespace {
179
+ if route .Spec .WildcardPolicy == routeapi .WildcardPolicySubdomain {
180
+ msg = fmt .Sprintf ("wildcard route %s/%s has host *.%s blocking %s" , route .Namespace , route .Name , wildcardKey , displacedRoute .Spec .Host )
181
+ } else {
182
+ msg = fmt .Sprintf ("route %s/%s has host %s, blocking %s" , route .Namespace , route .Name , route .Spec .Host , displacedRoute .Spec .Host )
183
+ }
184
+ } else {
185
+ msg = fmt .Sprintf ("a route in another namespace holds host %s" , displacedRoute .Spec .Host )
186
+ }
187
+
173
188
p .recorder .RecordRouteRejection (displacedRoute , "HostAlreadyClaimed" , msg )
174
189
p .plugin .HandleRoute (watch .Deleted , displacedRoute )
175
190
}
@@ -207,17 +222,42 @@ func (p *HostAdmitter) addRoute(route *routeapi.Route) error {
207
222
return nil
208
223
}
209
224
210
- func (p * HostAdmitter ) displacedRoutes (newRoute * routeapi.Route ) ([]* routeapi.Route , error ) {
225
+ func (p * HostAdmitter ) displacedRoutes (newRoute * routeapi.Route ) ([]* routeapi.Route , error , string ) {
211
226
displaced := []* routeapi.Route {}
212
227
213
228
// See if any existing routes block our host, or if we displace their host
214
229
for i , route := range p .claimedHosts [newRoute .Spec .Host ] {
215
230
if route .Namespace == newRoute .Namespace {
216
- // Never displace a route in our namespace
217
- continue
231
+ if route .Name == newRoute .Name {
232
+ continue
233
+ }
234
+
235
+ // Check for wildcard routes. Never displace a
236
+ // non-wildcard route in our namespace if we are a
237
+ // wildcard route.
238
+ // E.g. *.acme.test can co-exist with a
239
+ // route for www2.acme.test
240
+ if newRoute .Spec .WildcardPolicy == routeapi .WildcardPolicySubdomain {
241
+ continue
242
+ }
243
+
244
+ // New route is _NOT_ a wildcard - we need to check
245
+ // if the paths are same and if it is older before
246
+ // we can displace another route in our namespace.
247
+ // The path check below allows non-wildcard routes
248
+ // with different paths to coexist with the other
249
+ // non-wildcard routes in this namespace.
250
+ // E.g. www.acme.org/p1 can coexist with other
251
+ // non-wildcard routes www.acme.org/p1/p2 or
252
+ // www.acme.org/p2 or www.acme.org/p2/p3
253
+ // but ...
254
+ // not with www.acme.org/p1
255
+ if route .Spec .Path != newRoute .Spec .Path {
256
+ continue
257
+ }
218
258
}
219
259
if routeapi .RouteLessThan (route , newRoute ) {
220
- return nil , fmt .Errorf ("route %s/%s has host %s" , route .Namespace , route .Name , route .Spec .Host )
260
+ return nil , fmt .Errorf ("route %s/%s has host %s" , route .Namespace , route .Name , route .Spec .Host ), route . Namespace
221
261
}
222
262
displaced = append (displaced , p .claimedHosts [newRoute .Spec .Host ][i ])
223
263
}
@@ -227,11 +267,36 @@ func (p *HostAdmitter) displacedRoutes(newRoute *routeapi.Route) ([]*routeapi.Ro
227
267
// See if any existing wildcard routes block our domain, or if we displace them
228
268
for i , route := range p .claimedWildcards [wildcardKey ] {
229
269
if route .Namespace == newRoute .Namespace {
230
- // Never displace a route in our namespace
231
- continue
270
+ if route .Name == newRoute .Name {
271
+ continue
272
+ }
273
+
274
+ // Check for non-wildcard route. Never displace a
275
+ // wildcard route in our namespace if we are not a
276
+ // wildcard route.
277
+ // E.g. www1.foo.test can co-exist with a
278
+ // wildcard route for *.foo.test
279
+ if newRoute .Spec .WildcardPolicy != routeapi .WildcardPolicySubdomain {
280
+ continue
281
+ }
282
+
283
+ // New route is a wildcard - we need to check if the
284
+ // paths are same and if it is older before we can
285
+ // displace another route in our namespace.
286
+ // The path check below allows wildcard routes with
287
+ // different paths to coexist with the other wildcard
288
+ // routes in this namespace.
289
+ // E.g. *.bar.org/p1 can coexist with other wildcard
290
+ // wildcard routes *.bar.org/p1/p2 or
291
+ // *.bar.org/p2 or *.bar.org/p2/p3
292
+ // but ...
293
+ // not with *.bar.org/p1
294
+ if route .Spec .Path != newRoute .Spec .Path {
295
+ continue
296
+ }
232
297
}
233
298
if routeapi .RouteLessThan (route , newRoute ) {
234
- return nil , fmt .Errorf ("wildcard route %s/%s has host *.%s, blocking %s" , route .Namespace , route .Name , wildcardKey , newRoute .Spec .Host )
299
+ return nil , fmt .Errorf ("wildcard route %s/%s has host *.%s, blocking %s" , route .Namespace , route .Name , wildcardKey , newRoute .Spec .Host ), route . Namespace
235
300
}
236
301
displaced = append (displaced , p.claimedWildcards [wildcardKey ][i ])
237
302
}
@@ -244,11 +309,11 @@ func (p *HostAdmitter) displacedRoutes(newRoute *routeapi.Route) ([]*routeapi.Ro
244
309
continue
245
310
}
246
311
if routeapi .RouteLessThan (route , newRoute ) {
247
- return nil , fmt .Errorf ("route %s/%s has host %s, blocking *.%s" , route .Namespace , route .Name , route .Spec .Host , wildcardKey )
312
+ return nil , fmt .Errorf ("route %s/%s has host %s, blocking *.%s" , route .Namespace , route .Name , route .Spec .Host , wildcardKey ), route . Namespace
248
313
}
249
314
displaced = append (displaced , p.blockedWildcards [wildcardKey ][i ])
250
315
}
251
316
}
252
317
253
- return displaced , nil
318
+ return displaced , nil , newRoute . Namespace
254
319
}
0 commit comments