Skip to content

Commit

Permalink
Fix dashboard update
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Aug 16, 2024
1 parent 892f044 commit 7dbd1ce
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/controllers/openviz/grafanadashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,23 @@ func (r *GrafanaDashboardReconciler) deleteExternalDashboard(ctx context.Context
}

func (r *GrafanaDashboardReconciler) setDashboard(ctx context.Context, obj *openvizapi.GrafanaDashboard) (ctrl.Result, error) {
if obj.Status.Dashboard != nil {
ab, err := openvizapi.GetGrafana(ctx, r.Client, obj.Spec.GrafanaRef.WithNamespace(obj.Namespace))
if err != nil {
return r.handleSetDashboardError(ctx, obj, err, false)
}

state, err := GrafanaState(ab)
if err != nil {
return r.handleSetDashboardError(ctx, obj, err, false)
}

if obj.Status.Dashboard != nil && (obj.Status.Dashboard.State == nil || *obj.Status.Dashboard.State == state) {
model, err := addDashboardID(obj.Spec.Model.Raw, *obj.Status.Dashboard.ID, *obj.Status.Dashboard.UID)
if err != nil {
return r.handleSetDashboardError(ctx, obj, err, false)
}
obj.Spec.Model = &runtime.RawExtension{Raw: model}
}
ab, err := openvizapi.GetGrafana(ctx, r.Client, obj.Spec.GrafanaRef.WithNamespace(obj.Namespace))
if err != nil {
return r.handleSetDashboardError(ctx, obj, err, false)
}

dsConfig := &openvizapi.GrafanaConfiguration{}
if ab.Spec.Parameters != nil {
Expand Down Expand Up @@ -327,11 +333,6 @@ func (r *GrafanaDashboardReconciler) setDashboard(ctx context.Context, obj *open
return r.handleSetDashboardError(ctx, obj, err, false)
}

state, err := GrafanaState(ab)
if err != nil {
return r.handleSetDashboardError(ctx, obj, err, false)
}

_, err = kmc.PatchStatus(ctx, r.Client, obj, func(obj client.Object) client.Object {
in := obj.(*openvizapi.GrafanaDashboard)
reason := "Dashboard is successfully created"
Expand Down

0 comments on commit 7dbd1ce

Please sign in to comment.