Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controllers/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,20 @@ func (r *GrafanaDashboardReconciler) Reconcile(ctx context.Context, req ctrl.Req
err = ReconcilePlugins(ctx, r.Client, r.Scheme, &grafana, cr.Spec.Plugins, fmt.Sprintf("%v-dashboard", cr.Name))
if err != nil {
pluginErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = err.Error()
log.Error(err, "error reconciling plugins", "dashboard", cr.Name, "grafana", grafana.Name)
log.Error(err, "error reconciling plugins", "dashboard", cr.Name, "grafana", grafana.Name, "uid", uid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a mistake that we log here as the error is added to the pluginErrors map and printed later, we should instead remove this to not log the same error twice 😅

}
}

// then import the dashboard into the matching grafana instances
err = r.onDashboardCreated(ctx, &grafana, cr, dashboardModel, hash, folderUID)
if err != nil {
applyErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = err.Error()
applyErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = fmt.Sprintf("uid=%s: %s", uid, err.Error())
Copy link
Collaborator

@Baarsgaard Baarsgaard Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would revert this addition as we print all the errors at the end of the reconciliation.

}

if grafana.Spec.Preferences != nil && uid == grafana.Spec.Preferences.HomeDashboardUID {
err = r.UpdateHomeDashboard(ctx, grafana, uid, cr)
if err != nil {
applyHomeErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = err.Error()
applyHomeErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = fmt.Sprintf("uid=%s: %s", uid, err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this 🙂

}
}
}
Expand All @@ -208,7 +208,7 @@ func (r *GrafanaDashboardReconciler) Reconcile(ctx context.Context, req ctrl.Req
meta.SetStatusCondition(&cr.Status.Conditions, condition)

if len(allApplyErrors) > 0 {
return ctrl.Result{}, fmt.Errorf("failed to apply to all instances: %v", allApplyErrors)
return ctrl.Result{}, fmt.Errorf("uid=%s: failed to apply to all instances: %v", uid, allApplyErrors)
}

cr.Status.Hash = hash
Expand Down
6 changes: 4 additions & 2 deletions controllers/datasource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (r *GrafanaDatasourceReconciler) Reconcile(ctx context.Context, req ctrl.Re

log.Info("found matching Grafana instances for datasource", "count", len(instances))

uid := cr.CustomUIDOrUID()
if cr.IsUpdatedUID() {
log.Info("datasource uid got updated, deleting datasources with the old uid")

Expand Down Expand Up @@ -152,13 +153,14 @@ func (r *GrafanaDatasourceReconciler) Reconcile(ctx context.Context, req ctrl.Re
err = ReconcilePlugins(ctx, r.Client, r.Scheme, &grafana, cr.Spec.Plugins, fmt.Sprintf("%v-datasource", cr.Name))
if err != nil {
pluginErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = err.Error()
log.Error(err, "error reconciling plugins", "datasource", cr.Name, "grafana", grafana.Name, "uid", uid)
}
}

// then import the datasource into the matching grafana instances
err = r.onDatasourceCreated(ctx, &grafana, cr, datasource, hash)
if err != nil {
applyErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = err.Error()
applyErrors[fmt.Sprintf("%s/%s", grafana.Namespace, grafana.Name)] = fmt.Sprintf("uid=%s: %s", uid, err.Error())
}
}

Expand All @@ -173,7 +175,7 @@ func (r *GrafanaDatasourceReconciler) Reconcile(ctx context.Context, req ctrl.Re
meta.SetStatusCondition(&cr.Status.Conditions, condition)

if len(allApplyErrors) > 0 {
return ctrl.Result{}, fmt.Errorf("failed to apply to all instances: %v", allApplyErrors)
return ctrl.Result{}, fmt.Errorf("uid=%s: failed to apply to all instances: %v", uid, allApplyErrors)
}

cr.Status.Hash = hash
Expand Down
Loading