{{- if .Values.podMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  labels:
    helm.sh/chart: {{ template "flagger.chart" . }}
    app.kubernetes.io/name: {{ template "flagger.name" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    {{- range $k, $v := .Values.podMonitor.additionalLabels }}
    {{ $k }}: {{ $v | quote }}
    {{- end }}
  name: {{ include "flagger.fullname" . }}
  namespace: {{ .Values.podMonitor.namespace | default .Release.Namespace }}
spec:
  podMetricsEndpoints:
  - interval: {{ .Values.podMonitor.interval }}
    path: /metrics
    port: http
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ template "flagger.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
