-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummary.go
50 lines (44 loc) · 1.29 KB
/
summary.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
package main
func summary(config *Config, combined *CombinedResultMap, params LinterParams) ResultMap {
all := make(ResultMap)
var allKeys []string
for _, item := range config.Items {
//nested template with its own `metadata` and `spec` properties?
if item.Spec != nil && item.Spec.Template != nil {
for _, container := range item.Spec.Template.Spec.Containers {
name := container.Name
var key string
key = item.Metadata.Namespace + item.Metadata.Name + name
all[key] = append(all[key], ContainerSpec{item.Metadata.Namespace, item.Metadata.Name, name})
allKeys = append(allKeys, key)
}
}
}
err := make(map[string]int)
for _, result := range *combined {
for _, set := range result {
for _, spec := range set {
key := spec.Namespace + spec.Name + spec.Container
err[key]++
}
}
}
//now populate summary map
summary := make(ResultMap)
for _, key := range allKeys {
switch err[key] {
case 0:
summary["g"] = append(summary["g"], all[key]...)
case 1:
summary["ga"] = append(summary["ga"], all[key]...)
case 2:
summary["a"] = append(summary["a"], all[key]...)
case 3:
summary["ar"] = append(summary["ar"], all[key]...)
default:
summary["r"] = append(summary["r"], all[key]...)
}
}
postprocessResult(&summary, params)
return summary
}