Skip to content

Commit

Permalink
Add support for services of type ExternalName
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Apr 20, 2017
1 parent dcc0efc commit c71fe9f
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,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{}

Expand All @@ -1021,6 +1015,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 {

Expand Down

0 comments on commit c71fe9f

Please sign in to comment.