apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ .Chart.Name }}-{{ .Values.namespace }}
  namespace: {{ .Values.monitoring.namespace }}
  labels:
    app: utm-{{ .Values.namespace }}
    relatedNamespace: {{ .Release.Namespace }}
spec:
  endpoints:
    {{- range .Values.prometheus.endpoints }}
    - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
      interval: 30s
      path: {{ .scrapePath }}
      scheme: http
      targetPort: {{ tpl .port $ }}
    {{- end }}
  jobLabel: app
  namespaceSelector:
    matchNames:
      - {{ .Values.namespace }}
  selector:
    matchExpressions:
      - key: app
        operator: In
        values:
          - {{ .Chart.Name }}
