Skip to content

Commit f62b650

Browse files
Merge pull request #307 from grafana/datasources-in-json
Allow datasources as JSON objects not just YAML strings
2 parents 08a81ef + f3852e8 commit f62b650

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

prometheus-ksonnet/grafana/datasources.libsonnet

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// Generates yaml string containing datasource config
1515
grafana_datasource(name, url, default=false, method='GET')::
16-
$.util.manifestYaml({
16+
{
1717
apiVersion: 1,
1818
datasources: [{
1919
name: name,
@@ -27,7 +27,7 @@
2727
httpMethod: method,
2828
},
2929
}],
30-
}),
30+
},
3131

3232
/*
3333
helper to allow adding datasources directly to the datasource_config_map
@@ -38,12 +38,12 @@
3838
*/
3939
grafana_add_datasource(name, url, default=false, method='GET')::
4040
configMap.withDataMixin({
41-
['%s.yml' % name]: $.grafana_datasource(name, url, default, method),
41+
['%s.yml' % name]: $.util.manifestYaml($.grafana_datasource(name, url, default, method)),
4242
}),
4343

4444
// Generates yaml string containing datasource config
4545
grafana_datasource_with_basicauth(name, url, username, password, default=false, method='GET')::
46-
$.util.manifestYaml({
46+
{
4747
apiVersion: 1,
4848
datasources: [{
4949
name: name,
@@ -60,7 +60,7 @@
6060
httpMethod: method,
6161
},
6262
}],
63-
}),
63+
},
6464

6565
/*
6666
helper to allow adding datasources directly to the datasource_config_map
@@ -71,13 +71,18 @@
7171
*/
7272
grafana_add_datasource_with_basicauth(name, url, username, password, default=false, method='GET')::
7373
configMap.withDataMixin({
74-
['%s.yml' % name]: $.grafana_datasource_with_basicauth(name, url, username, password, default, method),
74+
['%s.yml' % name]: $.util.manifestYaml($.grafana_datasource_with_basicauth(name, url, username, password, default, method)),
7575
}),
7676

7777
grafana_datasource_config_map:
7878
configMap.new('grafana-datasources') +
7979
configMap.withDataMixin({
80-
[name]: std.toString($.grafanaDatasources[name])
80+
[name]: (
81+
if std.isString($.grafanaDatasources[name]) then
82+
$.grafanaDatasources[name]
83+
else
84+
$.util.manifestYaml($.grafanaDatasources[name])
85+
)
8186
for name in std.objectFields($.grafanaDatasources)
8287
}) +
8388
configMap.mixin.metadata.withLabels($._config.grafana_datasource_labels),

0 commit comments

Comments
 (0)