Properly set ing.Service when there are multiple rules with different hosts using the same path

Fixes #3611

Signed-off-by: Alejandro Pedraza <alejandro.pedraza@gmail.com>
This commit is contained in:
Alejandro Pedraza 2019-02-06 17:34:14 -05:00
parent ef0b1633e2
commit a3c87cf9cb
2 changed files with 12 additions and 2 deletions

View file

@ -731,13 +731,19 @@ func (info *ingressInformation) Equal(other *ingressInformation) bool {
return true return true
} }
func getIngressInformation(i, p interface{}) *ingressInformation { func getIngressInformation(i, h, p interface{}) *ingressInformation {
ing, ok := i.(*ingress.Ingress) ing, ok := i.(*ingress.Ingress)
if !ok { if !ok {
klog.Errorf("expected an '*ingress.Ingress' type but %T was returned", i) klog.Errorf("expected an '*ingress.Ingress' type but %T was returned", i)
return &ingressInformation{} 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) path, ok := p.(string)
if !ok { if !ok {
klog.Errorf("expected a 'string' type but %T was returned", p) klog.Errorf("expected a 'string' type but %T was returned", p)
@ -763,6 +769,10 @@ func getIngressInformation(i, p interface{}) *ingressInformation {
continue continue
} }
if hostname != "" && hostname != rule.Host {
continue
}
for _, rPath := range rule.HTTP.Paths { for _, rPath := range rule.HTTP.Paths {
if path == rPath.Path { if path == rPath.Path {
info.Service = rPath.Backend.ServiceName info.Service = rPath.Backend.ServiceName

View file

@ -1014,7 +1014,7 @@ stream {
{{ end }} {{ end }}
location {{ $path }} { location {{ $path }} {
{{ $ing := (getIngressInformation $location.Ingress $location.Path) }} {{ $ing := (getIngressInformation $location.Ingress $server.Hostname $location.Path) }}
set $namespace "{{ $ing.Namespace }}"; set $namespace "{{ $ing.Namespace }}";
set $ingress_name "{{ $ing.Rule }}"; set $ingress_name "{{ $ing.Rule }}";
set $service_name "{{ $ing.Service }}"; set $service_name "{{ $ing.Service }}";