Skip to content

Commit

Permalink
Merge pull request #4180 from aledbf/externalname
Browse files Browse the repository at this point in the history
Service type=ExternalName can be defined with ports
  • Loading branch information
k8s-ci-robot authored Jun 25, 2019
2 parents c2ea775 + 0ac850c commit ecce3fd
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,24 +850,9 @@ func (n *NGINXController) serviceEndpoints(svcKey, backendPort string) ([]ingres
}

klog.V(3).Infof("Obtaining ports information for Service %q", svcKey)
for _, servicePort := range svc.Spec.Ports {
// targetPort could be a string, use either the port name or number (int)
if strconv.Itoa(int(servicePort.Port)) == backendPort ||
servicePort.TargetPort.String() == backendPort ||
servicePort.Name == backendPort {

endps := getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
if len(endps) == 0 {
klog.Warningf("Service %q does not have any active Endpoint.", svcKey)
}

upstreams = append(upstreams, endps...)
break
}
}

// Ingress with an ExternalName Service and no port defined for that Service
if len(svc.Spec.Ports) == 0 && svc.Spec.Type == apiv1.ServiceTypeExternalName {
if svc.Spec.Type == apiv1.ServiceTypeExternalName {
externalPort, err := strconv.Atoi(backendPort)
if err != nil {
klog.Warningf("Only numeric ports are allowed in ExternalName Services: %q is not a valid port number.", backendPort)
Expand All @@ -889,6 +874,22 @@ func (n *NGINXController) serviceEndpoints(svcKey, backendPort string) ([]ingres
return upstreams, nil
}

for _, servicePort := range svc.Spec.Ports {
// targetPort could be a string, use either the port name or number (int)
if strconv.Itoa(int(servicePort.Port)) == backendPort ||
servicePort.TargetPort.String() == backendPort ||
servicePort.Name == backendPort {

endps := getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
if len(endps) == 0 {
klog.Warningf("Service %q does not have any active Endpoint.", svcKey)
}

upstreams = append(upstreams, endps...)
break
}
}

return upstreams, nil
}

Expand Down

0 comments on commit ecce3fd

Please sign in to comment.