CNAME flattening
This commit is contained in:
parent
139f280f35
commit
31a8e3e39a
16 changed files with 1724 additions and 5 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/containous/mux"
|
||||
"github.com/containous/traefik/configuration"
|
||||
"github.com/containous/traefik/healthcheck"
|
||||
"github.com/containous/traefik/hostresolver"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/containous/traefik/metrics"
|
||||
"github.com/containous/traefik/middlewares"
|
||||
|
@ -136,6 +137,7 @@ func (s *Server) loadFrontendConfig(
|
|||
) ([]handlerPostConfig, error) {
|
||||
|
||||
frontend := config.Frontends[frontendName]
|
||||
hostResolver := buildHostResolver(s.globalConfiguration)
|
||||
|
||||
if len(frontend.EntryPoints) == 0 {
|
||||
return nil, fmt.Errorf("no entrypoint defined for frontend %s", frontendName)
|
||||
|
@ -202,7 +204,7 @@ func (s *Server) loadFrontendConfig(
|
|||
frontend.Backend, entryPointName, providerName, frontendName, frontendHash)
|
||||
}
|
||||
|
||||
serverRoute, err := buildServerRoute(serverEntryPoints[entryPointName], frontendName, frontend)
|
||||
serverRoute, err := buildServerRoute(serverEntryPoints[entryPointName], frontendName, frontend, hostResolver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -261,12 +263,12 @@ func (s *Server) buildForwarder(entryPointName string, entryPoint *configuration
|
|||
return fwd, nil
|
||||
}
|
||||
|
||||
func buildServerRoute(serverEntryPoint *serverEntryPoint, frontendName string, frontend *types.Frontend) (*types.ServerRoute, error) {
|
||||
func buildServerRoute(serverEntryPoint *serverEntryPoint, frontendName string, frontend *types.Frontend, hostResolver *hostresolver.Resolver) (*types.ServerRoute, error) {
|
||||
serverRoute := &types.ServerRoute{Route: serverEntryPoint.httpRouter.GetHandler().NewRoute().Name(frontendName)}
|
||||
|
||||
priority := 0
|
||||
for routeName, route := range frontend.Routes {
|
||||
rls := rules.Rules{Route: serverRoute}
|
||||
rls := rules.Rules{Route: serverRoute, HostResolver: hostResolver}
|
||||
newRoute, err := rls.Parse(route.Rule)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating route for frontend %s: %v", frontendName, err)
|
||||
|
@ -582,3 +584,14 @@ func sortedFrontendNamesForConfig(configuration *types.Configuration) []string {
|
|||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func buildHostResolver(globalConfig configuration.GlobalConfiguration) *hostresolver.Resolver {
|
||||
if globalConfig.HostResolver != nil {
|
||||
return &hostresolver.Resolver{
|
||||
CnameFlattening: globalConfig.HostResolver.CnameFlattening,
|
||||
ResolvConfig: globalConfig.HostResolver.ResolvConfig,
|
||||
ResolvDepth: globalConfig.HostResolver.ResolvDepth,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue