Skip to content

Commit de3673a

Browse files
authored
Merge pull request prometheus-operator#1054 from adinhodovic/add-external-mixin-support
jsonnet: Add External mixin lib
2 parents 874bf08 + 0268128 commit de3673a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
local defaults = {
2+
name: error 'provide name',
3+
namespace: 'monitoring',
4+
labels: {
5+
prometheus: 'k8s',
6+
},
7+
mixin: error 'provide a mixin',
8+
};
9+
10+
function(params) {
11+
config:: defaults + params,
12+
13+
local m = self,
14+
15+
local prometheusRules = if std.objectHasAll(m.config.mixin, 'prometheusRules') || std.objectHasAll(m.config.mixin, 'prometheusAlerts') then {
16+
apiVersion: 'monitoring.coreos.com/v1',
17+
kind: 'PrometheusRule',
18+
metadata: {
19+
labels: m.config.labels,
20+
name: m.config.name,
21+
namespace: m.config.namespace,
22+
},
23+
spec: {
24+
local r = if std.objectHasAll(m.config.mixin, 'prometheusRules') then m.config.mixin.prometheusRules.groups else [],
25+
local a = if std.objectHasAll(m.config.mixin, 'prometheusAlerts') then m.config.mixin.prometheusAlerts.groups else [],
26+
groups: a + r,
27+
},
28+
},
29+
30+
local grafanaDashboards = if std.objectHasAll(m.config.mixin, 'grafanaDashboards') then (
31+
if std.objectHas(m.config, 'dashboardFolder') then {
32+
[m.config.dashboardFolder]+: m.config.mixin.grafanaDashboards,
33+
} else (m.config.mixin.grafanaDashboards)
34+
),
35+
36+
prometheusRules: prometheusRules,
37+
grafanaDashboards: grafanaDashboards,
38+
}

0 commit comments

Comments
 (0)