Skip to content

Commit

Permalink
NDS-1069: Do not include port in single-port spec ingress hosts (#217)
Browse files Browse the repository at this point in the history
* Check that service from event still exists

* Only add port to ingress/host if > 1

* Removed port from endpoints
  • Loading branch information
craig-willis authored and bodom0015 committed Oct 24, 2017
1 parent 09d958c commit f771cae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
12 changes: 11 additions & 1 deletion apiserver/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,12 @@ 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-%d.%s", stackService.Id, specPort.Port, s.domain)
if len(spec.Ports) == 1 {
endpoint.Host = fmt.Sprintf("%s.%s", stackService.Id, s.domain)
} else {
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 Expand Up @@ -2505,6 +2510,11 @@ func (s *Server) HandlePodEvent(eventType watch.EventType, event *k8api.Event, p
}
}

if stackService == nil {
glog.Errorf("No such stack service: %s\n", ssid)
return
}

if event != nil {
// This is a general Event
if event.Reason == "MissingClusterDNS" {
Expand Down
53 changes: 32 additions & 21 deletions apiserver/pkg/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ func (k *KubeHelper) CreateControllerTemplate(ns string, name string, stack stri
} else if len(spec.Image.Tags) > 0 {
tag = spec.Image.Tags[0]
} else {
tag = "latest"
}
tag = "latest"
}
k8template := api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{
Expand Down Expand Up @@ -1181,27 +1181,18 @@ func (k *KubeHelper) CreateIngress(pid string, domain string, service string, po
}

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)),
},
},
},
},
},
}
if len(ports) == 1 {
host := fmt.Sprintf("%s.%s", service, domain)
rule := k.createIngressRule(service, host, int(ports[0].Port))
ingress.Spec.Rules = append(ingress.Spec.Rules, rule)
hosts = append(hosts, host)
} else {
for _, port := range ports {
host := fmt.Sprintf("%s-%d.%s", service, port.Port, domain)
rule := k.createIngressRule(service, host, int(port.Port))
ingress.Spec.Rules = append(ingress.Spec.Rules, rule)
hosts = append(hosts, host)
}
}

annotations := map[string]string{}
Expand Down Expand Up @@ -1229,6 +1220,26 @@ func (k *KubeHelper) CreateIngress(pid string, domain string, service string, po
return k.CreateUpdateIngress(pid, ingress, update)
}

func (k *KubeHelper) createIngressRule(service string, host string, port int) extensions.IngressRule {
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(port),
},
},
},
},
},
}
return rule
}

func (k *KubeHelper) CreateUpdateIngress(pid string, ingress *extensions.Ingress, update bool) (*extensions.Ingress, error) {

glog.V(4).Info("Updating ingress " + ingress.Name)
Expand Down

0 comments on commit f771cae

Please sign in to comment.