Add support for named ports with service-upstream
. #1459
This commit is contained in:
parent
4f23572ab3
commit
8d4b50c523
1 changed files with 18 additions and 1 deletions
|
@ -824,7 +824,24 @@ func (ic *GenericController) getServiceClusterEndpoint(svcKey string, backend *e
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint.Address = svc.Spec.ClusterIP
|
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
|
return endpoint, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue