Skip to content

Commit c9f9f36

Browse files
committed
refactor cluster variable further
1 parent ce2bafa commit c9f9f36

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet';
2-
local var = g.dashboard.variable;
31
local common = import './common.libsonnet';
42

53
{
64
cluster(config)::
75
local datasource = common.datasource(config);
8-
local clusterVar =
9-
common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}')
10-
+ var.query.generalOptions.showOnDashboard.withLabelAndValue();
116
{
127
datasource: datasource,
13-
cluster: clusterVar,
8+
cluster: common.cluster(config, datasource),
149
},
1510
}

dashboards/resources/variables/common.libsonnet

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@ local var = g.dashboard.variable;
1515
},
1616
},
1717

18-
cluster(config, datasourceVar, selectorTemplate)::
18+
cluster(config, datasourceVar)::
1919
var.query.new('cluster')
2020
+ var.query.withDatasourceFromVariable(datasourceVar)
2121
+ var.query.queryTypes.withLabelValues(
2222
config.clusterLabel,
23-
selectorTemplate % config,
23+
'up{%(kubeStateMetricsSelector)s}' % config,
2424
)
2525
+ var.query.generalOptions.withLabel('cluster')
2626
+ var.query.refresh.onTime()
27-
+ (
28-
if config.showMultiCluster
29-
then var.query.generalOptions.showOnDashboard.withLabelAndValue()
30-
else var.query.generalOptions.showOnDashboard.withNothing()
31-
)
27+
+ var.query.generalOptions.showOnDashboard.withLabelAndValue()
3228
+ var.query.withSort(type='alphabetical'),
3329

3430
namespace(config, datasourceVar)::

dashboards/resources/variables/namespace.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local common = import './common.libsonnet';
33
{
44
namespace(config)::
55
local datasource = common.datasource(config);
6-
local clusterVar = common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}');
6+
local clusterVar = common.cluster(config, datasource);
77
{
88
datasource: datasource,
99
cluster: clusterVar,

dashboards/resources/variables/pod.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local common = import './common.libsonnet';
33
{
44
pod(config)::
55
local datasource = common.datasource(config);
6-
local clusterVar = common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}');
6+
local clusterVar = common.cluster(config, datasource);
77
{
88
datasource: datasource,
99
cluster: clusterVar,

0 commit comments

Comments
 (0)