Skip to content

Commit 405e8d7

Browse files
authored
Deduplicate dashboard folder mounts (#241)
* Deduplicate dashboard folder mounts so multiple mixins can share the same folder. Signed-off-by: Tom Wilkie <[email protected]> * make fmt Signed-off-by: Tom Wilkie <[email protected]>
1 parent 0a9945c commit 405e8d7

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

prometheus-ksonnet/grafana/deployment.libsonnet

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@
4747
{}
4848
),
4949

50+
local folder_mounts =
51+
// Dedupe folder names through a map fold first,
52+
// just incase two mixins go into the same folder.
53+
local folderShards = std.foldr(
54+
function(mixinName, acc)
55+
local mixin = $.mixins[mixinName];
56+
if !$.isFolderedMixin(mixin)
57+
then acc
58+
else acc {
59+
[$.folderID(mixin.grafanaDashboardFolder)]:
60+
if std.objectHas(mixin, 'grafanaDashboardShards')
61+
then mixin.grafanaDashboardShards
62+
else 1,
63+
},
64+
std.objectFields($.mixins),
65+
{},
66+
);
67+
std.foldr(
68+
function(folderName, acc)
69+
local config_map_name = 'dashboards-%s' % folderName;
70+
local shards = folderShards[folderName];
71+
sharded_config_map_mounts(config_map_name, shards) + acc,
72+
std.objectFields(folderShards),
73+
{},
74+
),
75+
5076
grafana_deployment:
5177
deployment.new('grafana', 1, [$.grafana_container]) +
5278
// Use configMapVolumeMount to automatically include the hash of the config
@@ -61,21 +87,7 @@
6187
sharded_config_map_mounts('dashboards', $._config.dashboard_config_maps)
6288
) + (
6389
// Add config map mounts for each folder for dashboards.
64-
std.foldr(
65-
function(mixinName, acc)
66-
local mixin = $.mixins[mixinName];
67-
if !$.isFolderedMixin(mixin)
68-
then acc
69-
else
70-
local config_map_name = 'dashboards-%s' % $.folderID(mixin.grafanaDashboardFolder);
71-
local shards =
72-
if std.objectHas(mixin, 'grafanaDashboardShards')
73-
then mixin.grafanaDashboardShards
74-
else 1;
75-
sharded_config_map_mounts(config_map_name, shards) + acc,
76-
std.objectFields($.mixins),
77-
{},
78-
)
90+
folder_mounts
7991
) +
8092
$.util.podPriority('critical'),
8193

0 commit comments

Comments
 (0)