Skip to content

Commit

Permalink
Fix no endpoints issue when named ports are used
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Jun 13, 2017
1 parent 72f484e commit a970ef8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a970ef8

Please sign in to comment.