{{- if .Values.serviceMonitor.enabled }}
apiVersion: "monitoring.coreos.com/v1"
kind: ServiceMonitor
metadata:
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
{{- if .Values.serviceMonitor.additionalLabels }}
{{ toYaml .Values.serviceMonitor.additionalLabels | indent 4 }}
{{- end }}
  name: {{ template "kyverno.serviceName" . }}-service-monitor
{{- if .Values.serviceMonitor.namespace }}
  namespace: {{ .Values.serviceMonitor.namespace }}
{{- else }}
  namespace: {{ template "kyverno.namespace" . }}
{{- end }}
spec:
  selector:
    matchLabels: {{ include "kyverno.matchLabels" . | nindent 6 }}
      app: kyverno
  namespaceSelector:
    matchNames:
    - {{ template "kyverno.namespace" . }}
  endpoints:
  - port: metrics-port
    interval: {{ .Values.serviceMonitor.interval }}
    scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
  {{- if .Values.serviceMonitor.secure }}
    scheme: https
    tlsConfig:
      {{- toYaml .Values.serviceMonitor.tlsConfig | nindent 8 }}
    {{- end }}
{{- end }}
