From 27b674d7e3b826421ed0a58774271b28b39719e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:37:29 +0200 Subject: [PATCH 1/7] Add default value to grafana_dashboard_api_version variable at prometheusexporter ansile role --- roles/prometheusexporter/defaults/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/prometheusexporter/defaults/main.yml b/roles/prometheusexporter/defaults/main.yml index f493703..c865fec 100644 --- a/roles/prometheusexporter/defaults/main.yml +++ b/roles/prometheusexporter/defaults/main.yml @@ -11,3 +11,4 @@ service_monitor_interval: "30s" grafana_dashboard_state: "present" # Converted to ansible state "absent" with an ansible set_fact task if CR boolean grafanaDashboard.enabled = false grafana_dashboard_label_key: "discovery" grafana_dashboard_label_value: "enabled" +grafana_dashboard_api_version: "v1alpha1" # Converted to ansible "v1beta1" with an ansible set_fact task if CR grafanaDashboard.apiVersion = v1beta1 \ No newline at end of file From 1cf4ba0ec91f9621734d207e3ddb40c1b27f48c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:37:29 +0200 Subject: [PATCH 2/7] Update grafana dashboard jinja template with different apiVersion and label selector fields depending on grafana_dashboard_api_version value at prometheusexporter ansile role --- roles/prometheusexporter/tasks/main.yml | 12 ++++++++++++ .../templates/grafanadashboard.yml.j2 | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/roles/prometheusexporter/tasks/main.yml b/roles/prometheusexporter/tasks/main.yml index 72a2559..3124dde 100644 --- a/roles/prometheusexporter/tasks/main.yml +++ b/roles/prometheusexporter/tasks/main.yml @@ -33,6 +33,16 @@ grafana_dashboard_state: "absent" when: grafana_dashboard.enabled is defined and grafana_dashboard.enabled|bool == false +- name: Convert possible grafanaDashboard.apiVersion v1alpha1 string var into ansible grafana_dashboard_api_version var for PrometheusExporter {{ ansible_operator_meta.name }} on Namespace { ansible_operator_meta.namespace }} + set_fact: + grafana_dashboard_api_version: "v1alpha1" + when: grafana_dashboard.api_version is defined and grafana_dashboard.api_version|string == "v1alpha1" + +- name: Convert possible grafanaDashboard.apiVersion v1beta1 string var into ansible grafana_dashboard_api_version var for PrometheusExporter {{ ansible_operator_meta.name }} on Namespace { ansible_operator_meta.namespace }} + set_fact: + grafana_dashboard_api_version: "v1beta1" + when: grafana_dashboard.api_version is defined and grafana_dashboard.api_version|string == "v1beta1" + - name: Manage GrafanaDashboard (if integreatly.org api-group exists) for PrometheusExporter {{ ansible_operator_meta.name }} on Namespace {{ ansible_operator_meta.namespace }} k8s: state: "{{ grafana_dashboard_state }}" @@ -41,3 +51,5 @@ loop: - name: "grafanadashboard.yml.j2" api_exists: "{{ True if 'integreatly.org' in api_groups else False }}" + - name: "grafanadashboard.yml.j2" + api_exists: "{{ True if 'grafana.integreatly.org' in api_groups else False }}" \ No newline at end of file diff --git a/roles/prometheusexporter/templates/grafanadashboard.yml.j2 b/roles/prometheusexporter/templates/grafanadashboard.yml.j2 index 4a042c7..c39b570 100644 --- a/roles/prometheusexporter/templates/grafanadashboard.yml.j2 +++ b/roles/prometheusexporter/templates/grafanadashboard.yml.j2 @@ -1,12 +1,23 @@ +{% if grafana_dashboard_api_version == "v1alpha1" %} apiVersion: integreatly.org/v1alpha1 +{% elif grafana_dashboard_api_version == "v1beta1" %} +apiVersion: grafana.integreatly.org/v1beta1 +{% endif %} kind: GrafanaDashboard metadata: name: "prometheus-exporter-{{ type }}" namespace: "{{ ansible_operator_meta.namespace }}" labels: prometheus_exporter_type: "{{ type }}" +{% if grafana_dashboard_api_version == "v1alpha1" %} "{{ grafana_dashboard.label.key | default(grafana_dashboard_label_key) }}": "{{ grafana_dashboard.label.value | default(grafana_dashboard_label_value) }}" +{% endif %} spec: +{% if grafana_dashboard_api_version == "v1beta1" %} + instanceSelector: + matchLabels: + "{{ grafana_dashboard.label.key | default(grafana_dashboard_label_key) }}": "{{ grafana_dashboard.label.value | default(grafana_dashboard_label_value) }}" +{% endif %} json: > {## ##} {% filter indent(4, True) %} From 00f565549f5cb01797756eb5d9e1ef7f23cd0faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:37:29 +0200 Subject: [PATCH 3/7] Add new optional grafanaDashboard.apiVersion CRD field with 2 possible values --- .../bases/monitoring.3scale.net_prometheusexporters.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/crd/bases/monitoring.3scale.net_prometheusexporters.yaml b/config/crd/bases/monitoring.3scale.net_prometheusexporters.yaml index 280d742..ffe5e12 100644 --- a/config/crd/bases/monitoring.3scale.net_prometheusexporters.yaml +++ b/config/crd/bases/monitoring.3scale.net_prometheusexporters.yaml @@ -69,6 +69,12 @@ spec: value: type: string description: Label value used by grafana-operator for dashboard discovery + apiVersion: + type: string + description: GrafanaDashboard custom resource apiVersion + enum: + - v1alpha1 + - v1beta1 extraLabel: type: object properties: From 9e77846fea0d2474cb46ca095daa7d52873297c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:37:29 +0200 Subject: [PATCH 4/7] Update docs with new optional grafanaDashboard.apiVersion CRD field --- docs/prometheus-exporter-crd-reference.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/prometheus-exporter-crd-reference.md b/docs/prometheus-exporter-crd-reference.md index eddefc1..1ad221d 100644 --- a/docs/prometheus-exporter-crd-reference.md +++ b/docs/prometheus-exporter-crd-reference.md @@ -19,6 +19,7 @@ spec: label: key: monitoring-key value: middleware + apiVersion: grafana.integreatly.org/v1beta1 extraLabel: key: tier value: frontend @@ -59,6 +60,7 @@ spec: | `grafanaDashboard.enabled` | `bool` | No | `true` | Create (`true`) or not (`false`) GrafanaDashboard object | | `grafanaDashboard.label.key` | `string` | No | discovery | Label `key` used by grafana-operator for dashboard discovery | | `grafanaDashboard.label.value` | `string` | No | enabled | Label `value` used by grafana-operator for dashboard discovery | +| `grafanaDashboard.apiVersion` | `string` | No | v1alpha1 | GrafanaDashboard custom resource apiVersion | | `extraLabel.key` | `string` | No | - | Add extra label `key` to all created resources (example `tier`) | | `extraLabel.value` | `string` | No | - | Add extra label `value` to all created resources (example `frontend`) | | `image.name` | `string` | No | Depends on exporter | Prometheus exporter image name | From fc43dab4fa968a1f1036252370ae576cb190347d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:37:29 +0200 Subject: [PATCH 5/7] Add new grafanaDashboard CRD with new apiVersion grafana.integreatly.org/v1beta1 --- config/rbac/role.yaml | 1 + ...anadashboards.grafana.integreatly.org.yaml | 235 ++++++++++++++++++ config/testing/kustomization.yaml | 1 + 3 files changed, 237 insertions(+) create mode 100644 config/testing/external-apis/grafanadashboards.grafana.integreatly.org.yaml diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index a60115f..774b3e2 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -58,6 +58,7 @@ rules: - watch - apiGroups: - integreatly.org + - grafana.integreatly.org resources: - grafanadashboards verbs: diff --git a/config/testing/external-apis/grafanadashboards.grafana.integreatly.org.yaml b/config/testing/external-apis/grafanadashboards.grafana.integreatly.org.yaml new file mode 100644 index 0000000..11536e6 --- /dev/null +++ b/config/testing/external-apis/grafanadashboards.grafana.integreatly.org.yaml @@ -0,0 +1,235 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.0 + name: grafanadashboards.grafana.integreatly.org +spec: + group: grafana.integreatly.org + names: + kind: GrafanaDashboard + listKind: GrafanaDashboardList + plural: grafanadashboards + singular: grafanadashboard + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .status.NoMatchingInstances + name: No matching instances + type: boolean + - format: date-time + jsonPath: .status.lastResync + name: Last resync + type: date + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + properties: + apiVersion: + type: string + kind: + type: string + metadata: + type: object + spec: + properties: + allowCrossNamespaceImport: + type: boolean + configMapRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + contentCacheDuration: + type: string + datasources: + items: + properties: + datasourceName: + type: string + inputName: + type: string + required: + - datasourceName + - inputName + type: object + type: array + envFrom: + items: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + type: array + envs: + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + folder: + type: string + grafanaCom: + properties: + id: + type: integer + revision: + type: integer + required: + - id + type: object + gzipJson: + format: byte + type: string + instanceSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic + json: + type: string + jsonnet: + type: string + jsonnetLib: + properties: + fileName: + type: string + gzipJsonnetProject: + format: byte + type: string + jPath: + items: + type: string + type: array + required: + - fileName + - gzipJsonnetProject + type: object + plugins: + items: + properties: + name: + type: string + version: + type: string + required: + - name + - version + type: object + type: array + resyncPeriod: + type: string + url: + type: string + required: + - instanceSelector + type: object + status: + properties: + NoMatchingInstances: + type: boolean + contentCache: + format: byte + type: string + contentTimestamp: + format: date-time + type: string + contentUrl: + type: string + hash: + type: string + lastResync: + format: date-time + type: string + uid: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} \ No newline at end of file diff --git a/config/testing/kustomization.yaml b/config/testing/kustomization.yaml index 2f3d477..07798f8 100644 --- a/config/testing/kustomization.yaml +++ b/config/testing/kustomization.yaml @@ -18,6 +18,7 @@ resources: - ../manager - external-apis/servicemonitors.monitoring.coreos.com.yaml - external-apis/grafanadashboards.integreatly.org.yaml +- external-apis/grafanadashboards.grafana.integreatly.org.yaml images: - name: testing newName: testing-operator From 8aa860bde50b5ea5bbca7d5d32483aa943ee23f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:37:30 +0200 Subject: [PATCH 6/7] Add new e2e test for a prometheusexporter with non default grafanaDashboard.apiVersion --- .../01-assert.yaml | 26 +++++++++++++++++++ .../01-prometheusexporter.yaml | 14 ++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/e2e/prometheusexporter-grafanadashboard-apiversion/01-assert.yaml create mode 100644 test/e2e/prometheusexporter-grafanadashboard-apiversion/01-prometheusexporter.yaml diff --git a/test/e2e/prometheusexporter-grafanadashboard-apiversion/01-assert.yaml b/test/e2e/prometheusexporter-grafanadashboard-apiversion/01-assert.yaml new file mode 100644 index 0000000..705f8aa --- /dev/null +++ b/test/e2e/prometheusexporter-grafanadashboard-apiversion/01-assert.yaml @@ -0,0 +1,26 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus-exporter-memcached-example2-memcached + namespace: default +status: + readyReplicas: 1 +--- +apiVersion: v1 +kind: Service +metadata: + name: prometheus-exporter-memcached-example2-memcached + namespace: default +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: prometheus-exporter-memcached-example2-memcached + namespace: default +--- +apiVersion: grafana.integreatly.org/v1beta1 +kind: GrafanaDashboard +metadata: + name: prometheus-exporter-memcached + namespace: default \ No newline at end of file diff --git a/test/e2e/prometheusexporter-grafanadashboard-apiversion/01-prometheusexporter.yaml b/test/e2e/prometheusexporter-grafanadashboard-apiversion/01-prometheusexporter.yaml new file mode 100644 index 0000000..b315571 --- /dev/null +++ b/test/e2e/prometheusexporter-grafanadashboard-apiversion/01-prometheusexporter.yaml @@ -0,0 +1,14 @@ +apiVersion: monitoring.3scale.net/v1alpha1 +kind: PrometheusExporter +metadata: + name: example2-memcached + namespace: default +spec: + type: memcached + grafanaDashboard: + label: + key: autodiscovery + value: enabled + apiVersion: v1beta1 + dbHost: your-memcached-host + dbPort: 11211 \ No newline at end of file From d45f584b3f2663f1dfe3c83cfb2cbec3ac0992ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20L=C3=B3pez?= Date: Fri, 1 Sep 2023 18:39:01 +0200 Subject: [PATCH 7/7] Alpha release v0.7.0-alpha.1 --- Makefile | 2 +- bundle.Dockerfile | 3 +-- .../monitoring.3scale.net_prometheusexporters.yaml | 6 ++++++ ...prometheus-exporter-operator.clusterserviceversion.yaml | 7 ++++--- bundle/metadata/annotations.yaml | 3 +-- config/manager/kustomization.yaml | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 1ed3489..be8f183 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # To re-generate a bundle for another specific version without changing the standard setup, you can: # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) -VERSION ?= 0.6.2 +VERSION ?= 0.7.0-alpha.1 # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") diff --git a/bundle.Dockerfile b/bundle.Dockerfile index 07c3405..9fc49ea 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -5,8 +5,7 @@ LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=prometheus-exporter-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha,stable -LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha +LABEL operators.operatorframework.io.bundle.channels.v1=alpha LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.24.0 LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=ansible.sdk.operatorframework.io/v1 diff --git a/bundle/manifests/monitoring.3scale.net_prometheusexporters.yaml b/bundle/manifests/monitoring.3scale.net_prometheusexporters.yaml index d660617..7fe12ca 100644 --- a/bundle/manifests/monitoring.3scale.net_prometheusexporters.yaml +++ b/bundle/manifests/monitoring.3scale.net_prometheusexporters.yaml @@ -74,6 +74,12 @@ spec: type: object grafanaDashboard: properties: + apiVersion: + description: GrafanaDashboard custom resource apiVersion + enum: + - v1alpha1 + - v1beta1 + type: string enabled: description: Create (true) or not (false) GrafanaDashboard object type: boolean diff --git a/bundle/manifests/prometheus-exporter-operator.clusterserviceversion.yaml b/bundle/manifests/prometheus-exporter-operator.clusterserviceversion.yaml index 7d33ee5..3dd4d66 100644 --- a/bundle/manifests/prometheus-exporter-operator.clusterserviceversion.yaml +++ b/bundle/manifests/prometheus-exporter-operator.clusterserviceversion.yaml @@ -34,7 +34,7 @@ metadata: operators.operatorframework.io/project_layout: ansible.sdk.operatorframework.io/v1 repository: https://github.com/3scale-ops/prometheus-exporter-operator support: Red Hat, Inc. - name: prometheus-exporter-operator.v0.6.2 + name: prometheus-exporter-operator.v0.7.0-alpha.1 namespace: placeholder spec: apiservicedefinitions: {} @@ -124,7 +124,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.annotations['olm.targetNamespaces'] - image: quay.io/3scale/prometheus-exporter-operator:v0.6.2 + image: quay.io/3scale/prometheus-exporter-operator:v0.7.0-alpha.1 livenessProbe: httpGet: path: /healthz @@ -246,6 +246,7 @@ spec: - watch - apiGroups: - integreatly.org + - grafana.integreatly.org resources: - grafanadashboards verbs: @@ -307,4 +308,4 @@ spec: provider: name: Red Hat url: https://www.redhat.com - version: 0.6.2 + version: 0.7.0-alpha.1 diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index 5639002..aabb48c 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -4,8 +4,7 @@ annotations: operators.operatorframework.io.bundle.manifests.v1: manifests/ operators.operatorframework.io.bundle.metadata.v1: metadata/ operators.operatorframework.io.bundle.package.v1: prometheus-exporter-operator - operators.operatorframework.io.bundle.channels.v1: alpha,stable - operators.operatorframework.io.bundle.channel.default.v1: alpha + operators.operatorframework.io.bundle.channels.v1: alpha operators.operatorframework.io.metrics.builder: operator-sdk-v1.24.0 operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 operators.operatorframework.io.metrics.project_layout: ansible.sdk.operatorframework.io/v1 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 4991d69..191d2a4 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -8,4 +8,4 @@ kind: Kustomization images: - name: controller newName: quay.io/3scale/prometheus-exporter-operator - newTag: v0.6.2 + newTag: v0.7.0-alpha.1