From 456df0fc190925ac2276f924a97c0e1384db2704 Mon Sep 17 00:00:00 2001 From: Wouter Dullaert Date: Tue, 20 Apr 2021 17:19:29 +0200 Subject: [PATCH] feat: Add ServersTransport annotation to k8s ingress provider --- docs/content/routing/providers/kubernetes-ingress.md | 8 ++++++++ pkg/provider/kubernetes/ingress/annotations.go | 7 ++++--- pkg/provider/kubernetes/ingress/annotations_test.go | 8 ++++++-- .../ingress/fixtures/Ingress-with-annotations_service.yml | 1 + pkg/provider/kubernetes/ingress/kubernetes.go | 4 ++++ pkg/provider/kubernetes/ingress/kubernetes_test.go | 1 + 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/content/routing/providers/kubernetes-ingress.md b/docs/content/routing/providers/kubernetes-ingress.md index 9550bd8ec..afa8a60a5 100644 --- a/docs/content/routing/providers/kubernetes-ingress.md +++ b/docs/content/routing/providers/kubernetes-ingress.md @@ -294,6 +294,14 @@ which in turn will create the resulting routers, services, handlers, etc. traefik.ingress.kubernetes.io/service.serversscheme: h2c ``` +??? info "`traefik.ingress.kubernetes.io/service.serverstransport`" + + See [ServersTransport](../services/index.md#serverstransport) for more information. + + ```yaml + traefik.ingress.kubernetes.io/service.serversscheme: mtls@file + ``` + ??? info "`traefik.ingress.kubernetes.io/service.passhostheader`" See [pass Host header](../services/index.md#pass-host-header) for more information. diff --git a/pkg/provider/kubernetes/ingress/annotations.go b/pkg/provider/kubernetes/ingress/annotations.go index bd7fc8e7c..25807cdd2 100644 --- a/pkg/provider/kubernetes/ingress/annotations.go +++ b/pkg/provider/kubernetes/ingress/annotations.go @@ -41,9 +41,10 @@ type ServiceConfig struct { // ServiceIng is the service's configuration from annotations. type ServiceIng struct { - ServersScheme string `json:"serversScheme,omitempty"` - PassHostHeader *bool `json:"passHostHeader"` - Sticky *dynamic.Sticky `json:"sticky,omitempty" label:"allowEmpty"` + ServersScheme string `json:"serversScheme,omitempty"` + ServersTransport string `json:"serversTransport,omitempty"` + PassHostHeader *bool `json:"passHostHeader"` + Sticky *dynamic.Sticky `json:"sticky,omitempty" label:"allowEmpty"` } // SetDefaults sets the default values. diff --git a/pkg/provider/kubernetes/ingress/annotations_test.go b/pkg/provider/kubernetes/ingress/annotations_test.go index cd2b50d5e..075e76f90 100644 --- a/pkg/provider/kubernetes/ingress/annotations_test.go +++ b/pkg/provider/kubernetes/ingress/annotations_test.go @@ -104,6 +104,7 @@ func Test_parseServiceConfig(t *testing.T) { "ingress.kubernetes.io/foo": "bar", "traefik.ingress.kubernetes.io/foo": "bar", "traefik.ingress.kubernetes.io/service.serversscheme": "protocol", + "traefik.ingress.kubernetes.io/service.serverstransport": "foobar@file", "traefik.ingress.kubernetes.io/service.passhostheader": "true", "traefik.ingress.kubernetes.io/service.sticky.cookie": "true", "traefik.ingress.kubernetes.io/service.sticky.cookie.httponly": "true", @@ -121,8 +122,9 @@ func Test_parseServiceConfig(t *testing.T) { SameSite: "none", }, }, - ServersScheme: "protocol", - PassHostHeader: Bool(true), + ServersScheme: "protocol", + ServersTransport: "foobar@file", + PassHostHeader: Bool(true), }, }, }, @@ -205,6 +207,7 @@ func Test_convertAnnotations(t *testing.T) { desc: "service annotations", annotations: map[string]string{ "traefik.ingress.kubernetes.io/service.serversscheme": "protocol", + "traefik.ingress.kubernetes.io/service.serverstransport": "foobar@file", "traefik.ingress.kubernetes.io/service.passhostheader": "true", "traefik.ingress.kubernetes.io/service.sticky.cookie": "true", "traefik.ingress.kubernetes.io/service.sticky.cookie.httponly": "true", @@ -214,6 +217,7 @@ func Test_convertAnnotations(t *testing.T) { expected: map[string]string{ "traefik.service.passhostheader": "true", "traefik.service.serversscheme": "protocol", + "traefik.service.serverstransport": "foobar@file", "traefik.service.sticky.cookie": "true", "traefik.service.sticky.cookie.httponly": "true", "traefik.service.sticky.cookie.name": "foobar", diff --git a/pkg/provider/kubernetes/ingress/fixtures/Ingress-with-annotations_service.yml b/pkg/provider/kubernetes/ingress/fixtures/Ingress-with-annotations_service.yml index 980d463c2..57c561247 100644 --- a/pkg/provider/kubernetes/ingress/fixtures/Ingress-with-annotations_service.yml +++ b/pkg/provider/kubernetes/ingress/fixtures/Ingress-with-annotations_service.yml @@ -8,6 +8,7 @@ metadata: ingress.kubernetes.io/foo: bar traefik.ingress.kubernetes.io/foo: bar traefik.ingress.kubernetes.io/service.serversscheme: protocol + traefik.ingress.kubernetes.io/service.serverstransport: foobar@file traefik.ingress.kubernetes.io/service.passhostheader: "true" traefik.ingress.kubernetes.io/service.sticky.cookie: "true" traefik.ingress.kubernetes.io/service.sticky.cookie.httponly: "true" diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 770f565fd..87be4f53b 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -530,6 +530,10 @@ func loadService(client Client, namespace string, backend networkingv1.IngressBa } } + if svcConfig != nil && svcConfig.Service != nil && svcConfig.Service.ServersTransport != "" { + svc.LoadBalancer.ServersTransport = svcConfig.Service.ServersTransport + } + if service.Spec.Type == corev1.ServiceTypeExternalName { protocol := getProtocol(portSpec, portSpec.Name, svcConfig) hostPort := net.JoinHostPort(service.Spec.ExternalName, strconv.Itoa(int(portSpec.Port))) diff --git a/pkg/provider/kubernetes/ingress/kubernetes_test.go b/pkg/provider/kubernetes/ingress/kubernetes_test.go index c0853f1bb..7a69ebd7a 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes_test.go +++ b/pkg/provider/kubernetes/ingress/kubernetes_test.go @@ -130,6 +130,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { URL: "protocol://10.21.0.1:8080", }, }, + ServersTransport: "foobar@file", }, }, },