Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for services of type ExternalName #629

Merged
merged 1 commit into from
Apr 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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