Skip to content

Commit

Permalink
fixed loading dashboard with an id (#244)
Browse files Browse the repository at this point in the history
Co-authored-by: Herve Nicol <[email protected]>
  • Loading branch information
hervenicol and hervenicol authored Feb 6, 2025
1 parent b778e76 commit f0c7419
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- improved run-local port-forward management

### Fixed

- fixed loading dashboards when they have an `id` defined

### Removed

- Remove turtle related Alertmanager configuration
Expand Down
12 changes: 12 additions & 0 deletions internal/controller/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func getDashboardUID(dashboard map[string]interface{}) (string, error) {
return UID, nil
}

func cleanDashboardID(dashboard map[string]interface{}) {
if dashboard["id"] != nil {
delete(dashboard, "id")
}
}

func getOrgFromDashboardConfigmap(dashboard *v1.ConfigMap) (string, error) {
// Try to look for an annotation first
annotations := dashboard.GetAnnotations()
Expand Down Expand Up @@ -232,6 +238,9 @@ func (r DashboardReconciler) configureDashboard(ctx context.Context, dashboardCM
continue
}

// Clean the dashboard ID to avoid conflicts
cleanDashboardID(dashboard)

// Create or update dashboard
err = grafana.PublishDashboard(r.GrafanaAPI, dashboard)
if err != nil {
Expand Down Expand Up @@ -292,6 +301,9 @@ func (r DashboardReconciler) reconcileDelete(ctx context.Context, dashboardCM *v
continue
}

// Clean the dashboard ID to avoid conflicts
cleanDashboardID(dashboard)

_, err = r.GrafanaAPI.Dashboards.GetDashboardByUID(dashboardUID)
if err != nil {
logger.Error(err, "Failed getting dashboard")
Expand Down

0 comments on commit f0c7419

Please sign in to comment.