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:
|
||||
name: traefik-web-ui
|
||||
namespace: kube-system
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik
|
||||
spec:
|
||||
rules:
|
||||
- host: traefik-ui.local
|
||||
|
@ -328,6 +330,8 @@ apiVersion: extensions/v1beta1
|
|||
kind: Ingress
|
||||
metadata:
|
||||
name: cheese
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik
|
||||
spec:
|
||||
rules:
|
||||
- host: stilton.local
|
||||
|
@ -390,6 +394,7 @@ kind: Ingress
|
|||
metadata:
|
||||
name: cheeses
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik
|
||||
traefik.frontend.rule.type: pathprefixstrip
|
||||
spec:
|
||||
rules:
|
||||
|
@ -451,6 +456,7 @@ kind: Ingress
|
|||
metadata:
|
||||
name: example
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik
|
||||
traefik.frontend.passHostHeader: "false"
|
||||
spec:
|
||||
rules:
|
||||
|
@ -484,3 +490,9 @@ request with the Host header being static.otherdomain.com.
|
|||
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
|
||||
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{},
|
||||
}
|
||||
for _, i := range ingresses {
|
||||
ingressClass := i.Annotations["kubernetes.io/ingress.class"]
|
||||
|
||||
if !shouldProcessIngress(ingressClass) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, r := range i.Spec.Rules {
|
||||
if r.HTTP == nil {
|
||||
log.Warnf("Error in ingress: HTTP is nil")
|
||||
|
@ -281,6 +287,15 @@ func equalPorts(servicePort v1.ServicePort, ingressPort intstr.IntOrString) bool
|
|||
return false
|
||||
}
|
||||
|
||||
func shouldProcessIngress(ingressClass string) bool {
|
||||
switch ingressClass {
|
||||
case "", "traefik":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (provider *Kubernetes) getPassHostHeader() bool {
|
||||
if provider.DisablePassHostHeaders {
|
||||
return false
|
||||
|
|
|
@ -1492,6 +1492,7 @@ func TestIngressAnnotations(t *testing.T) {
|
|||
ObjectMeta: v1.ObjectMeta{
|
||||
Namespace: "testing",
|
||||
Annotations: map[string]string{
|
||||
"kubernetes.io/ingress.class": "traefik",
|
||||
"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{
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue