From ce2bafac4215afd16a99f0a2e5b90b4c9f3dc576 Mon Sep 17 00:00:00 2001 From: Serena K Date: Fri, 28 Nov 2025 13:59:20 -0500 Subject: [PATCH 1/2] fix: cluster variable in resources/cluster --- dashboards/resources/variables/cluster.libsonnet | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dashboards/resources/variables/cluster.libsonnet b/dashboards/resources/variables/cluster.libsonnet index d2126c844..083388826 100644 --- a/dashboards/resources/variables/cluster.libsonnet +++ b/dashboards/resources/variables/cluster.libsonnet @@ -1,10 +1,15 @@ +local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'; +local var = g.dashboard.variable; local common = import './common.libsonnet'; { cluster(config):: local datasource = common.datasource(config); + local clusterVar = + common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}') + + var.query.generalOptions.showOnDashboard.withLabelAndValue(); { datasource: datasource, - cluster: common.cluster(config, datasource, 'up{%(cadvisorSelector)s}'), + cluster: clusterVar, }, } From c9f9f36f48969ab896b8fdc3883990d9d2320495 Mon Sep 17 00:00:00 2001 From: Serena K Date: Fri, 28 Nov 2025 16:52:39 -0500 Subject: [PATCH 2/2] refactor cluster variable further --- dashboards/resources/variables/cluster.libsonnet | 7 +------ dashboards/resources/variables/common.libsonnet | 10 +++------- dashboards/resources/variables/namespace.libsonnet | 2 +- dashboards/resources/variables/pod.libsonnet | 2 +- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/dashboards/resources/variables/cluster.libsonnet b/dashboards/resources/variables/cluster.libsonnet index 083388826..43fe42156 100644 --- a/dashboards/resources/variables/cluster.libsonnet +++ b/dashboards/resources/variables/cluster.libsonnet @@ -1,15 +1,10 @@ -local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'; -local var = g.dashboard.variable; local common = import './common.libsonnet'; { cluster(config):: local datasource = common.datasource(config); - local clusterVar = - common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}') - + var.query.generalOptions.showOnDashboard.withLabelAndValue(); { datasource: datasource, - cluster: clusterVar, + cluster: common.cluster(config, datasource), }, } diff --git a/dashboards/resources/variables/common.libsonnet b/dashboards/resources/variables/common.libsonnet index 4926fd9e2..b1b73ad2e 100644 --- a/dashboards/resources/variables/common.libsonnet +++ b/dashboards/resources/variables/common.libsonnet @@ -15,20 +15,16 @@ local var = g.dashboard.variable; }, }, - cluster(config, datasourceVar, selectorTemplate):: + cluster(config, datasourceVar):: var.query.new('cluster') + var.query.withDatasourceFromVariable(datasourceVar) + var.query.queryTypes.withLabelValues( config.clusterLabel, - selectorTemplate % config, + 'up{%(kubeStateMetricsSelector)s}' % config, ) + var.query.generalOptions.withLabel('cluster') + var.query.refresh.onTime() - + ( - if config.showMultiCluster - then var.query.generalOptions.showOnDashboard.withLabelAndValue() - else var.query.generalOptions.showOnDashboard.withNothing() - ) + + var.query.generalOptions.showOnDashboard.withLabelAndValue() + var.query.withSort(type='alphabetical'), namespace(config, datasourceVar):: diff --git a/dashboards/resources/variables/namespace.libsonnet b/dashboards/resources/variables/namespace.libsonnet index 091173361..c523666f6 100644 --- a/dashboards/resources/variables/namespace.libsonnet +++ b/dashboards/resources/variables/namespace.libsonnet @@ -3,7 +3,7 @@ local common = import './common.libsonnet'; { namespace(config):: local datasource = common.datasource(config); - local clusterVar = common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}'); + local clusterVar = common.cluster(config, datasource); { datasource: datasource, cluster: clusterVar, diff --git a/dashboards/resources/variables/pod.libsonnet b/dashboards/resources/variables/pod.libsonnet index 37f7204bd..33baaa2e4 100644 --- a/dashboards/resources/variables/pod.libsonnet +++ b/dashboards/resources/variables/pod.libsonnet @@ -3,7 +3,7 @@ local common = import './common.libsonnet'; { pod(config):: local datasource = common.datasource(config); - local clusterVar = common.cluster(config, datasource, 'up{%(kubeStateMetricsSelector)s}'); + local clusterVar = common.cluster(config, datasource); { datasource: datasource, cluster: clusterVar,