-
Notifications
You must be signed in to change notification settings - Fork 33
/
output.go
60 lines (55 loc) · 1.45 KB
/
output.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
package core
import (
"github.com/viant/toolbox"
"github.com/viant/toolbox/data"
"github.com/viant/toolbox/data/udf"
"strings"
)
const defaultOutputTemplate = "default"
var outputTemplates = map[string]map[string]string{
"pod": {
"namespace": "$namespace",
"name": "$name",
"status": "$status.phase",
"age": "$Elapsed('$status.startTime')",
"ip": "$status.podIP",
},
"service": {
"namespace": "$namespace",
"name": "$name",
"type": "$spec.type",
"clusterIP": "$spec.clusterIP",
"externalIP": "$spec.externalIPs",
"selector": "$spec.selector",
"ports": "$spec.ports",
},
"replicaset": {
"namespace": "$namespace",
"name": "$name",
"desired": "$spec.replicas",
"current": "$status.replicas",
"selector": "$spec.selector",
"containers": "$spec.template.spec.containers",
},
}
func transformOutput(outputPaths map[string]string, source, target map[string]interface{}) {
sourceMap := data.Map(source)
udf.Register(sourceMap)
for k, v := range outputPaths {
value := sourceMap.Expand(v)
if value == nil || toolbox.AsString(value) == "" || value == v {
continue
}
target[k] = value
}
}
func getOutputRules(template, kind string, outputPaths map[string]string) map[string]string {
if len(outputPaths) > 0 {
return outputPaths
}
outputPaths, ok := outputTemplates[template]
if !ok {
outputPaths, _ = outputTemplates[strings.ToLower(kind)]
}
return outputPaths
}