mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-31 00:52:35 +02:00
fix incorrect route loading behaviors
This commit is contained in:
parent
c61d893403
commit
1baf10fa88
5 changed files with 13 additions and 25 deletions
|
@ -368,7 +368,7 @@ func TestImplicitExcludeDatabase(t *testing.T) {
|
|||
},
|
||||
})["a"]
|
||||
ExpectTrue(t, ok)
|
||||
ExpectTrue(t, r.ShouldNotServe())
|
||||
ExpectTrue(t, r.ShouldExclude())
|
||||
})
|
||||
t.Run("exposed port detection", func(t *testing.T) {
|
||||
r, ok := makeRoutes(&types.Container{
|
||||
|
@ -378,6 +378,6 @@ func TestImplicitExcludeDatabase(t *testing.T) {
|
|||
},
|
||||
})["a"]
|
||||
ExpectTrue(t, ok)
|
||||
ExpectTrue(t, r.ShouldNotServe())
|
||||
ExpectTrue(t, r.ShouldExclude())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -65,12 +65,10 @@ func (handler *EventHandler) Handle(parent task.Parent, events []watcher.Event)
|
|||
handler.Remove(oldr)
|
||||
case handler.matchAny(events, newr):
|
||||
handler.Update(parent, oldr, newr)
|
||||
case newr.ShouldNotServe():
|
||||
handler.Remove(oldr)
|
||||
}
|
||||
}
|
||||
for k, newr := range newRoutes {
|
||||
if _, ok := oldRoutes[k]; !(ok || newr.ShouldNotServe()) {
|
||||
if _, ok := oldRoutes[k]; !ok {
|
||||
handler.Add(parent, newr)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
|
||||
"github.com/rs/zerolog"
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/logging"
|
||||
"github.com/yusing/go-proxy/internal/route"
|
||||
"github.com/yusing/go-proxy/internal/route/provider/types"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
|
@ -83,10 +82,6 @@ func (p *Provider) MarshalText() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (p *Provider) startRoute(parent task.Parent, r *route.Route) E.Error {
|
||||
if r.ShouldNotServe() {
|
||||
logging.Debug().Str("alias", r.Alias).Str("provider", p.ShortName()).Msg("route excluded")
|
||||
return nil
|
||||
}
|
||||
err := r.Start(parent)
|
||||
if err != nil {
|
||||
return err.Subject(r.Alias)
|
||||
|
@ -155,7 +150,6 @@ func (p *Provider) loadRoutes() (routes route.Routes, err E.Error) {
|
|||
}
|
||||
if r.ShouldExclude() {
|
||||
delete(routes, alias)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return routes, errs.Error()
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/yusing/go-proxy/internal/docker"
|
||||
idlewatcher "github.com/yusing/go-proxy/internal/docker/idlewatcher/types"
|
||||
"github.com/yusing/go-proxy/internal/homepage"
|
||||
"github.com/yusing/go-proxy/internal/logging"
|
||||
net "github.com/yusing/go-proxy/internal/net/types"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
||||
|
@ -67,10 +66,6 @@ func (r *Route) Validate() E.Error {
|
|||
}
|
||||
r.isValidated = true
|
||||
|
||||
if r.ShouldNotServe() {
|
||||
return nil
|
||||
}
|
||||
|
||||
errs := E.NewBuilder("entry validation failed")
|
||||
|
||||
switch r.Scheme {
|
||||
|
@ -85,7 +80,7 @@ func (r *Route) Validate() E.Error {
|
|||
r.lURL = E.Collect(errs, net.ParseURL, fmt.Sprintf("%s://%s:%d", r.Scheme, r.Host, r.Port.Listening))
|
||||
fallthrough
|
||||
default:
|
||||
if r.Port.Proxy == 0 && !r.UseIdleWatcher() {
|
||||
if r.Port.Proxy == 0 && !r.IsDocker() {
|
||||
errs.Adds("missing proxy port")
|
||||
}
|
||||
if r.LoadBalance != nil && r.LoadBalance.Link == "" {
|
||||
|
@ -124,6 +119,11 @@ func (r *Route) Finish(reason any) {
|
|||
return
|
||||
}
|
||||
r.impl.Finish(reason)
|
||||
r.impl = nil
|
||||
}
|
||||
|
||||
func (r *Route) Started() bool {
|
||||
return r.impl != nil
|
||||
}
|
||||
|
||||
func (r *Route) ProviderName() string {
|
||||
|
@ -190,7 +190,8 @@ func (r *Route) ShouldExclude() bool {
|
|||
case r.Container.IsExcluded:
|
||||
return true
|
||||
case r.IsZeroPort() && !r.UseIdleWatcher():
|
||||
logging.Debug().Str("container", r.Container.ContainerName).Msg("route excluded")
|
||||
return true
|
||||
case r.Container.IsDatabase && !r.Container.IsExplicit:
|
||||
return true
|
||||
case strings.HasPrefix(r.Container.ContainerName, "buildx_"):
|
||||
return true
|
||||
|
@ -205,13 +206,6 @@ func (r *Route) ShouldExclude() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (r *Route) ShouldNotServe() bool {
|
||||
if r.Container != nil && r.Container.IsDatabase && !r.Container.IsExplicit {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Route) UseLoadBalance() bool {
|
||||
return r.LoadBalance != nil && r.LoadBalance.Link != ""
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ type (
|
|||
TargetURL() *net.URL
|
||||
HealthMonitor() health.HealthMonitor
|
||||
|
||||
Started() bool
|
||||
|
||||
IdlewatcherConfig() *idlewatcher.Config
|
||||
HealthCheckConfig() *health.HealthCheckConfig
|
||||
LoadBalanceConfig() *loadbalance.Config
|
||||
|
|
Loading…
Add table
Reference in a new issue