From 4652318767b9dbb3384e6e1e7a7d347c5c743dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=A5rtensson?= Date: Thu, 5 May 2022 17:51:24 +0200 Subject: [PATCH] Fix bug introduced by #690 --- controllers/config/controller_config.go | 17 ++++++++--------- controllers/grafana/grafana_controller.go | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/controllers/config/controller_config.go b/controllers/config/controller_config.go index f6fe8231d..4a65e9603 100644 --- a/controllers/config/controller_config.go +++ b/controllers/config/controller_config.go @@ -158,16 +158,15 @@ func (c *ControllerConfig) GetDashboards(namespace string) []*v1alpha1.GrafanaDa return c.Dashboards[namespace] } - return []*v1alpha1.GrafanaDashboardRef{} -} - -func (c *ControllerConfig) GetAllDashboards() []*v1alpha1.GrafanaDashboardRef { - c.Lock() - defer c.Unlock() + dashboards := []*v1alpha1.GrafanaDashboardRef{} - var dashboards []*v1alpha1.GrafanaDashboardRef - for _, ds := range c.Dashboards { - dashboards = append(dashboards, ds...) + // The periodic resync in grafanadashboard.GrafanaDashboardReconciler rely on the convention + // that an empty namespace means all of them, so we follow that rule here. + if namespace == "" { + for _, ds := range c.Dashboards { + dashboards = append(dashboards, ds...) + } + return dashboards } return dashboards diff --git a/controllers/grafana/grafana_controller.go b/controllers/grafana/grafana_controller.go index 54556e489..7fac7f1dc 100644 --- a/controllers/grafana/grafana_controller.go +++ b/controllers/grafana/grafana_controller.go @@ -283,7 +283,7 @@ func (r *ReconcileGrafana) manageSuccess(cr *grafanav1alpha1.Grafana, state *com // Only update the status if the dashboard controller had a chance to sync the cluster // dashboards first. Otherwise reuse the existing dashboard config from the CR. if r.Config.GetConfigBool(config.ConfigGrafanaDashboardsSynced, false) { - cr.Status.InstalledDashboards = r.Config.GetAllDashboards() + cr.Status.InstalledDashboards = r.Config.GetDashboards("") } instance := &grafanav1alpha1.Grafana{}