Skip to content

Commit de586e2

Browse files
Merge pull request #319 from grafana/dont-wrap-datasources
Don't wrap datasources in an array
2 parents 0f9b4bb + 1f26aa5 commit de586e2

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

prometheus-ksonnet/grafana/datasources.libsonnet

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@
1212
grafanaDatasources+:: {},
1313

1414
// Generates yaml string containing datasource config
15-
grafana_datasource(name, url, default=false, method='GET')::
16-
{
17-
apiVersion: 1,
18-
datasources: [{
19-
name: name,
20-
type: 'prometheus',
21-
access: 'proxy',
22-
url: url,
23-
isDefault: default,
24-
version: 1,
25-
editable: false,
26-
jsonData: {
27-
httpMethod: method,
28-
},
29-
}],
15+
grafana_datasource(name, url, default=false, method='GET', type='prometheus'):: {
16+
name: name,
17+
type: type,
18+
access: 'proxy',
19+
url: url,
20+
isDefault: default,
21+
version: 1,
22+
editable: false,
23+
jsonData: {
24+
httpMethod: method,
3025
},
26+
},
3127

3228
/*
3329
helper to allow adding datasources directly to the datasource_config_map
@@ -38,29 +34,28 @@
3834
*/
3935
grafana_add_datasource(name, url, default=false, method='GET')::
4036
configMap.withDataMixin({
41-
['%s.yml' % name]: $.util.manifestYaml($.grafana_datasource(name, url, default, method)),
37+
['%s.yml' % name]: $.util.manifestYaml({
38+
apiVersion: 1,
39+
datasources: [$.grafana_datasource(name, url, default, method)],
40+
}),
4241
}),
4342

4443
// Generates yaml string containing datasource config
45-
grafana_datasource_with_basicauth(name, url, username, password, default=false, method='GET')::
46-
{
47-
apiVersion: 1,
48-
datasources: [{
49-
name: name,
50-
type: 'prometheus',
51-
access: 'proxy',
52-
url: url,
53-
isDefault: default,
54-
version: 1,
55-
editable: false,
56-
basicAuth: true,
57-
basicAuthUser: username,
58-
basicAuthPassword: password,
59-
jsonData: {
60-
httpMethod: method,
61-
},
62-
}],
44+
grafana_datasource_with_basicauth(name, url, username, password, default=false, method='GET', type='prometheus'):: {
45+
name: name,
46+
type: type,
47+
access: 'proxy',
48+
url: url,
49+
isDefault: default,
50+
version: 1,
51+
editable: false,
52+
basicAuth: true,
53+
basicAuthUser: username,
54+
basicAuthPassword: password,
55+
jsonData: {
56+
httpMethod: method,
6357
},
58+
},
6459

6560
/*
6661
helper to allow adding datasources directly to the datasource_config_map
@@ -71,17 +66,23 @@
7166
*/
7267
grafana_add_datasource_with_basicauth(name, url, username, password, default=false, method='GET')::
7368
configMap.withDataMixin({
74-
['%s.yml' % name]: $.util.manifestYaml($.grafana_datasource_with_basicauth(name, url, username, password, default, method)),
69+
['%s.yml' % name]: $.util.manifestYaml({
70+
apiVersion: 1,
71+
datasources: [$.grafana_datasource_with_basicauth(name, url, username, password, default, method)],
72+
}),
7573
}),
7674

7775
grafana_datasource_config_map:
7876
configMap.new('grafana-datasources') +
7977
configMap.withDataMixin({
80-
[name]: (
78+
[if std.endsWith(name, '.yml') then name else name + '.yml']: (
8179
if std.isString($.grafanaDatasources[name]) then
8280
$.grafanaDatasources[name]
8381
else
84-
$.util.manifestYaml($.grafanaDatasources[name])
82+
$.util.manifestYaml({
83+
apiVersion: 1,
84+
datasources: [$.grafanaDatasources[name]],
85+
})
8586
)
8687
for name in std.objectFields($.grafanaDatasources)
8788
}) +

0 commit comments

Comments
 (0)