{{- if .Values.prometheus.servicemonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "collabora-online.fullname" . }}
  labels:
    {{- include "collabora-online.labels" . | nindent 4 }}
    {{- with .Values.prometheus.servicemonitor.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  endpoints:
    - port: http
      path: "/cool/getMetrics"
      basicAuth:
        username:
          {{- if (.Values.collabora.existingSecret).enabled }}
          name: {{ .Values.collabora.existingSecret.secretName | quote }}
          key: {{ .Values.collabora.existingSecret.usernameKey | quote }}
          {{- else }}
          name: {{ include "collabora-online.fullname" . }}
          key: username
          {{- end }}
        password:
          {{- if (.Values.collabora.existingSecret).enabled }}
          name: {{ .Values.collabora.existingSecret.secretName | quote }}
          key: {{ .Values.collabora.existingSecret.passwordKey | quote }}
          {{- else }}
          name: {{ include "collabora-online.fullname" . }}
          key: password
          {{- end }}
  selector:
    matchLabels:
      {{- include "collabora-online.selectorLabels" . | nindent 6 }}
      type: main
{{- end }}
