Repository: grafana/grafana-operator
Pull request #1949: OLM Refinements
Author: login: theSuess
Labels: name: chore
Created: 2025-04-09T08:20:26Z | Merged: 2025-04-09T12:02:34Z

Fixes #1925 and removes the upper limit on OpenShift versions, ensuring I don't forget to change this on every OCP release.



Linked issue #1925: Service Monitor Missing from Operator Hub and Kustomize Install
**Describe the bug**
I install this operator onto my OpenShift cluster via the Catalogue I am not getting metrics about the operator when investigating it seems there is no Service Monitor

**Version**
v 5.17.0

**To Reproduce**
Steps to reproduce the behavior:

Install Operator
Service Monitor Missing

**Expected behavior**
I would expect this to be part of the install or configurable in the 

apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana


**Suspect component/Location where the bug might be occurring**
Missing Service Monitor I cannot see a way to Add one via the Operator instructions the Kustomize files do not provide one either I can see there is Helm Values for this could they be made av alible to the Operator hub and or Kustomize versions potential this could be confirmed as part of the 

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Runtime (please complete the following information):**

- OS: Openshift
- Grafana Operator Version 5.17.0
- Environment: Openshift 4.14
- Deployment type: Openshift OLM
- Other: N/A

**Additional context**
Add any other context about the problem here.

Linked issue comments: user: login: theSuess
created_at: 2025-03-31T09:58:58Z
body: I'll take a look at this with the next OperatorHub release
author_association: COLLABORATOR
user: login: theSuess
created_at: 2025-04-11T11:52:49Z
body: Coming back to this, adding the service monitor to the OperatorHub installation is not as straight forward as expected. It would create a dependency on the Prometheus operator, which I'd like to avoid.

I'll create a PR for documenting how to set up the service monitor manually
author_association: COLLABORATOR

Diff:
diff --git a/Makefile b/Makefile
index 3db1cadda..937d96116 100644
--- a/Makefile
+++ b/Makefile
@@ -117,12 +117,12 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
 
 .PHONY: deploy
 deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
-	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
-	$(KUSTOMIZE) build config/default | kubectl apply --server-side --force-conflicts -f -
+	cd deploy/kustomize/overlays/cluster_scoped && $(KUSTOMIZE) edit set image controller=${IMG}
+	$(KUSTOMIZE) build deploy/kustomize/overlays/cluster_scoped | kubectl apply --server-side --force-conflicts -f -
 
 .PHONY: deploy-chainsaw
 deploy-chainsaw: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
-	$(KUSTOMIZE) build config/chainsaw-overlay | kubectl apply --server-side --force-conflicts -f -
+	$(KUSTOMIZE) build deploy/kustomize/overlays/chainsaw | kubectl apply --server-side --force-conflicts -f -
 
 .PHONY: undeploy
 undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml
index 4e2932030..a53edc134 100644
--- a/config/default/kustomization.yaml
+++ b/config/default/kustomization.yaml
@@ -22,7 +22,7 @@ resources:
 # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
 #- ../certmanager
 # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
-#- ../prometheus
+- ../prometheus
 # Add metrics service
 - metrics_service.yaml
 
diff --git a/config/default/metrics_service.yaml b/config/default/metrics_service.yaml
index f01c1c52c..e47a928d6 100644
--- a/config/default/metrics_service.yaml
+++ b/config/default/metrics_service.yaml
@@ -9,7 +9,7 @@ metadata:
 spec:
   ports:
     - name: metrics
-      port: 8443
+      port: 9090
       protocol: TCP
       targetPort: metrics
     - port: 8888
diff --git a/config/prometheus/monitor.yaml b/config/prometheus/monitor.yaml
index a2e60628b..a6b80bf35 100644
--- a/config/prometheus/monitor.yaml
+++ b/config/prometheus/monitor.yaml
@@ -10,11 +10,8 @@ metadata:
 spec:
   endpoints:
     - path: /metrics
-      port: https
-      scheme: https
-      bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
-      tlsConfig:
-        insecureSkipVerify: true
+      port: metrics
+      interval: 60s
   selector:
     matchLabels:
       app.kubernetes.io/name: grafana-operator
diff --git a/config/samples/grafana_v1beta1_grafanalibrarypanel.yaml b/config/samples/grafana_v1beta1_grafanalibrarypanel.yaml
new file mode 100644
index 000000000..60a1b4a7a
--- /dev/null
+++ b/config/samples/grafana_v1beta1_grafanalibrarypanel.yaml
@@ -0,0 +1,19 @@
+apiVersion: grafana.integreatly.org/v1beta1
+kind: GrafanaLibraryPanel
+metadata:
+  name: grafana-library-panel-inline-envs
+spec:
+  instanceSelector:
+    matchLabels:
+      dashboards: "grafana"
+  envs:
+    - name: CUSTOM_RANGE_ENV
+      value: "now - 12h"
+  plugins:
+    - name: grafana-piechart-panel
+      version: 1.3.9
+  jsonnet: >
+    local myRange = std.extVar('CUSTOM_RANGE_ENV');
+    {
+      model: {}
+    }
diff --git a/config/samples/grafana_v1beta1_grafanamutetiming.yaml b/config/samples/grafana_v1beta1_grafanamutetiming.yaml
new file mode 100644
index 000000000..4d82b28d2
--- /dev/null
+++ b/config/samples/grafana_v1beta1_grafanamutetiming.yaml
@@ -0,0 +1,17 @@
+apiVersion: grafana.integreatly.org/v1beta1
+kind: GrafanaMuteTiming
+metadata:
+  name: mutetiming-sample
+spec:
+  instanceSelector:
+    matchLabels:
+      dashboards: "grafana"
+  name: mutetiming-sample
+  editable: false
+  time_intervals:
+    - times:
+        - start_time: "00:00"
+          end_time: "06:00"
+      weekdays: [saturday]
+      days_of_month: ["1", "15"]
+      location: Asia/Shanghai
diff --git a/config/samples/grafana_v1beta1_grafananotificationtemplate.yaml b/config/samples/grafana_v1beta1_grafananotificationtemplate.yaml
new file mode 100644
index 000000000..87e7d5614
--- /dev/null
+++ b/config/samples/grafana_v1beta1_grafananotificationtemplate.yaml
@@ -0,0 +1,28 @@
+---
+apiVersion: grafana.integreatly.org/v1beta1
+kind: GrafanaNotificationTemplate
+metadata:
+  name: test
+spec:
+  instanceSelector:
+    matchLabels:
+      dashboards: "grafana"
+  name: test
+  template: |
+    {{ define "SlackAlert" }}
+      [{{.Status}}] {{ .Labels.alertname }}
+      {{ .Annotations.AlertValues }}
+    {{ end }}
+
+    {{ define "SlackAlertMessage" }}
+      {{ if gt (len .Alerts.Firing) 0 }}
+        {{ len .Alerts.Firing }} firing:
+        {{ range .Alerts.Firing }} {{ template "SlackAlert" . }} {{ end }}
+      {{ end }}
+      {{ if gt (len .Alerts.Resolved) 0 }}
+        {{ len .Alerts.Resolved }} resolved:
+        {{ range .Alerts.Resolved }} {{ template "SlackAlert" . }} {{ end }}
+      {{ end }}
+    {{ end }}
+
+    {{ template "SlackAlertMessage" . }}
diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml
index 91b5c26c1..35007e536 100644
--- a/config/samples/kustomization.yaml
+++ b/config/samples/kustomization.yaml
@@ -7,5 +7,8 @@ resources:
 - grafana_v1beta1_grafanaalertrulegroup.yaml
 - grafana_v1beta1_grafanacontactpoint.yaml
 - grafana_v1beta1_grafananotificationpolicy.yaml
+- grafana_v1beta1_grafananotificationtemplate.yaml
 - grafana_v1beta1_grafananotificationpolicyroute.yaml
+- grafana_v1beta1_grafanalibrarypanel.yaml
+- grafana_v1beta1_grafanamutetiming.yaml
 #+kubebuilder:scaffold:manifestskustomizesamples
diff --git a/config/chainsaw-overlay/deployment-patch.yaml b/deploy/kustomize/overlays/chainsaw/deployment-patch.yaml
similarity index 100%
rename from config/chainsaw-overlay/deployment-patch.yaml
rename to deploy/kustomize/overlays/chainsaw/deployment-patch.yaml
diff --git a/config/chainsaw-overlay/kustomization.yaml b/deploy/kustomize/overlays/chainsaw/kustomization.yaml
similarity index 95%
rename from config/chainsaw-overlay/kustomization.yaml
rename to deploy/kustomize/overlays/chainsaw/kustomization.yaml
index ccfe4473d..39de1f958 100644
--- a/config/chainsaw-overlay/kustomization.yaml
+++ b/deploy/kustomize/overlays/chainsaw/kustomization.yaml
@@ -1,5 +1,5 @@
 resources:
-  - ../default
+  - ../../base
 
 patches:
   - path: deployment-patch.yaml
diff --git a/hack/add-openshift-annotations.sh b/hack/add-openshift-annotations.sh
index 65f676b17..ffe1a0b6e 100755
--- a/hack/add-openshift-annotations.sh
+++ b/hack/add-openshift-annotations.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-OPENSHIFT_VERSIONS="\"v4.11-v4.16\""
+OPENSHIFT_VERSIONS="\"v4.11\""
 
 {
     echo ""


Reviews:
user: login: theSuess
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T08:21:07Z
user: login: theSuess
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T08:27:14Z
user: login: theSuess
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T08:39:31Z
user: login: weisdd
body: LGTM (but I don't have OpenShift cluster to test any of that)
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-09T09:12:10Z
user: login: Baarsgaard
body: I'm running into errors when running `make deploy` during tests locally as I don't have the CRD installed in Kind:
But it's something I can work around by changing `&&` to `;` in my chain of commands.
```
deployment.apps/grafana-operator-controller-manager-v5 serverside-applied
error: resource mapping not found for name: "grafana-operator-controller-manager-metrics-monitor" namespace: "grafana-operator-system" from "STDIN": no matches for kind "ServiceMonitor" in version "monitoring.coreos.com/v1"
ensure CRDs are installed first
make: *** [Makefile:121: deploy] Error 1
```

state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-09T10:59:18Z

Review comments:
diff_hunk: @@ -22,7 +22,7 @@ resources:
 # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
 #- ../certmanager
 # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
-#- ../prometheus
+- ../prometheus
path: config/default/kustomization.yaml
user: login: theSuess
body: This is the only thing I'm unsure about. This would enable the service monitor by default in kustomize releases as well. Not sure how it handles with missing CRDs in case the user doesn't have the prometheus operator set up
created_at: 2025-04-09T08:21:04Z
author_association: COLLABORATOR
diff_hunk: @@ -22,7 +22,7 @@ resources:
 # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
 #- ../certmanager
 # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
-#- ../prometheus
+- ../prometheus
path: config/default/kustomization.yaml
user: login: theSuess
body: which includes the E2E tests ^^

I'll investigate alternatives
created_at: 2025-04-09T08:27:14Z
author_association: COLLABORATOR
diff_hunk: @@ -22,7 +22,7 @@ resources:
 # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
 #- ../certmanager
 # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
-#- ../prometheus
+- ../prometheus
path: config/default/kustomization.yaml
user: login: theSuess
body: Kustomize is actually defined in a different place, it's just that OLM is also using kustomize, but in a different structure.

I've reworked the e2e deployment to use the kustomize artifacts instead, which turns CI green again :)
created_at: 2025-04-09T08:39:31Z
author_association: COLLABORATOR

PR comments:
user: login: theSuess
created_at: 2025-04-09T11:20:14Z
body: Good catch @Baarsgaard, the `make deploy` step is also using the OLM manifests and not the kustomize ones. I'll replace that as well
author_association: COLLABORATOR
user: login: theSuess
created_at: 2025-04-09T11:26:49Z
body: @Baarsgaard can you try again? My local setup is pretty messed up so I don't trust it ^^
author_association: COLLABORATOR
user: login: Baarsgaard
created_at: 2025-04-09T11:43:26Z
body: It works without errors, but the namespace and deployment name changed:
`grafana-operator-system/grafana-operator-controller-manager-v5 -> grafana/grafana-operator-controller-manager`
author_association: COLLABORATOR
user: login: theSuess
created_at: 2025-04-09T11:45:46Z
body: I think that's fine - thanks for checking!
author_association: COLLABORATOR