{{- /*
ServiceMonitor — Catalyst-overlay variant for OpenMeter.

The upstream openmeter chart does NOT publish a ServiceMonitor template,
so this Catalyst-side template is the only path for Prometheus scraping.
DEFAULT FALSE per docs/BLUEPRINT-AUTHORING.md §11.2 — Prometheus Operator
(monitoring.coreos.com/v1) is NOT in the bootstrap-kit prior to slot 25
(kube-prometheus-stack), so a ServiceMonitor shipped enabled-by-default
would generate Helm install errors on a Sovereign that hasn't reached
Phase 2 yet.

Defense in depth: the values toggle (.Values.serviceMonitor.enabled) is
the operator switch; the Capabilities gate skips the resource entirely
on a Sovereign that has not yet reconciled the CRD, so flipping the
toggle on a too-early Sovereign cannot break the bp-openmeter reconcile.

Per docs/INVIOLABLE-PRINCIPLES.md #4 every knob (interval, namespace,
labels, scrape path) is operator-tunable.
*/}}
{{- if and .Values.serviceMonitor.enabled (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: bp-openmeter
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "bp-openmeter.labels" . | nindent 4 }}
    {{- with .Values.serviceMonitor.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: openmeter
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  endpoints:
    - port: http
      path: {{ .Values.serviceMonitor.path | quote }}
      interval: {{ .Values.serviceMonitor.interval | quote }}
      scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout | quote }}
{{- end }}
