1
0
Fork 0

Fix multi-layer routing with models

This commit is contained in:
Julien Salleyron 2025-11-12 14:13:39 +01:00 committed by GitHub
parent a01c73d506
commit d271750062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 432 additions and 0 deletions

View file

@ -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
}