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

Fix ExternalName services #1605

Merged
merged 1 commit into from
Oct 27, 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
26 changes: 26 additions & 0 deletions pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,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 {
rand.Seed(time.Now().UnixNano())
for i := range upstreams {
Expand Down Expand Up @@ -1100,9 +1123,12 @@ func (ic *GenericController) getEndpoints(

// ExternalName services
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()
// check for invalid port value
if targetPort <= 0 {
glog.Errorf("ExternalName service with an invalid port: %v", targetPort)
return upsServers
}

Expand Down