Merge pull request #1605 from aledbf/externalname

Fix ExternalName services
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-10-27 13:40:00 -03:00 committed by GitHub
commit 3751159e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -885,6 +885,29 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
} }
} }
// Ingress with an ExternalName service and no port defined in the service.
if len(svc.Spec.Ports) == 0 && svc.Spec.Type == apiv1.ServiceTypeExternalName {
externalPort, err := strconv.Atoi(backendPort)
if err != nil {
glog.Warningf("only numeric ports are allowed in ExternalName services: %v is not valid as a TCP/UDP port", backendPort)
return upstreams, nil
}
servicePort := apiv1.ServicePort{
Protocol: "TCP",
Port: int32(externalPort),
TargetPort: intstr.FromString(backendPort),
}
endps := ic.getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, hz)
if len(endps) == 0 {
glog.Warningf("service %v does not have any active endpoints", svcKey)
return upstreams, nil
}
upstreams = append(upstreams, endps...)
return upstreams, nil
}
if !ic.cfg.SortBackends { if !ic.cfg.SortBackends {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
for i := range upstreams { for i := range upstreams {
@ -1122,9 +1145,12 @@ func (ic *GenericController) getEndpoints(
// ExternalName services // ExternalName services
if s.Spec.Type == apiv1.ServiceTypeExternalName { if s.Spec.Type == apiv1.ServiceTypeExternalName {
glog.V(3).Info("Ingress using a service %v of type=ExternalName : %v", s.Name)
targetPort := servicePort.TargetPort.IntValue() targetPort := servicePort.TargetPort.IntValue()
// check for invalid port value // check for invalid port value
if targetPort <= 0 { if targetPort <= 0 {
glog.Errorf("ExternalName service with an invalid port: %v", targetPort)
return upsServers return upsServers
} }