Fix multi-layer routing with models
This commit is contained in:
parent
a01c73d506
commit
d271750062
2 changed files with 432 additions and 0 deletions
|
|
@ -175,9 +175,11 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
|
|||
if cfg.HTTP != nil && len(cfg.HTTP.Models) > 0 {
|
||||
rts := make(map[string]*dynamic.Router)
|
||||
|
||||
modelRouterNames := make(map[string][]string)
|
||||
for name, rt := range cfg.HTTP.Routers {
|
||||
// Only root routers can have models applied.
|
||||
if rt.ParentRefs != nil {
|
||||
rts[name] = rt
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +235,9 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
|
|||
rtName := name
|
||||
if len(eps) > 1 {
|
||||
rtName = epName + "-" + name
|
||||
modelRouterNames[name] = append(modelRouterNames[name], rtName)
|
||||
}
|
||||
|
||||
rts[rtName] = cp
|
||||
} else {
|
||||
router.EntryPoints = append(router.EntryPoints, epName)
|
||||
|
|
@ -243,6 +247,26 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
for _, rt := range rts {
|
||||
if rt.ParentRefs == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var parentRefs []string
|
||||
for _, ref := range rt.ParentRefs {
|
||||
// Only add the initial parent ref if it still exists.
|
||||
if _, ok := rts[ref]; ok {
|
||||
parentRefs = append(parentRefs, ref)
|
||||
}
|
||||
|
||||
if names, ok := modelRouterNames[ref]; ok {
|
||||
parentRefs = append(parentRefs, names...)
|
||||
}
|
||||
}
|
||||
|
||||
rt.ParentRefs = parentRefs
|
||||
}
|
||||
|
||||
cfg.HTTP.Routers = rts
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue