-
Notifications
You must be signed in to change notification settings - Fork 350
/
eastwest.go
59 lines (48 loc) · 1.39 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
package kubernetes
import (
"fmt"
"strings"
"github.com/zalando/skipper/eskip"
)
func eastWestRouteID(rid string) string {
return "kubeew" + rid[len(ingressRouteIDPrefix):]
}
func createEastWestRouteIng(eastWestDomain, name, ns string, r *eskip.Route) *eskip.Route {
if strings.HasPrefix(r.Id, "kubeew") || ns == "" || name == "" {
return nil
}
ewR := *r
ewR.HostRegexps = []string{createHostRx(name + "." + ns + "." + eastWestDomain)}
ewR.Id = eastWestRouteID(r.Id)
return &ewR
}
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
}
func applyEastWestRange(domains []string, predicates []*eskip.Predicate, host string, routes []*eskip.Route) {
for _, d := range domains {
if strings.HasSuffix(host, d) {
applyEastWestRangePredicates(routes, predicates)
}
}
}
func applyEastWestRangePredicates(routes []*eskip.Route, predicates []*eskip.Predicate) {
for _, route := range routes {
route.Predicates = append(route.Predicates, predicates...)
}
}