{{- if ( .Values.reloader.podMonitor.enabled ) }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
{{- if .Values.reloader.podMonitor.annotations }}
  annotations:
{{ tpl (toYaml .Values.reloader.podMonitor.annotations) . | indent 4 }}
{{- end }}
  labels:
{{ include "reloader-labels.chart" . | indent 4 }}
{{- if .Values.reloader.podMonitor.labels }}
{{ tpl (toYaml .Values.reloader.podMonitor.labels) . | indent 4 }}
{{- end }}
  name: {{ template "reloader-fullname" . }}
{{- if .Values.reloader.podMonitor.namespace }}
  namespace: {{ tpl .Values.reloader.podMonitor.namespace . }}
{{- else }}
  namespace: {{ .Values.namespace | default .Release.Namespace }}
{{- end }}
spec:
  podMetricsEndpoints:
  - port: http
    path: "/metrics"
    {{- with .Values.reloader.podMonitor.interval }}
    interval: {{ . }}
    {{- end }}
    {{- with .Values.reloader.podMonitor.scheme }}
    scheme: {{ . }}
    {{- end }}
    {{- with .Values.reloader.podMonitor.bearerTokenSecret }}
    bearerTokenSecret: {{ . }}
    {{- end }}
    {{- with .Values.reloader.podMonitor.tlsConfig }}
    tlsConfig:
      {{- toYaml .| nindent 6 }}
    {{- end }}
    {{- with .Values.reloader.podMonitor.timeout }}
    scrapeTimeout: {{ . }}
    {{- end }}
    honorLabels: {{ .Values.reloader.podMonitor.honorLabels }}
    {{- with .Values.reloader.podMonitor.metricRelabelings }}
    metricRelabelings:
      {{- tpl (toYaml . | nindent 6) $ }}
    {{- end }}
    {{- with .Values.reloader.podMonitor.relabelings }}
    relabelings:
      {{- toYaml . | nindent 6 }}
    {{- end }}
  {{- with .Values.reloader.podMonitor.podTargetLabels }}
  podTargetLabels:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  jobLabel: {{ template "reloader-fullname" . }}
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  selector:
    matchLabels:
      {{ include "reloader-labels.chart" . | nindent 6 }}
{{- end }}
