{{- if .Values.oncall.enabled }}
{{- $myNS := lookup "v1" "Namespace" "" .Release.Namespace }}
{{- $host := index $myNS.metadata.annotations "namespace.cozystack.io/host" }}
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: grafana-oncall
  labels:
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  chart:
    spec:
      chart: cozy-grafana-oncall
      reconcileStrategy: Revision
      sourceRef:
        kind: HelmRepository
        name: cozystack-extra
        namespace: cozy-public
      version: 0.1.0
  interval: 1m0s
  timeout: 5m0s
  values:
    oncall:
      fullnameOverride: grafana-oncall
      externalGrafana:
        url: "https://{{ .Values.host | default (printf "grafana.%s" $host) }}/"
      
      externalPostgresql:
        host: grafana-oncall-db-rw
        db_name: app
        user: app
        existingSecret: grafana-oncall-db-app
        passwordKey: password
      
      externalRedis:
        host: rfrm-grafana-oncall
        existingSecret: {{ .Release.Name }}-oncall-redis-password
        passwordKey: password
{{- end }}
