Skip to content

Commit

Permalink
NDS-355: Added support for multiple ports (#208)
Browse files Browse the repository at this point in the history
* Added port to endpoint name

* Multiple port support requires multiple names and ports in the ingress rules
  • Loading branch information
craig-willis authored and bodom0015 committed Jul 27, 2017
1 parent efabd4f commit 56bf2fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
9 changes: 4 additions & 5 deletions apiserver/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1608,15 +1608,14 @@ func (s *Server) createKubernetesService(userId string, stack *api.Stack, spec *

func (s *Server) createIngressRule(userId string, svc *k8api.Service, stack *api.Stack) error {

host := fmt.Sprintf("%s.%s", svc.Name, s.domain)
_, err := s.kube.CreateIngress(userId, host, svc.Name,
int(svc.Spec.Ports[0].Port), stack.Secure)
_, err := s.kube.CreateIngress(userId, s.domain, svc.Name,
svc.Spec.Ports, stack.Secure)
if err != nil {
glog.Errorf("Error creating ingress for %s\n", svc.Name)
glog.Error(err)
return err
}
glog.V(4).Infof("Started ingress %s for service %s (secure=%t)\n", host, svc.Name, stack.Secure)
glog.V(4).Infof("Started ingress for service %s (secure=%t)\n", svc.Name, stack.Secure)
return nil
}

Expand Down Expand Up @@ -2225,7 +2224,7 @@ func (s *Server) getStackWithStatus(userId string, sid string) (*api.Stack, erro
endpoint.Protocol = specPort.Protocol
endpoint.NodePort = k8port.NodePort
if s.useLoadBalancer() && spec.Access == api.AccessExternal {
endpoint.Host = fmt.Sprintf("%s.%s", stackService.Id, s.domain)
endpoint.Host = fmt.Sprintf("%s-%d.%s", stackService.Id, specPort.Port, s.domain)
endpoint.Path = specPort.ContextPath
endpoint.URL = endpoint.Host + specPort.ContextPath
}
Expand Down
38 changes: 21 additions & 17 deletions apiserver/pkg/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ func (k *KubeHelper) Exec(pid string, pod string, container string, kube *KubeHe
return &wsHandler
}

func (k *KubeHelper) CreateIngress(pid string, host string, service string, port int, basicAuth bool) (*extensions.Ingress, error) {
func (k *KubeHelper) CreateIngress(pid string, domain string, service string, ports []api.ServicePort, basicAuth bool) (*extensions.Ingress, error) {

name := service + "-ingress"
update := true
Expand All @@ -1170,27 +1170,31 @@ func (k *KubeHelper) CreateIngress(pid string, host string, service string, port
Name: name,
Namespace: pid,
},
Spec: extensions.IngressSpec{
Rules: []extensions.IngressRule{
extensions.IngressRule{
Host: host,
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
extensions.HTTPIngressPath{
Path: "/",
Backend: extensions.IngressBackend{
ServiceName: service,
ServicePort: intstr.FromInt(port),
},
},
},
}
}

hosts := []string{}
for _, port := range ports {

host := fmt.Sprintf("%s-%d.%s", service, port.Port, domain)
rule := extensions.IngressRule{
Host: host,
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
extensions.HTTPIngressPath{
Path: "/",
Backend: extensions.IngressBackend{
ServiceName: service,
ServicePort: intstr.FromInt(int(port.Port)),
},
},
},
},
},
}
ingress.Spec.Rules = append(ingress.Spec.Rules, rule)
hosts = append(hosts, host)
}

annotations := map[string]string{}
Expand All @@ -1209,7 +1213,7 @@ func (k *KubeHelper) CreateIngress(pid string, host string, service string, port
if secret != nil {
ingress.Spec.TLS = []extensions.IngressTLS{
extensions.IngressTLS{
Hosts: []string{host},
Hosts: hosts,
SecretName: tlsSecretName,
},
}
Expand Down

0 comments on commit 56bf2fe

Please sign in to comment.