Merge pull request #629 from aledbf/externalname-feature

Add support for services of type ExternalName
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-04-20 16:44:03 -03:00 committed by GitHub
commit b18f8e86ad

View file

@ -1024,12 +1024,6 @@ func (ic *GenericController) getEndpoints(
servicePort intstr.IntOrString,
proto api.Protocol,
hz *healthcheck.Upstream) []ingress.Endpoint {
glog.V(3).Infof("getting endpoints for service %v/%v and port %v", s.Namespace, s.Name, servicePort.String())
ep, err := ic.endpLister.GetServiceEndpoints(s)
if err != nil {
glog.Warningf("unexpected error obtaining service endpoints: %v", err)
return []ingress.Endpoint{}
}
upsServers := []ingress.Endpoint{}
@ -1038,6 +1032,53 @@ func (ic *GenericController) getEndpoints(
// targetport.
adus := make(map[string]bool, 0)
// ExternalName services
if s.Spec.Type == api.ServiceTypeExternalName {
var targetPort int
switch servicePort.Type {
case intstr.Int:
targetPort = servicePort.IntValue()
case intstr.String:
port, err := service.GetPortMapping(servicePort.StrVal, s)
if err == nil {
targetPort = int(port)
break
}
glog.Warningf("error mapping service port: %v", err)
err = ic.checkSvcForUpdate(s)
if err != nil {
glog.Warningf("error mapping service ports: %v", err)
return upsServers
}
port, err = service.GetPortMapping(servicePort.StrVal, s)
if err == nil {
targetPort = int(port)
}
}
// check for invalid port value
if targetPort <= 0 {
return upsServers
}
return append(upsServers, ingress.Endpoint{
Address: s.Spec.ExternalName,
Port: fmt.Sprintf("%v", targetPort),
MaxFails: hz.MaxFails,
FailTimeout: hz.FailTimeout,
})
}
glog.V(3).Infof("getting endpoints for service %v/%v and port %v", s.Namespace, s.Name, servicePort.String())
ep, err := ic.endpLister.GetServiceEndpoints(s)
if err != nil {
glog.Warningf("unexpected error obtaining service endpoints: %v", err)
return upsServers
}
for _, ss := range ep.Subsets {
for _, epPort := range ss.Ports {