This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-06-13 00:27:54 +00:00 committed by GitHub
commit 0ab56351a8

View file

@ -836,12 +836,17 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
svc := svcObj.(*api.Service) svc := svcObj.(*api.Service)
glog.V(3).Infof("obtaining port information for service %v", svcKey) glog.V(3).Infof("obtaining port information for service %v", svcKey)
for _, servicePort := range svc.Spec.Ports { for _, servicePort := range svc.Spec.Ports {
// targetPort could be a string, use the name or the port (int) var p intstr.IntOrString
if strconv.Itoa(int(servicePort.Port)) == backendPort || switch {
servicePort.TargetPort.String() == backendPort || case backendPort == strconv.Itoa(int(servicePort.Port)):
servicePort.Name == backendPort { p = intstr.FromInt(int(servicePort.Port))
case backendPort == servicePort.Name:
p = intstr.FromString(servicePort.Name)
default:
continue
}
endps := ic.getEndpoints(svc, servicePort.TargetPort, api.ProtocolTCP, hz) endps := ic.getEndpoints(svc, p, api.ProtocolTCP, hz)
if len(endps) == 0 { if len(endps) == 0 {
glog.Warningf("service %v does not have any active endpoints", svcKey) glog.Warningf("service %v does not have any active endpoints", svcKey)
} }
@ -850,7 +855,6 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
upstreams = append(upstreams, endps...) upstreams = append(upstreams, endps...)
break break
} }
}
return upstreams, nil return upstreams, nil
} }