Skip to content

Commit

Permalink
Use preferences PUT endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: João Henri <[email protected]>

wip: Use PUT endpoint
  • Loading branch information
jaehnri committed Nov 7, 2023
1 parent 9b6cb4e commit 8e66ce0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 26 deletions.
3 changes: 1 addition & 2 deletions api/v1beta1/grafana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ type GrafanaClient struct {
PreferIngress *bool `json:"preferIngress,omitempty"`
}

// GrafanaPreferences holds Grafana preferences settings
// GrafanaPreferences holds Grafana preferences API settings
type GrafanaPreferences struct {
Theme string `json:"theme"`
HomeDashboardUID string `json:"homeDashboardUid,omitempty"`
}

Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/grafana.integreatly.org_grafanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3633,10 +3633,6 @@ spec:
properties:
homeDashboardUid:
type: string
theme:
type: string
required:
- theme
type: object
route:
properties:
Expand Down
4 changes: 0 additions & 4 deletions config/grafana.integreatly.org_grafanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9033,10 +9033,6 @@ spec:
properties:
homeDashboardUid:
type: string
theme:
type: string
required:
- theme
type: object
route:
description: Route sets how the ingress object should look like with
Expand Down
14 changes: 9 additions & 5 deletions controllers/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (r *GrafanaDashboardReconciler) Reconcile(ctx context.Context, req ctrl.Req
success = false
}

if grafana.Spec.Preferences != nil && grafana.Spec.Preferences.HomeDashboardUID != "" && uid == grafana.Spec.Preferences.HomeDashboardUID {
if grafana.Spec.Preferences != nil && uid == grafana.Spec.Preferences.HomeDashboardUID {
err = r.UpdateHomeDashboard(ctx, grafana, uid, cr)
if err != nil {
return ctrl.Result{RequeueAfter: RequeueDelay}, err
Expand Down Expand Up @@ -750,10 +750,14 @@ func (r *GrafanaDashboardReconciler) UpdateHomeDashboard(ctx context.Context, gr
return err
}

_, err = grafanaClient.UpdateOrgPreferences(grapi.Preferences{
Theme: grafana.Spec.Preferences.Theme,
HomeDashboardUID: uid,
})
p, err := grafanaClient.OrgPreferences()
if err != nil {
r.Log.Error(err, "unable to fetch org preferences", "namespace", dashboard.Namespace, "name", dashboard.Name)
return err
}

p.HomeDashboardUID = uid
_, err = grafanaClient.UpdateAllOrgPreferences(p)
if err != nil {
r.Log.Error(err, "unable to update the home dashboard", "namespace", dashboard.Namespace, "name", dashboard.Name)
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3633,10 +3633,6 @@ spec:
properties:
homeDashboardUid:
type: string
theme:
type: string
required:
- theme
type: object
route:
properties:
Expand Down
6 changes: 6 additions & 0 deletions deploy/kustomize/base/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9703,6 +9703,12 @@ spec:
type: string
type: object
type: object
preferences:
description: Preferences holds the Grafana Preferences settings
properties:
homeDashboardUid:
type: string
type: object
route:
description: Route sets how the ingress object should look like with
your grafana instance, this only works in Openshift.
Expand Down
7 changes: 0 additions & 7 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15545,13 +15545,6 @@ Preferences holds the Grafana Preferences settings
</tr>
</thead>
<tbody><tr>
<td><b>theme</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>homeDashboardUid</b></td>
<td>string</td>
<td>
Expand Down

0 comments on commit 8e66ce0

Please sign in to comment.