forked from kiali/kiali
/
route_rule.go
54 lines (47 loc) · 1.52 KB
/
route_rule.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
package appender
import (
"strings"
"github.com/kiali/kiali/graph/tree"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/log"
"github.com/kiali/kiali/services/models"
)
type RouteRuleAppender struct{}
func (a RouteRuleAppender) AppendGraph(trees *[]tree.ServiceNode, namespaceName string) {
istioClient, err := kubernetes.NewClient()
checkError(err)
for _, tree := range *trees {
applyRouteRules(&tree, namespaceName, istioClient)
}
}
func applyRouteRules(n *tree.ServiceNode, namespaceName string, istioClient *kubernetes.IstioClient) {
// determine if there is a route rule on this node
routeRules, err := istioClient.GetRouteRules(namespaceName, strings.Split(n.Name, ".")[0])
if err == nil {
if routeRules != nil {
rrs := make(models.RouteRules, 0)
rrs.Parse(routeRules)
Found:
for _, rr := range rrs {
if routeMaps, ok := rr.Route.([]interface{}); ok {
for _, routeMap := range routeMaps {
if rm, ok2 := routeMap.(map[string]interface{}); ok2 {
if labels, ok3 := rm["labels"].(map[string]interface{}); ok3 {
if labels["version"] == n.Version {
n.Metadata["hasRouteRule"] = "true"
break Found // no need to keep going, we know it has at least one RouteRule
}
}
}
}
}
}
}
} else {
log.Warningf("Cannot determine if service [%v:%v] has route rules: %v", namespaceName, n.Name, err)
n.Metadata["hasRouteRule"] = "unknown"
}
for _, child := range n.Children {
applyRouteRules(child, namespaceName, istioClient)
}
}