{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "falcosidekick.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "falcosidekick.labels" . | nindent 4 }}
    app.kubernetes.io/component: core
    {{- range $key, $value := .Values.serviceMonitor.additionalLabels }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  endpoints:
  - port: http
    {{- if .Values.serviceMonitor.interval }}
    interval: {{ .Values.serviceMonitor.interval }}
    {{- end }}
    {{- if .Values.serviceMonitor.scrapeTimeout }}
    scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
    {{- end }}
  selector:
    matchLabels:
      {{- include "falcosidekick.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: core
{{- end }}