-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem-route.go
57 lines (45 loc) · 1.39 KB
/
item-route.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
package main
import "fmt"
type ItemRouteConflict struct {
name, description, kind string
}
func (irc *ItemRouteConflict) Name() string {
return irc.name
}
func (irc *ItemRouteConflict) Description() string {
return irc.description
}
func (irc *ItemRouteConflict) Kind() string {
return irc.kind
}
func (irc *ItemRouteConflict) Lint(config *Config, params LinterParams) (ResultMap, error) {
resultRouteConflict := make(ResultMap)
//populate map with key spec.host and value metadata.name
//only one route (metadata.name) should resolve to a given FQDN stored in spec.host
routeMap := make(map[string]string)
var key, value string
for _, item := range config.Items {
if item.Kind != irc.Kind() {
continue
}
if item.Metadata != nil && item.Spec != nil {
//skip if host or targetPort field not present
if item.Spec.Host == "" {
continue
}
namespace := item.Metadata.Namespace
key = item.Spec.Host + item.Spec.Path
value = item.Metadata.Name
if len(routeMap[key]) > 0 && routeMap[key] != value {
problem := fmt.Sprintf("Route to '%s' defined twice: '%s' and '%s'", key, routeMap[key], value)
if len(namespace) > 0 {
problem += fmt.Sprintf(" (namespace '%s')", namespace)
}
resultRouteConflict[problem] = append(resultRouteConflict[problem], ContainerSpec{"", "", ""})
} else {
routeMap[key] = value
}
}
}
return resultRouteConflict, nil
}