feat(k8s): add error pages annotations.
This commit is contained in:
parent
5bfd6acd52
commit
4c0d6e211b
4 changed files with 74 additions and 0 deletions
|
@ -219,6 +219,39 @@ func redirectRegex(regex, replacement string) func(*types.Frontend) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func errorPage(name string, opts ...func(*types.ErrorPage)) func(*types.Frontend) {
|
||||||
|
return func(f *types.Frontend) {
|
||||||
|
if f.Errors == nil {
|
||||||
|
f.Errors = make(map[string]*types.ErrorPage)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(name) > 0 {
|
||||||
|
f.Errors[name] = &types.ErrorPage{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(f.Errors[name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorStatus(status ...string) func(*types.ErrorPage) {
|
||||||
|
return func(page *types.ErrorPage) {
|
||||||
|
page.Status = status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorQuery(query string) func(*types.ErrorPage) {
|
||||||
|
return func(page *types.ErrorPage) {
|
||||||
|
page.Query = query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorBackend(backend string) func(*types.ErrorPage) {
|
||||||
|
return func(page *types.ErrorPage) {
|
||||||
|
page.Backend = backend
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func passTLSCert() func(*types.Frontend) {
|
func passTLSCert() func(*types.Frontend) {
|
||||||
return func(f *types.Frontend) {
|
return func(f *types.Frontend) {
|
||||||
f.PassTLSCert = true
|
f.PassTLSCert = true
|
||||||
|
|
|
@ -220,6 +220,8 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
||||||
|
|
||||||
whitelistSourceRange := label.GetSliceStringValue(i.Annotations, annotationKubernetesWhitelistSourceRange)
|
whitelistSourceRange := label.GetSliceStringValue(i.Annotations, annotationKubernetesWhitelistSourceRange)
|
||||||
|
|
||||||
|
errorPages := label.ParseErrorPages(i.Annotations, label.Prefix+label.BaseFrontendErrorPage, label.RegexpFrontendErrorPage)
|
||||||
|
|
||||||
templateObjects.Frontends[r.Host+pa.Path] = &types.Frontend{
|
templateObjects.Frontends[r.Host+pa.Path] = &types.Frontend{
|
||||||
Backend: r.Host + pa.Path,
|
Backend: r.Host + pa.Path,
|
||||||
PassHostHeader: passHostHeader,
|
PassHostHeader: passHostHeader,
|
||||||
|
@ -231,6 +233,7 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
||||||
Redirect: getFrontendRedirect(i),
|
Redirect: getFrontendRedirect(i),
|
||||||
EntryPoints: entryPoints,
|
EntryPoints: entryPoints,
|
||||||
Headers: getHeader(i),
|
Headers: getHeader(i),
|
||||||
|
Errors: errorPages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -673,6 +673,18 @@ func TestIngressAnnotations(t *testing.T) {
|
||||||
iPaths(onePath(iPath("/https"), iBackend("service1", intstr.FromInt(80))))),
|
iPaths(onePath(iPath("/https"), iBackend("service1", intstr.FromInt(80))))),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
buildIngress(
|
||||||
|
iNamespace("testing"),
|
||||||
|
iAnnotation(annotationKubernetesIngressClass, "traefik"),
|
||||||
|
iAnnotation(label.Prefix+label.BaseFrontendErrorPage+"foo."+label.SuffixErrorPageQuery, "/bar"),
|
||||||
|
iAnnotation(label.Prefix+label.BaseFrontendErrorPage+"foo."+label.SuffixErrorPageStatus, "123,456"),
|
||||||
|
iAnnotation(label.Prefix+label.BaseFrontendErrorPage+"foo."+label.SuffixErrorPageBackend, "bar"),
|
||||||
|
iRules(
|
||||||
|
iRule(
|
||||||
|
iHost("error-pages"),
|
||||||
|
iPaths(onePath(iPath("/errorpages"), iBackend("service1", intstr.FromInt(80))))),
|
||||||
|
),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
services := []*v1.Service{
|
services := []*v1.Service{
|
||||||
|
@ -767,6 +779,12 @@ func TestIngressAnnotations(t *testing.T) {
|
||||||
server("http://example.com", weight(1))),
|
server("http://example.com", weight(1))),
|
||||||
lbMethod("wrr"),
|
lbMethod("wrr"),
|
||||||
),
|
),
|
||||||
|
backend("error-pages/errorpages",
|
||||||
|
servers(
|
||||||
|
server("http://example.com", weight(1)),
|
||||||
|
server("http://example.com", weight(1))),
|
||||||
|
lbMethod("wrr"),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
frontends(
|
frontends(
|
||||||
frontend("foo/bar",
|
frontend("foo/bar",
|
||||||
|
@ -837,6 +855,14 @@ func TestIngressAnnotations(t *testing.T) {
|
||||||
route("/api", "PathPrefix:/api;ReplacePath:/"),
|
route("/api", "PathPrefix:/api;ReplacePath:/"),
|
||||||
route("rewrite", "Host:rewrite")),
|
route("rewrite", "Host:rewrite")),
|
||||||
),
|
),
|
||||||
|
frontend("error-pages/errorpages",
|
||||||
|
headers(),
|
||||||
|
passHostHeader(),
|
||||||
|
errorPage("foo", errorQuery("/bar"), errorStatus("123", "456"), errorBackend("bar")),
|
||||||
|
routes(
|
||||||
|
route("/errorpages", "PathPrefix:/errorpages"),
|
||||||
|
route("error-pages", "Host:error-pages")),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,18 @@
|
||||||
replacement = "{{$frontend.RedirectReplacement}}"
|
replacement = "{{$frontend.RedirectReplacement}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{ if $frontend.Errors }}
|
||||||
|
[frontends."frontend-{{$frontendName}}".errors]
|
||||||
|
{{ range $pageName, $page := $frontend.Errors }}
|
||||||
|
[frontends."frontend-{{$frontendName}}".errors.{{ $pageName }}]
|
||||||
|
status = [{{range $page.Status}}
|
||||||
|
"{{.}}",
|
||||||
|
{{end}}]
|
||||||
|
backend = "{{$page.Backend}}"
|
||||||
|
query = "{{$page.Query}}"
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{if $frontend.Headers }}
|
{{if $frontend.Headers }}
|
||||||
[frontends."{{$frontendName}}".headers]
|
[frontends."{{$frontendName}}".headers]
|
||||||
SSLRedirect = {{$frontend.Headers.SSLRedirect}}
|
SSLRedirect = {{$frontend.Headers.SSLRedirect}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue