From 8e66ce0684525a640b9fbc60c08a0b5dab91a432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henri?= Date: Tue, 7 Nov 2023 19:12:07 -0300 Subject: [PATCH] Use preferences PUT endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Henri wip: Use PUT endpoint --- api/v1beta1/grafana_types.go | 3 +-- .../bases/grafana.integreatly.org_grafanas.yaml | 4 ---- config/grafana.integreatly.org_grafanas.yaml | 4 ---- controllers/dashboard_controller.go | 14 +++++++++----- .../crds/grafana.integreatly.org_grafanas.yaml | 4 ---- deploy/kustomize/base/crds.yaml | 6 ++++++ docs/docs/api.md | 7 ------- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/api/v1beta1/grafana_types.go b/api/v1beta1/grafana_types.go index 0dd19af58..347c626d8 100644 --- a/api/v1beta1/grafana_types.go +++ b/api/v1beta1/grafana_types.go @@ -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"` } diff --git a/config/crd/bases/grafana.integreatly.org_grafanas.yaml b/config/crd/bases/grafana.integreatly.org_grafanas.yaml index 2f7b3dc21..37454f569 100644 --- a/config/crd/bases/grafana.integreatly.org_grafanas.yaml +++ b/config/crd/bases/grafana.integreatly.org_grafanas.yaml @@ -3633,10 +3633,6 @@ spec: properties: homeDashboardUid: type: string - theme: - type: string - required: - - theme type: object route: properties: diff --git a/config/grafana.integreatly.org_grafanas.yaml b/config/grafana.integreatly.org_grafanas.yaml index 3d41d8363..0438586a4 100644 --- a/config/grafana.integreatly.org_grafanas.yaml +++ b/config/grafana.integreatly.org_grafanas.yaml @@ -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 diff --git a/controllers/dashboard_controller.go b/controllers/dashboard_controller.go index cad70bc37..b23b0e210 100644 --- a/controllers/dashboard_controller.go +++ b/controllers/dashboard_controller.go @@ -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 @@ -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 diff --git a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml index 2f7b3dc21..37454f569 100644 --- a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml +++ b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml @@ -3633,10 +3633,6 @@ spec: properties: homeDashboardUid: type: string - theme: - type: string - required: - - theme type: object route: properties: diff --git a/deploy/kustomize/base/crds.yaml b/deploy/kustomize/base/crds.yaml index 6154a4bd6..8713813f3 100644 --- a/deploy/kustomize/base/crds.yaml +++ b/deploy/kustomize/base/crds.yaml @@ -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. diff --git a/docs/docs/api.md b/docs/docs/api.md index 051f62410..c90679fb9 100644 --- a/docs/docs/api.md +++ b/docs/docs/api.md @@ -15545,13 +15545,6 @@ Preferences holds the Grafana Preferences settings - theme - string - -
- - true - homeDashboardUid string