Skip to content

Commit fca2ee7

Browse files
author
OpenShift Bot
authored
Merge pull request #11849 from ramr/fix-bugz-1391878
Merged by openshift-bot
2 parents 6e707be + 098705f commit fca2ee7

File tree

2 files changed

+162
-51
lines changed

2 files changed

+162
-51
lines changed

pkg/router/controller/host_admitter.go

+77-12
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,16 @@ func (p *HostAdmitter) SetLastSyncProcessed(processed bool) error {
155155
// addRoute admits routes based on subdomain ownership - returns errors if the route is not admitted.
156156
func (p *HostAdmitter) addRoute(route *routeapi.Route) error {
157157
// Find displaced routes (or error if an existing route displaces us)
158-
displacedRoutes, err := p.displacedRoutes(route)
158+
displacedRoutes, err, ownerNamespace := p.displacedRoutes(route)
159159
if err != nil {
160160
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+
}
161166
p.recorder.RecordRouteRejection(route, "HostAlreadyClaimed", msg)
162-
return fmt.Errorf("%s (%s)", msg, err)
167+
return err
163168
}
164169

165170
// Remove displaced routes
@@ -169,7 +174,17 @@ func (p *HostAdmitter) addRoute(route *routeapi.Route) error {
169174
p.blockedWildcards.RemoveRoute(wildcardKey, displacedRoute)
170175
p.claimedWildcards.RemoveRoute(wildcardKey, displacedRoute)
171176

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+
173188
p.recorder.RecordRouteRejection(displacedRoute, "HostAlreadyClaimed", msg)
174189
p.plugin.HandleRoute(watch.Deleted, displacedRoute)
175190
}
@@ -207,17 +222,42 @@ func (p *HostAdmitter) addRoute(route *routeapi.Route) error {
207222
return nil
208223
}
209224

210-
func (p *HostAdmitter) displacedRoutes(newRoute *routeapi.Route) ([]*routeapi.Route, error) {
225+
func (p *HostAdmitter) displacedRoutes(newRoute *routeapi.Route) ([]*routeapi.Route, error, string) {
211226
displaced := []*routeapi.Route{}
212227

213228
// See if any existing routes block our host, or if we displace their host
214229
for i, route := range p.claimedHosts[newRoute.Spec.Host] {
215230
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+
}
218258
}
219259
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
221261
}
222262
displaced = append(displaced, p.claimedHosts[newRoute.Spec.Host][i])
223263
}
@@ -227,11 +267,36 @@ func (p *HostAdmitter) displacedRoutes(newRoute *routeapi.Route) ([]*routeapi.Ro
227267
// See if any existing wildcard routes block our domain, or if we displace them
228268
for i, route := range p.claimedWildcards[wildcardKey] {
229269
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+
}
232297
}
233298
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
235300
}
236301
displaced = append(displaced, p.claimedWildcards[wildcardKey][i])
237302
}
@@ -244,11 +309,11 @@ func (p *HostAdmitter) displacedRoutes(newRoute *routeapi.Route) ([]*routeapi.Ro
244309
continue
245310
}
246311
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
248313
}
249314
displaced = append(displaced, p.blockedWildcards[wildcardKey][i])
250315
}
251316
}
252317

253-
return displaced, nil
318+
return displaced, nil, newRoute.Namespace
254319
}

0 commit comments

Comments
 (0)