From a970ef834d1ae9eee31e35c2e7292d087a9ac61a Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Mon, 12 Jun 2017 20:27:18 -0400 Subject: [PATCH] Fix no endpoints issue when named ports are used --- core/pkg/ingress/controller/controller.go | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/core/pkg/ingress/controller/controller.go b/core/pkg/ingress/controller/controller.go index 6fb5c8c212..b5032c751d 100644 --- a/core/pkg/ingress/controller/controller.go +++ b/core/pkg/ingress/controller/controller.go @@ -836,20 +836,24 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string, svc := svcObj.(*api.Service) glog.V(3).Infof("obtaining port information for service %v", svcKey) for _, servicePort := range svc.Spec.Ports { - // targetPort could be a string, use the name or the port (int) - if strconv.Itoa(int(servicePort.Port)) == backendPort || - servicePort.TargetPort.String() == backendPort || - servicePort.Name == backendPort { - - endps := ic.getEndpoints(svc, servicePort.TargetPort, api.ProtocolTCP, hz) - if len(endps) == 0 { - glog.Warningf("service %v does not have any active endpoints", svcKey) - } + var p intstr.IntOrString + switch { + case backendPort == strconv.Itoa(int(servicePort.Port)): + p = intstr.FromInt(int(servicePort.Port)) + case backendPort == servicePort.Name: + p = intstr.FromString(servicePort.Name) + default: + continue + } - sort.Sort(ingress.EndpointByAddrPort(endps)) - upstreams = append(upstreams, endps...) - break + endps := ic.getEndpoints(svc, p, api.ProtocolTCP, hz) + if len(endps) == 0 { + glog.Warningf("service %v does not have any active endpoints", svcKey) } + + sort.Sort(ingress.EndpointByAddrPort(endps)) + upstreams = append(upstreams, endps...) + break } return upstreams, nil