Add errors about unknown entryPoint in runtime api
This commit is contained in:
parent
38508f9a9c
commit
df0dd2f5e6
4 changed files with 22 additions and 2 deletions
|
@ -17,6 +17,11 @@
|
||||||
## dynamic configuration ##
|
## dynamic configuration ##
|
||||||
|
|
||||||
[http.routers]
|
[http.routers]
|
||||||
|
[http.routers.router3]
|
||||||
|
entrypoints=["unknown-entrypoint"]
|
||||||
|
service = "service1"
|
||||||
|
rule = "Host(`mydomain.com`)"
|
||||||
|
|
||||||
[http.routers.router4]
|
[http.routers.router4]
|
||||||
service = "service1"
|
service = "service1"
|
||||||
rule = "Host(`snitest.net`)"
|
rule = "Host(`snitest.net`)"
|
||||||
|
|
|
@ -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"]`))
|
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)
|
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
|
// 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"`))
|
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)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
||||||
|
@ -17,23 +18,32 @@ func (c *Configuration) GetRoutersByEntryPoints(ctx context.Context, entryPoints
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := log.FromContext(log.With(ctx, log.Str(log.RouterName, rtName)))
|
||||||
eps := rt.EntryPoints
|
eps := rt.EntryPoints
|
||||||
if len(eps) == 0 {
|
if len(eps) == 0 {
|
||||||
|
logger.Debugf("No entrypoint defined for this router, using the default one(s) instead: %+v", entryPoints)
|
||||||
eps = entryPoints
|
eps = entryPoints
|
||||||
}
|
}
|
||||||
|
entryPointsCount := 0
|
||||||
for _, entryPointName := range eps {
|
for _, entryPointName := range eps {
|
||||||
if !contains(entryPoints, entryPointName) {
|
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)
|
Errorf("entryPoint %q doesn't exist", entryPointName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entryPointsCount++
|
||||||
if _, ok := entryPointsRouters[entryPointName]; !ok {
|
if _, ok := entryPointsRouters[entryPointName]; !ok {
|
||||||
entryPointsRouters[entryPointName] = make(map[string]*RouterInfo)
|
entryPointsRouters[entryPointName] = make(map[string]*RouterInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
entryPointsRouters[entryPointName][rtName] = rt
|
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
|
return entryPointsRouters
|
||||||
|
|
|
@ -111,7 +111,8 @@ func TestGetRoutersByEntryPoints(t *testing.T) {
|
||||||
Service: "foobar-service@myprovider",
|
Service: "foobar-service@myprovider",
|
||||||
Rule: "Host(`bar.foobar`)",
|
Rule: "Host(`bar.foobar`)",
|
||||||
},
|
},
|
||||||
Status: "enabled",
|
Status: "warning",
|
||||||
|
Err: []string{`entryPoint "webs" doesn't exist`},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue