apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: prometheus-stack
  namespace: prometheus-stack
spec:
  interval: 5m
  timeout: 5m
  install:
    disableWait: true
  upgrade:
    disableWait: true
  rollback:
    disableWait: true
  values:
    fullnameOverride: prometheus-stack
    crds:
      enabled: true
    defaultRules:
      create: true
    alertmanager:
      enabled: false
    prometheus:
      enabled: false
    prometheusOperator:
      enabled: true
    kubeStateMetrics:
      enabled: false
    nodeExporter:
      enabled: true
    prometheus-node-exporter:
      prometheus:
        monitor:
          enabled: false
          jobLabel: node-exporter
    extraServiceMonitors:
      - name: zitadel-external-metrics
        namespace: prometheus-stack
        labels:
          release: prometheus
        spec:
          endpoints:
            - interval: 30s
              scheme: https
              path: /debug/metrics
              port: https
              tlsConfig:
                serverName: login.sarex.io
                insecureSkipVerify: false
              relabelings:
                - targetLabel: __address__
                  replacement: login.sarex.io:443
          namespaceSelector:
            matchNames:
              - prometheus-stack
          selector:
            matchLabels:
              app: zitadel-metrics-ext
      - name: prometheus-istio-ingressgateway
        namespace: istio-system
        labels:
          release: prometheus
        spec:
          endpoints:
            - interval: 15s
              port: status-port
          jobLabel: istio
          namespaceSelector:
            any: true
          selector:
            matchExpressions:
              - key: istio
                operator: In
                values:
                  - ingressgateway
      - name: prometheus-istio-istiod
        namespace: istio-system
        labels:
          release: prometheus
        spec:
          endpoints:
            - interval: 15s
              port: http-monitoring
          jobLabel: istio
          namespaceSelector:
            any: true
          selector:
            matchExpressions:
              - key: istio
                operator: In
                values:
                  - pilot
    grafana:
      enabled: true
      securityContext:
        runAsNonRoot: true
        runAsUser: 472
        runAsGroup: 472
        fsGroup: 472
      initChownData:
        enabled: false
      adminUser: grafana-admin
      admin:
        existingSecret: grafana-admin
        userKey: admin-user
        passwordKey: admin-password
      extraObjects:
        - |
          {{- $secret := lookup "v1" "Secret" .Release.Namespace "grafana-admin" }}
          apiVersion: v1
          kind: Secret
          metadata:
            name: grafana-admin
            namespace: {{ .Release.Namespace }}
            labels:
              app.kubernetes.io/name: grafana
              app.kubernetes.io/instance: {{ .Release.Name }}
              app.kubernetes.io/managed-by: Helm
          type: Opaque
          data:
            admin-user: {{ .Values.adminUser | b64enc | quote }}
            admin-password: {{ if $secret }}{{ index $secret.data "admin-password" | quote }}{{ else }}{{ randAlphaNum 40 | b64enc | quote }}{{ end }}
      persistence:
        enabled: true
        type: sts
        storageClassName: local-path
        accessModes:
          - ReadWriteOnce
        size: 20Gi
      ingress:
        enabled: false
      env:
        GF_SERVER_DOMAIN: grafana-srx.wb.ru
        GF_SERVER_ROOT_URL: https://grafana-srx.wb.ru/
      sidecar:
        dashboards:
          enabled: true
          searchNamespace: ALL
          label: grafana_dashboard
          labelValue: "1"
        datasources:
          enabled: true
          defaultDatasourceEnabled: true
          isDefaultDatasource: true
          name: VictoriaMetrics
          uid: vm
          url: http://vmsingle-vmstack.vmstack.svc.cluster.local:8428
