Add errors about unknown entryPoint in runtime api

This commit is contained in:
Julien Salleyron 2019-08-29 12:38:04 +02:00 committed by Traefiker Bot
parent 38508f9a9c
commit df0dd2f5e6
4 changed files with 22 additions and 2 deletions

View file

@ -17,6 +17,11 @@
## dynamic configuration ##
[http.routers]
[http.routers.router3]
entrypoints=["unknown-entrypoint"]
service = "service1"
rule = "Host(`mydomain.com`)"
[http.routers.router4]
service = "service1"
rule = "Host(`snitest.net`)"

View file

@ -546,6 +546,10 @@ func (s *SimpleSuite) TestRouterConfigErrors(c *check.C) {
err = try.GetRequest("http://127.0.0.1:8080/api/http/routers", 1000*time.Millisecond, try.BodyContains(`["middleware \"unknown@file\" does not exist","found different TLS options for routers on the same host snitest.net, so using the default TLS options instead"]`))
c.Assert(err, checker.IsNil)
// router3 has an error because it uses an unknown entrypoint
err = try.GetRequest("http://127.0.0.1:8080/api/http/routers/router3@file", 1000*time.Millisecond, try.BodyContains(`entryPoint \"unknown-entrypoint\" doesn't exist`, "no valid entryPoint for this router"))
c.Assert(err, checker.IsNil)
// router4 is enabled, but in warning state because its tls options conf was messed up
err = try.GetRequest("http://127.0.0.1:8080/api/http/routers/router4@file", 1000*time.Millisecond, try.BodyContains(`"status":"warning"`))
c.Assert(err, checker.IsNil)

View file

@ -2,6 +2,7 @@ package runtime
import (
"context"
"fmt"
"sync"
"github.com/containous/traefik/v2/pkg/config/dynamic"
@ -17,23 +18,32 @@ func (c *Configuration) GetRoutersByEntryPoints(ctx context.Context, entryPoints
continue
}
logger := log.FromContext(log.With(ctx, log.Str(log.RouterName, rtName)))
eps := rt.EntryPoints
if len(eps) == 0 {
logger.Debugf("No entrypoint defined for this router, using the default one(s) instead: %+v", entryPoints)
eps = entryPoints
}
entryPointsCount := 0
for _, entryPointName := range eps {
if !contains(entryPoints, entryPointName) {
log.FromContext(log.With(ctx, log.Str(log.EntryPointName, entryPointName))).
rt.AddError(fmt.Errorf("entryPoint %q doesn't exist", entryPointName), false)
logger.WithField(log.EntryPointName, entryPointName).
Errorf("entryPoint %q doesn't exist", entryPointName)
continue
}
entryPointsCount++
if _, ok := entryPointsRouters[entryPointName]; !ok {
entryPointsRouters[entryPointName] = make(map[string]*RouterInfo)
}
entryPointsRouters[entryPointName][rtName] = rt
}
if entryPointsCount == 0 {
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
logger.Error("no valid entryPoint for this router")
}
}
return entryPointsRouters

View file

@ -111,7 +111,8 @@ func TestGetRoutersByEntryPoints(t *testing.T) {
Service: "foobar-service@myprovider",
Rule: "Host(`bar.foobar`)",
},
Status: "enabled",
Status: "warning",
Err: []string{`entryPoint "webs" doesn't exist`},
},
},
},