Adding support for Traefik to respect the K8s ingress class annotation (#1182)
This commit is contained in:
parent
38c0cf7007
commit
f530284031
3 changed files with 57 additions and 1 deletions
|
@ -123,6 +123,8 @@ kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: traefik-web-ui
|
name: traefik-web-ui
|
||||||
namespace: kube-system
|
namespace: kube-system
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: traefik
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- host: traefik-ui.local
|
- host: traefik-ui.local
|
||||||
|
@ -328,6 +330,8 @@ apiVersion: extensions/v1beta1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: cheese
|
name: cheese
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: traefik
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- host: stilton.local
|
- host: stilton.local
|
||||||
|
@ -390,6 +394,7 @@ kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: cheeses
|
name: cheeses
|
||||||
annotations:
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: traefik
|
||||||
traefik.frontend.rule.type: pathprefixstrip
|
traefik.frontend.rule.type: pathprefixstrip
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
|
@ -451,6 +456,7 @@ kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: example
|
name: example
|
||||||
annotations:
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: traefik
|
||||||
traefik.frontend.passHostHeader: "false"
|
traefik.frontend.passHostHeader: "false"
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
|
@ -483,4 +489,10 @@ request with the Host header being static.otherdomain.com.
|
||||||
|
|
||||||
Note: The per ingress annotation overides whatever the global value is set to. So you
|
Note: The per ingress annotation overides whatever the global value is set to. So you
|
||||||
could set `disablePassHostHeaders` to true in your toml file and then enable passing
|
could set `disablePassHostHeaders` to true in your toml file and then enable passing
|
||||||
the host header per ingress if you wanted.
|
the host header per ingress if you wanted.
|
||||||
|
|
||||||
|
## Excluding an ingress from Træfɪk
|
||||||
|
You can control which ingress Træfɪk cares about by using the "kubernetes.io/ingress.class"
|
||||||
|
annotation. By default if the annotation is not set at all Træfɪk will include the
|
||||||
|
ingress. If the annotation is set to anything other than traefik or a blank string
|
||||||
|
Træfɪk will ignore it.
|
|
@ -116,6 +116,12 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur
|
||||||
map[string]*types.Frontend{},
|
map[string]*types.Frontend{},
|
||||||
}
|
}
|
||||||
for _, i := range ingresses {
|
for _, i := range ingresses {
|
||||||
|
ingressClass := i.Annotations["kubernetes.io/ingress.class"]
|
||||||
|
|
||||||
|
if !shouldProcessIngress(ingressClass) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range i.Spec.Rules {
|
for _, r := range i.Spec.Rules {
|
||||||
if r.HTTP == nil {
|
if r.HTTP == nil {
|
||||||
log.Warnf("Error in ingress: HTTP is nil")
|
log.Warnf("Error in ingress: HTTP is nil")
|
||||||
|
@ -281,6 +287,15 @@ func equalPorts(servicePort v1.ServicePort, ingressPort intstr.IntOrString) bool
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldProcessIngress(ingressClass string) bool {
|
||||||
|
switch ingressClass {
|
||||||
|
case "", "traefik":
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (provider *Kubernetes) getPassHostHeader() bool {
|
func (provider *Kubernetes) getPassHostHeader() bool {
|
||||||
if provider.DisablePassHostHeaders {
|
if provider.DisablePassHostHeaders {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -1492,6 +1492,7 @@ func TestIngressAnnotations(t *testing.T) {
|
||||||
ObjectMeta: v1.ObjectMeta{
|
ObjectMeta: v1.ObjectMeta{
|
||||||
Namespace: "testing",
|
Namespace: "testing",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
|
"kubernetes.io/ingress.class": "traefik",
|
||||||
"traefik.frontend.passHostHeader": "true",
|
"traefik.frontend.passHostHeader": "true",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1516,6 +1517,34 @@ func TestIngressAnnotations(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ObjectMeta: v1.ObjectMeta{
|
||||||
|
Namespace: "testing",
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"kubernetes.io/ingress.class": "somethingOtherThanTraefik",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: v1beta1.IngressSpec{
|
||||||
|
Rules: []v1beta1.IngressRule{
|
||||||
|
{
|
||||||
|
Host: "herp",
|
||||||
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||||
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||||
|
Paths: []v1beta1.HTTPIngressPath{
|
||||||
|
{
|
||||||
|
Path: "/derp",
|
||||||
|
Backend: v1beta1.IngressBackend{
|
||||||
|
ServiceName: "service2",
|
||||||
|
ServicePort: intstr.FromInt(80),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
services := []*v1.Service{
|
services := []*v1.Service{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue