This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.go
107 lines (97 loc) · 2.64 KB
/
app.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
package servicemonitor
type ConfigEndpoint struct {
Port string
TargetPort string
Interval string
Scheme string
Path string
BearerTokenFile string
MetricRelabelings []*ConfigRelabeling
Relabelings []*ConfigRelabeling
TLSConfig *ConfigTLSConfig
HonorLabels bool
}
type ConfigTLSConfig struct {
CaFile string
ServerName string
}
type ConfigRelabeling struct {
Action string
Regex string
SourceLabels []string
TargetLabel string
Replacement string
}
type Config struct {
Name string
Endpoints []*ConfigEndpoint
NamespaceSelector []string
MonitorMatchingLabels map[string]string
ServiceMatchingLabels map[string]string
JobName string
}
func SpecToValues(config *Config) *Values {
endpoints := make([]*Endpoint, 0)
for _, endpoint := range config.Endpoints {
metricRels := make([]*MetricRelabeling, 0)
for _, relabel := range endpoint.MetricRelabelings {
rel := &MetricRelabeling{
Action: relabel.Action,
Regex: relabel.Regex,
SourceLabels: relabel.SourceLabels,
TargetLabel: relabel.TargetLabel,
Replacement: relabel.Replacement,
}
metricRels = append(metricRels, rel)
}
rels := make([]*Relabeling, 0)
for _, relabel := range endpoint.Relabelings {
rel := &Relabeling{
Action: relabel.Action,
Regex: relabel.Regex,
SourceLabels: relabel.SourceLabels,
TargetLabel: relabel.TargetLabel,
Replacement: relabel.Replacement,
}
rels = append(rels, rel)
}
valueEndpoint := &Endpoint{
Port: endpoint.Port,
TargetPort: endpoint.TargetPort,
Interval: endpoint.Interval,
Scheme: endpoint.Scheme,
Path: endpoint.Path,
BearerTokenFile: endpoint.BearerTokenFile,
MetricRelabelings: metricRels,
Relabelings: rels,
HonorLabels: endpoint.HonorLabels,
}
if endpoint.TLSConfig != nil {
t := &TLSConfig{
CaFile: endpoint.TLSConfig.CaFile,
ServerName: endpoint.TLSConfig.ServerName,
}
valueEndpoint.TLSConfig = t
}
endpoints = append(endpoints, valueEndpoint)
}
values := &Values{
Name: config.Name,
AdditionalLabels: config.MonitorMatchingLabels,
Selector: &Selector{
MatchLabels: config.ServiceMatchingLabels,
},
NamespaceSelector: &NamespaceSelector{
Any: true,
},
JobLabel: config.JobName,
Endpoints: endpoints,
}
if len(config.NamespaceSelector) != 0 {
values.NamespaceSelector = &NamespaceSelector{
Any: false,
MatchNames: config.NamespaceSelector,
}
}
return values
}