From a3c87cf9cbd583d49c2da269bf7b9740c0cd2b67 Mon Sep 17 00:00:00 2001 From: Alejandro Pedraza Date: Wed, 6 Feb 2019 17:34:14 -0500 Subject: [PATCH] Properly set ing.Service when there are multiple rules with different hosts using the same path Fixes #3611 Signed-off-by: Alejandro Pedraza --- internal/ingress/controller/template/template.go | 12 +++++++++++- rootfs/etc/nginx/template/nginx.tmpl | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index e796ab2b1..f7b17af2b 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -731,13 +731,19 @@ func (info *ingressInformation) Equal(other *ingressInformation) bool { return true } -func getIngressInformation(i, p interface{}) *ingressInformation { +func getIngressInformation(i, h, p interface{}) *ingressInformation { ing, ok := i.(*ingress.Ingress) if !ok { klog.Errorf("expected an '*ingress.Ingress' type but %T was returned", i) return &ingressInformation{} } + hostname, ok := h.(string) + if !ok { + klog.Errorf("expected a 'string' type but %T was returned", h) + return &ingressInformation{} + } + path, ok := p.(string) if !ok { klog.Errorf("expected a 'string' type but %T was returned", p) @@ -763,6 +769,10 @@ func getIngressInformation(i, p interface{}) *ingressInformation { continue } + if hostname != "" && hostname != rule.Host { + continue + } + for _, rPath := range rule.HTTP.Paths { if path == rPath.Path { info.Service = rPath.Backend.ServiceName diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index a1919abcd..8f140ceea 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1014,7 +1014,7 @@ stream { {{ end }} location {{ $path }} { - {{ $ing := (getIngressInformation $location.Ingress $location.Path) }} + {{ $ing := (getIngressInformation $location.Ingress $server.Hostname $location.Path) }} set $namespace "{{ $ing.Namespace }}"; set $ingress_name "{{ $ing.Rule }}"; set $service_name "{{ $ing.Service }}";