feat: Add ServersTransport annotation to k8s ingress provider

This commit is contained in:
Wouter Dullaert 2021-04-20 17:19:29 +02:00 committed by Jean-Baptiste Doumenjou
parent 526f493e12
commit 456df0fc19
6 changed files with 24 additions and 5 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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",

View file

@ -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"

View file

@ -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)))

View file

@ -130,6 +130,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
URL: "protocol://10.21.0.1:8080",
},
},
ServersTransport: "foobar@file",
},
},
},