Skip to content
This repository has been archived by the owner on Apr 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #150 from ccojocar/fix-multiple-ports
Browse files Browse the repository at this point in the history
fix:(ingress) create a path based routing when multiple ports are defined in the service
  • Loading branch information
jenkins-x-bot authored Oct 19, 2018
2 parents c633685 + 65f01d9 commit b5b72ca
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions exposestrategy/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}

Expand Down Expand Up @@ -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"] != "" {
Expand Down

0 comments on commit b5b72ca

Please sign in to comment.