From 76ac844ccbaa2bb2f176f547e1dabbe1a431b8bc Mon Sep 17 00:00:00 2001 From: Gabriel Bernal Date: Tue, 2 Apr 2024 11:40:20 +0200 Subject: [PATCH] fix dashboards api definition nesting --- api/v1alpha1/perses_dashboard.go | 2 +- .../bases/perses.dev_persesdashboards.yaml | 239 ++++++++---------- controllers/dashboard_controller_test.go | 2 +- controllers/dashboards/dasboard_controller.go | 11 +- 4 files changed, 115 insertions(+), 139 deletions(-) diff --git a/api/v1alpha1/perses_dashboard.go b/api/v1alpha1/perses_dashboard.go index d2f25f8..773fe18 100644 --- a/api/v1alpha1/perses_dashboard.go +++ b/api/v1alpha1/perses_dashboard.go @@ -6,7 +6,7 @@ import ( ) type Dashboard struct { - persesv1.Dashboard `json:",inline"` + persesv1.DashboardSpec `json:",inline"` } func (in *Dashboard) DeepCopyInto(out *Dashboard) { diff --git a/config/crd/bases/perses.dev_persesdashboards.yaml b/config/crd/bases/perses.dev_persesdashboards.yaml index 2e58a8e..8801c26 100644 --- a/config/crd/bases/perses.dev_persesdashboards.yaml +++ b/config/crd/bases/perses.dev_persesdashboards.yaml @@ -34,47 +34,77 @@ spec: type: object spec: properties: - kind: - type: string - metadata: - description: ProjectMetadata is the metadata struct for resources - that belongs to a project. + datasources: + additionalProperties: + properties: + default: + type: boolean + display: + properties: + description: + type: string + name: + type: string + type: object + plugin: + description: Plugin will contain the datasource configuration. + The data typed is available in Cue. + properties: + kind: + type: string + spec: + x-kubernetes-preserve-unknown-fields: true + required: + - kind + - spec + type: object + required: + - default + - plugin + type: object + description: Datasources is an optional list of datasource definition. + type: object + display: properties: - createdAt: - format: date-time + description: type: string name: type: string - project: - type: string - updatedAt: - format: date-time - type: string - version: - format: int64 - type: integer - required: - - name - - project - - version type: object - spec: - properties: - datasources: - additionalProperties: + duration: + description: Duration is the default time range to use when getting + data to fill the dashboard + format: duration + type: string + layouts: + items: + properties: + kind: + type: string + spec: + x-kubernetes-preserve-unknown-fields: true + required: + - kind + - spec + type: object + type: array + panels: + additionalProperties: + properties: + kind: + type: string + spec: properties: - default: - type: boolean display: properties: description: type: string name: type: string + required: + - name type: object plugin: - description: Plugin will contain the datasource configuration. - The data typed is available in Cue. properties: kind: type: string @@ -84,124 +114,63 @@ spec: - kind - spec type: object - required: - - default - - plugin - type: object - description: Datasources is an optional list of datasource definition. - type: object - display: - properties: - description: - type: string - name: - type: string - type: object - duration: - description: Duration is the default time range to use when getting - data to fill the dashboard - format: duration - type: string - layouts: - items: - properties: - kind: - type: string - spec: - x-kubernetes-preserve-unknown-fields: true - required: - - kind - - spec - type: object - type: array - panels: - additionalProperties: - properties: - kind: - type: string - spec: - properties: - display: - properties: - description: - type: string - name: - type: string - required: - - name - type: object - plugin: - properties: - kind: - type: string - spec: - x-kubernetes-preserve-unknown-fields: true - required: - - kind - - spec - type: object - queries: - items: + queries: + items: + properties: + kind: + type: string + spec: properties: - kind: - type: string - spec: + plugin: properties: - plugin: - properties: - kind: - type: string - spec: - x-kubernetes-preserve-unknown-fields: true - required: - - kind - - spec - type: object + kind: + type: string + spec: + x-kubernetes-preserve-unknown-fields: true required: - - plugin + - kind + - spec type: object required: - - kind - - spec + - plugin type: object - type: array - required: - - display - - plugin - type: object - required: - - kind - - spec - type: object - type: object - refreshInterval: - description: RefreshInterval is the default refresh interval to - use when landing on the dashboard - format: duration - type: string - variables: - items: - properties: - kind: - description: Kind is the type of the variable. Depending - on the value of Kind, it will change the content of Spec. - type: string - spec: - x-kubernetes-preserve-unknown-fields: true + required: + - kind + - spec + type: object + type: array required: - - kind - - spec + - display + - plugin type: object - type: array - required: - - duration - - layouts - - panels + required: + - kind + - spec + type: object type: object + refreshInterval: + description: RefreshInterval is the default refresh interval to use + when landing on the dashboard + format: duration + type: string + variables: + items: + properties: + kind: + description: Kind is the type of the variable. Depending on + the value of Kind, it will change the content of Spec. + type: string + spec: + x-kubernetes-preserve-unknown-fields: true + required: + - kind + - spec + type: object + type: array required: - - kind - - metadata - - spec + - duration + - layouts + - panels type: object status: description: PersesDashboardStatus defines the observed state of PersesDashboard diff --git a/controllers/dashboard_controller_test.go b/controllers/dashboard_controller_test.go index 4abf300..14e0079 100644 --- a/controllers/dashboard_controller_test.go +++ b/controllers/dashboard_controller_test.go @@ -119,7 +119,7 @@ var _ = Describe("Dashboard controller", func() { Namespace: PersesNamespace, }, Spec: persesv1alpha1.Dashboard{ - Dashboard: *newDashboard, + DashboardSpec: newDashboard.Spec, }, } diff --git a/controllers/dashboards/dasboard_controller.go b/controllers/dashboards/dasboard_controller.go index c3d1a2e..c069e15 100644 --- a/controllers/dashboards/dasboard_controller.go +++ b/controllers/dashboards/dasboard_controller.go @@ -94,8 +94,15 @@ func (r *PersesDashboardReconciler) syncPersesDashboard(ctx context.Context, per _, err = persesClient.Dashboard(dashboard.Namespace).Get(dashboard.Name) - persesDashboard := &dashboard.Spec.Dashboard - persesDashboard.Metadata.Name = dashboard.Name + persesDashboard := &persesv1.Dashboard{ + Kind: persesv1.KindDashboard, + Metadata: persesv1.ProjectMetadata{ + Metadata: persesv1.Metadata{ + Name: dashboard.Name, + }, + }, + Spec: dashboard.Spec.DashboardSpec, + } if err != nil { if errors.Is(err, perseshttp.RequestNotFoundError) {