{{- if .Values.metrics }}
{{- if .Values.metrics.enabled }}
{{- if .Values.metrics.serviceMonitor }}
{{- if .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "zot.fullname" . }}
  namespace: {{ .Values.namespace | default .Release.Namespace }}
  labels:
    app.kubernetes.io/component: metrics
spec:
  {{- if .Values.metrics.serviceMonitor.jobLabel }}
  jobLabel: {{ .Values.metrics.serviceMonitor.jobLabel }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "zot.selectorLabels" . | nindent 6 }}
  endpoints:
    - port: zot
      {{- if .Values.metrics.serviceMonitor.interval }}
      interval: {{ .Values.metrics.serviceMonitor.interval }}
      {{- end }}
      {{- if .Values.metrics.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
      {{- end }}
      {{- if .Values.metrics.serviceMonitor.path }}
      path: {{ .Values.metrics.serviceMonitor.path }}
      {{- end }}
      {{- if .Values.metrics.serviceMonitor.scheme }}
      scheme: {{ .Values.metrics.serviceMonitor.scheme }}
      {{- end }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
