Don't add TCP proxy when error occurs during creation.
This commit is contained in:
parent
2617de2cdd
commit
c2345c6e9a
6 changed files with 149 additions and 55 deletions
|
@ -62,14 +62,12 @@ func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string) m
|
|||
|
||||
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*config.TCPRouter, handlerHTTP http.Handler, handlerHTTPS http.Handler) (*tcp.Router, error) {
|
||||
router := &tcp.Router{}
|
||||
|
||||
router.HTTPHandler(handlerHTTP)
|
||||
router.HTTPSHandler(handlerHTTPS, m.tlsConfig)
|
||||
for routerName, routerConfig := range configs {
|
||||
ctxRouter := log.With(ctx, log.Str(log.RouterName, routerName))
|
||||
logger := log.FromContext(ctxRouter)
|
||||
|
||||
ctxRouter = internal.AddProviderInContext(ctxRouter, routerName)
|
||||
for routerName, routerConfig := range configs {
|
||||
ctxRouter := log.With(internal.AddProviderInContext(ctx, routerName), log.Str(log.RouterName, routerName))
|
||||
logger := log.FromContext(ctxRouter)
|
||||
|
||||
handler, err := m.serviceManager.BuildTCP(ctxRouter, routerConfig.Service)
|
||||
if err != nil {
|
||||
|
@ -79,18 +77,18 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
|
|||
|
||||
domains, err := rules.ParseHostSNI(routerConfig.Rule)
|
||||
if err != nil {
|
||||
log.WithoutContext().Debugf("Unknown rule %s", routerConfig.Rule)
|
||||
logger.Debugf("Unknown rule %s", routerConfig.Rule)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, domain := range domains {
|
||||
log.WithoutContext().Debugf("Add route %s on TCP", domain)
|
||||
logger.Debugf("Add route %s on TCP", domain)
|
||||
switch {
|
||||
case routerConfig.TLS != nil:
|
||||
if routerConfig.TLS.Passthrough {
|
||||
router.AddRoute(domain, handler)
|
||||
} else {
|
||||
router.AddRouteTLS(domain, handler, m.tlsConfig)
|
||||
|
||||
}
|
||||
case domain == "*":
|
||||
router.AddCatchAllNoTLS(handler)
|
||||
|
@ -103,15 +101,6 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
|
|||
return router, nil
|
||||
}
|
||||
|
||||
func contains(entryPoints []string, entryPointName string) bool {
|
||||
for _, name := range entryPoints {
|
||||
if name == entryPointName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *Manager) filteredRouters(ctx context.Context, entryPoints []string) map[string]map[string]*config.TCPRouter {
|
||||
entryPointsRouters := make(map[string]map[string]*config.TCPRouter)
|
||||
|
||||
|
@ -120,6 +109,7 @@ func (m *Manager) filteredRouters(ctx context.Context, entryPoints []string) map
|
|||
if len(eps) == 0 {
|
||||
eps = entryPoints
|
||||
}
|
||||
|
||||
for _, entryPointName := range eps {
|
||||
if !contains(entryPoints, entryPointName) {
|
||||
log.FromContext(log.With(ctx, log.Str(log.EntryPointName, entryPointName))).
|
||||
|
@ -137,3 +127,12 @@ func (m *Manager) filteredRouters(ctx context.Context, entryPoints []string) map
|
|||
|
||||
return entryPointsRouters
|
||||
}
|
||||
|
||||
func contains(entryPoints []string, entryPointName string) bool {
|
||||
for _, name := range entryPoints {
|
||||
if name == entryPointName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue