-
Notifications
You must be signed in to change notification settings - Fork 350
/
eastwest.go
68 lines (57 loc) · 1.77 KB
/
eastwest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package kubernetes
import (
"fmt"
"strings"
"github.com/zalando/skipper/eskip"
)
func eastWestRouteID(rid string) string {
return "kubeew" + rid[len(ingressRouteIDPrefix):]
}
func createEastWestRouteIng(eastWestDomainRegexpPostfix, name, ns string, r *eskip.Route) *eskip.Route {
if strings.HasPrefix(r.Id, "kubeew") || ns == "" || name == "" {
return nil
}
ewR := *r
ewR.HostRegexps = []string{"^" + name + "[.]" + ns + eastWestDomainRegexpPostfix + "$"}
ewR.Id = eastWestRouteID(r.Id)
return &ewR
}
func createEastWestRoutesIng(eastWestDomainRegexpPostfix, name, ns string, routes []*eskip.Route) []*eskip.Route {
ewroutes := make([]*eskip.Route, 0)
newHostRegexps := []string{"^" + name + "[.]" + ns + eastWestDomainRegexpPostfix + "$"}
ingressAlreadyHandled := false
for _, r := range routes {
// TODO(sszuecs) we have to rethink how to handle eastwest routes in more complex cases
n := countPathRoutes(r)
// FIX memory leak in route creation
if strings.HasPrefix(r.Id, "kubeew") || (n == 0 && ingressAlreadyHandled) {
continue
}
r.Namespace = ns // store namespace
r.Name = name // store name
ewR := *r
ewR.HostRegexps = newHostRegexps
ewR.Id = eastWestRouteID(r.Id)
ewroutes = append(ewroutes, &ewR)
ingressAlreadyHandled = true
}
return ewroutes
}
func createEastWestRouteRG(name, ns, postfix string, r *eskip.Route) *eskip.Route {
hostRx := createHostRx(fmt.Sprintf("%s.%s.%s", name, ns, postfix))
ewr := eskip.Copy(r)
ewr.Id = eastWestRouteID(ewr.Id)
ewr.HostRegexps = nil
p := make([]*eskip.Predicate, 0, len(ewr.Predicates))
for _, pi := range ewr.Predicates {
if pi.Name != "Host" {
p = append(p, pi)
}
}
p = append(p, &eskip.Predicate{
Name: "Host",
Args: []interface{}{hostRx},
})
ewr.Predicates = p
return ewr
}