feat(healthcheck): allow health checking for excluded routes

This commit is contained in:
yusing
2025-06-02 23:19:30 +08:00
parent 4705989f4b
commit 9087c4f195
9 changed files with 138 additions and 57 deletions

View File

@@ -71,9 +71,6 @@ func (p *DockerProvider) loadRoutesImpl() (route.Routes, gperr.Error) {
for _, c := range containers {
container := docker.FromDocker(&c, p.dockerHost)
if container.IsExcluded {
continue
}
if container.IsHostNetworkMode {
err := container.UpdatePorts()
@@ -89,10 +86,15 @@ func (p *DockerProvider) loadRoutesImpl() (route.Routes, gperr.Error) {
}
for k, v := range newEntries {
if conflict, ok := routes[k]; ok {
errs.Add(gperr.Multiline().
err := gperr.Multiline().
Addf("route with alias %s already exists", k).
Addf("container %s", container.ContainerName).
Addf("conflicting container %s", conflict.Container.ContainerName))
Addf("conflicting container %s", conflict.Container.ContainerName)
if conflict.ShouldExclude() || v.ShouldExclude() {
gperr.LogWarn("skipping conflicting route", err)
} else {
errs.Add(err)
}
} else {
routes[k] = v
}

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"path"
"slices"
"time"
"github.com/rs/zerolog"
@@ -11,6 +12,7 @@ import (
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/route"
"github.com/yusing/go-proxy/internal/route/provider/types"
"github.com/yusing/go-proxy/internal/route/routes"
"github.com/yusing/go-proxy/internal/task"
W "github.com/yusing/go-proxy/internal/watcher"
"github.com/yusing/go-proxy/internal/watcher/events"
@@ -90,9 +92,17 @@ func (p *Provider) startRoute(parent task.Parent, r *route.Route) gperr.Error {
err := r.Start(parent)
if err != nil {
delete(p.routes, r.Alias)
routes.All.Del(r)
return err.Subject(r.Alias)
}
p.routes[r.Alias] = r
if conflict, added := routes.All.AddIfNotExists(r); !added {
delete(p.routes, r.Alias)
return gperr.Errorf("route %s already exists: from %s and %s", r.Alias, r.ProviderName(), conflict.ProviderName())
} else {
r.Task().OnCancel("remove_routes_from_all", func() {
routes.All.Del(r)
})
}
return nil
}
@@ -155,10 +165,6 @@ func (p *Provider) loadRoutes() (routes route.Routes, err gperr.Error) {
delete(routes, alias)
continue
}
if r.ShouldExclude() {
delete(routes, alias)
continue
}
r.FinalizeHomepageConfig()
}
return routes, errs.Error()