-
Notifications
You must be signed in to change notification settings - Fork 478
/
types.go
163 lines (129 loc) · 3.83 KB
/
types.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package k8sattributes
type FieldExtractConfig struct {
TagName string `river:"tag_name,attr,optional"`
Key string `river:"key,attr,optional"`
KeyRegex string `river:"key_regex,attr,optional"`
Regex string `river:"regex,attr,optional"`
From string `river:"from,attr,optional"`
}
func (args FieldExtractConfig) convert() map[string]interface{} {
return map[string]interface{}{
"tag_name": args.TagName,
"key": args.Key,
"key_regex": args.KeyRegex,
"regex": args.Regex,
"from": args.From,
}
}
type ExtractConfig struct {
Metadata []string `river:"metadata,attr,optional"`
Annotations []FieldExtractConfig `river:"annotation,block,optional"`
Labels []FieldExtractConfig `river:"label,block,optional"`
}
func (args ExtractConfig) convert() map[string]interface{} {
annotations := make([]interface{}, 0, len(args.Annotations))
for _, annotation := range args.Annotations {
annotations = append(annotations, annotation.convert())
}
labels := make([]interface{}, 0, len(args.Labels))
for _, label := range args.Labels {
labels = append(labels, label.convert())
}
return map[string]interface{}{
"metadata": args.Metadata,
"annotations": annotations,
"labels": labels,
}
}
type FieldFilterConfig struct {
Key string `river:"key,attr"`
Value string `river:"value,attr"`
Op string `river:"op,attr,optional"`
}
func (args FieldFilterConfig) convert() map[string]interface{} {
return map[string]interface{}{
"key": args.Key,
"value": args.Value,
"op": args.Op,
}
}
type FilterConfig struct {
Node string `river:"node,attr,optional"`
Namespace string `river:"namespace,attr,optional"`
Fields []FieldFilterConfig `river:"field,block,optional"`
Labels []FieldFilterConfig `river:"label,block,optional"`
}
func (args FilterConfig) convert() map[string]interface{} {
result := make(map[string]interface{})
if args.Node != "" {
result["node"] = args.Node
}
if args.Namespace != "" {
result["namespace"] = args.Namespace
}
fields := make([]interface{}, 0, len(args.Fields))
for _, field := range args.Fields {
fields = append(fields, field.convert())
}
if len(fields) > 0 {
result["fields"] = fields
}
labels := make([]interface{}, 0, len(args.Labels))
for _, label := range args.Labels {
labels = append(labels, label.convert())
}
if len(labels) > 0 {
result["labels"] = labels
}
return result
}
type PodAssociation struct {
Sources []PodAssociationSource `river:"source,block"`
}
func (args PodAssociation) convert() []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(args.Sources))
for _, source := range args.Sources {
result = append(result, source.convert())
}
return result
}
type PodAssociationSource struct {
From string `river:"from,attr"`
Name string `river:"name,attr,optional"`
}
func (args PodAssociationSource) convert() map[string]interface{} {
return map[string]interface{}{
"from": args.From,
"name": args.Name,
}
}
type PodAssociationSlice []PodAssociation
func (args PodAssociationSlice) convert() []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(args))
for _, podAssociation := range args {
result = append(result, map[string]interface{}{
"sources": podAssociation.convert(),
})
}
return result
}
type ExcludeConfig struct {
Pods []ExcludePodConfig `river:"pod,block,optional"`
}
type ExcludePodConfig struct {
Name string `river:"name,attr"`
}
func (args ExcludePodConfig) convert() map[string]interface{} {
return map[string]interface{}{
"name": args.Name,
}
}
func (args ExcludeConfig) convert() map[string]interface{} {
result := make(map[string]interface{})
pods := make([]interface{}, 0, len(args.Pods))
for _, pod := range args.Pods {
pods = append(pods, pod.convert())
}
result["pods"] = pods
return result
}