mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-07 12:02:34 +02:00
fix: conflict error on load-balanced and excluded routes
This commit is contained in:
parent
44ef351840
commit
d3568d9c35
4 changed files with 41 additions and 6 deletions
|
@ -6,6 +6,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkExists(r routes.Route) gperr.Error {
|
func checkExists(r routes.Route) gperr.Error {
|
||||||
|
if r.UseLoadBalance() { // skip checking for load balanced routes
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
existing routes.Route
|
existing routes.Route
|
||||||
ok bool
|
ok bool
|
||||||
|
|
|
@ -192,16 +192,18 @@ func (r *ReveseProxyRoute) addToLoadBalancer(parent task.Parent) {
|
||||||
_ = lb.Start(parent) // always return nil
|
_ = lb.Start(parent) // always return nil
|
||||||
linked = &ReveseProxyRoute{
|
linked = &ReveseProxyRoute{
|
||||||
Route: &Route{
|
Route: &Route{
|
||||||
Alias: cfg.Link,
|
Alias: cfg.Link + "-loadbalancer",
|
||||||
Homepage: r.Homepage,
|
Homepage: r.Homepage,
|
||||||
},
|
},
|
||||||
HealthMon: lb,
|
HealthMon: lb,
|
||||||
loadBalancer: lb,
|
loadBalancer: lb,
|
||||||
handler: lb,
|
handler: lb,
|
||||||
}
|
}
|
||||||
routes.HTTP.Add(linked)
|
routes.HTTP.AddKey(cfg.Link, linked)
|
||||||
r.task.OnFinished("entrypoint_remove_route", func() {
|
routes.All.AddKey(cfg.Link, linked)
|
||||||
routes.HTTP.Del(linked)
|
r.task.OnFinished("remove_loadbalancer_route", func() {
|
||||||
|
routes.HTTP.DelKey(cfg.Link)
|
||||||
|
routes.All.DelKey(cfg.Link)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
r.loadBalancer = lb
|
r.loadBalancer = lb
|
||||||
|
|
|
@ -66,7 +66,7 @@ type (
|
||||||
LisURL *net.URL `json:"lurl,omitempty"`
|
LisURL *net.URL `json:"lurl,omitempty"`
|
||||||
ProxyURL *net.URL `json:"purl,omitempty"`
|
ProxyURL *net.URL `json:"purl,omitempty"`
|
||||||
|
|
||||||
Excluded bool `json:"excluded"`
|
Excluded *bool `json:"excluded"`
|
||||||
|
|
||||||
impl routes.Route
|
impl routes.Route
|
||||||
isValidated bool
|
isValidated bool
|
||||||
|
@ -233,7 +233,8 @@ func (r *Route) Validate() gperr.Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
r.impl = impl
|
r.impl = impl
|
||||||
r.Excluded = r.ShouldExclude()
|
excluded := r.ShouldExclude()
|
||||||
|
r.Excluded = &excluded
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,6 +327,14 @@ func (r *Route) Name() string {
|
||||||
|
|
||||||
// Key implements pool.Object.
|
// Key implements pool.Object.
|
||||||
func (r *Route) Key() string {
|
func (r *Route) Key() string {
|
||||||
|
if r.UseLoadBalance() || r.ShouldExclude() {
|
||||||
|
// for excluded routes and load balanced routes, use provider:alias[-container_id[:8]] as key to make them unique.
|
||||||
|
if r.Container != nil {
|
||||||
|
return r.Provider + ":" + r.Alias + "-" + r.Container.ContainerID[:8]
|
||||||
|
}
|
||||||
|
return r.Provider + ":" + r.Alias
|
||||||
|
}
|
||||||
|
// we need to use alias as key for non-excluded routes because it's being used for subdomain / fqdn lookup for http routes.
|
||||||
return r.Alias
|
return r.Alias
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,6 +403,12 @@ func (r *Route) IsZeroPort() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) ShouldExclude() bool {
|
func (r *Route) ShouldExclude() bool {
|
||||||
|
if r.lastError != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if r.Excluded != nil {
|
||||||
|
return *r.Excluded
|
||||||
|
}
|
||||||
if r.Container != nil {
|
if r.Container != nil {
|
||||||
switch {
|
switch {
|
||||||
case r.Container.IsExcluded:
|
case r.Container.IsExcluded:
|
||||||
|
|
|
@ -39,6 +39,14 @@ func (p *Pool[T]) Add(obj T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Pool[T]) AddKey(key string, obj T) {
|
||||||
|
p.checkExists(key)
|
||||||
|
p.m.Store(key, obj)
|
||||||
|
if !p.disableLog {
|
||||||
|
log.Info().Msgf("%s: added %s", p.name, obj.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Pool[T]) AddIfNotExists(obj T) (actual T, added bool) {
|
func (p *Pool[T]) AddIfNotExists(obj T) (actual T, added bool) {
|
||||||
actual, loaded := p.m.LoadOrStore(obj.Key(), obj)
|
actual, loaded := p.m.LoadOrStore(obj.Key(), obj)
|
||||||
return actual, !loaded
|
return actual, !loaded
|
||||||
|
@ -51,6 +59,13 @@ func (p *Pool[T]) Del(obj T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Pool[T]) DelKey(key string) {
|
||||||
|
p.m.Delete(key)
|
||||||
|
if !p.disableLog {
|
||||||
|
log.Info().Msgf("%s: removed %s", p.name, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Pool[T]) Get(key string) (T, bool) {
|
func (p *Pool[T]) Get(key string) (T, bool) {
|
||||||
return p.m.Load(key)
|
return p.m.Load(key)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue