From 8d4b50c5235002b8fe855beb5d0a1578ad8feef7 Mon Sep 17 00:00:00 2001 From: Chris Moos Date: Thu, 26 Oct 2017 15:48:50 -0700 Subject: [PATCH] Add support for named ports with `service-upstream`. #1459 --- pkg/ingress/controller/controller.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/ingress/controller/controller.go b/pkg/ingress/controller/controller.go index d6608f8b2..d825031bd 100644 --- a/pkg/ingress/controller/controller.go +++ b/pkg/ingress/controller/controller.go @@ -824,7 +824,24 @@ func (ic *GenericController) getServiceClusterEndpoint(svcKey string, backend *e } endpoint.Address = svc.Spec.ClusterIP - endpoint.Port = backend.ServicePort.String() + + // If the service port in the ingress uses a name, lookup + // the actual port in the service spec + if backend.ServicePort.Type == intstr.String { + var port int32 = -1 + for _, svcPort := range svc.Spec.Ports { + if svcPort.Name == backend.ServicePort.String() { + port = svcPort.Port + break + } + } + if port == -1 { + return endpoint, fmt.Errorf("no port mapped for service %s and port name %s", svc.Name, backend.ServicePort.String()) + } + endpoint.Port = fmt.Sprintf("%d", port) + } else { + endpoint.Port = backend.ServicePort.String() + } return endpoint, err }