Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Update prometheus-exporter-operator to manage possible different GrafanaDashboard apiVersions #49

Merged
merged 7 commits into from
Sep 4, 2023
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -246,6 +246,7 @@ spec:
- watch
- apiGroups:
- integreatly.org
- grafana.integreatly.org
resources:
- grafanadashboards
verbs:
Expand Down Expand Up @@ -307,4 +308,4 @@ spec:
provider:
name: Red Hat
url: https://www.redhat.com
version: 0.6.2
version: 0.7.0-alpha.1
3 changes: 1 addition & 2 deletions bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ rules:
- watch
- apiGroups:
- integreatly.org
- grafana.integreatly.org
resources:
- grafanadashboards
verbs:
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {}
1 change: 1 addition & 0 deletions config/testing/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/prometheus-exporter-crd-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
label:
key: monitoring-key
value: middleware
apiVersion: grafana.integreatly.org/v1beta1
extraLabel:
key: tier
value: frontend
Expand Down Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions roles/prometheusexporter/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions roles/prometheusexporter/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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 }}"
Loading