From 65f01d9704d1a8f973859a90ea3e25b2d815a32c Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Fri, 19 Oct 2018 15:51:05 +0200 Subject: [PATCH] fix:(ingress) create a path based routing when multiple prots are defined in the service It appends the port name as s suffix of the path if multiple ports are defined. --- exposestrategy/ingress.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/exposestrategy/ingress.go b/exposestrategy/ingress.go index 5db846729..c7fa84237 100644 --- a/exposestrategy/ingress.go +++ b/exposestrategy/ingress.go @@ -174,29 +174,27 @@ func (s *IngressStrategy) Add(svc *api.Service) error { ServiceName: svc.Name, ServicePort: intstr.FromInt(int(port.Port)), }, - Path: path, + Path: s.portPath(svc, &port, path), } - backendPaths = append(backendPaths, ingressPath) - rule := extensions.IngressRule{ Host: hostName, IngressRuleValue: extensions.IngressRuleValue{ HTTP: &extensions.HTTPIngressRuleValue{ - Paths: backendPaths, + Paths: []extensions.HTTPIngressPath{ingressPath}, }, }, } ingress.Spec.Rules = append(ingress.Spec.Rules, rule) + } - if s.tlsAcme && svc.Annotations["jenkins-x.io/skip.tls"] != "true" { - ingress.Spec.TLS = []extensions.IngressTLS{ - { - Hosts: []string{hostName}, - SecretName: tlsSecretName, - }, - } + if s.tlsAcme && svc.Annotations["jenkins-x.io/skip.tls"] != "true" { + ingress.Spec.TLS = []extensions.IngressTLS{ + { + Hosts: []string{hostName}, + SecretName: tlsSecretName, + }, } } @@ -248,6 +246,13 @@ func (s *IngressStrategy) Add(svc *api.Service) error { return nil } +func (s *IngressStrategy) portPath(svc *api.Service, port *api.ServicePort, path string) string { + if len(svc.Spec.Ports) > 1 { + return UrlJoin(path, "/", port.Name) + } + return path +} + func (s *IngressStrategy) Remove(svc *api.Service) error { var appName string if svc.Labels["release"] != "" {