{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "mariadb.fullname" . }} {{- if .Values.metrics.serviceMonitor.namespace }} namespace: {{ .Values.metrics.serviceMonitor.namespace }} {{- else }} namespace: {{ .Release.Namespace }} {{- end }} labels: app: "{{ template "mariadb.name" . }}" chart: {{ template "mariadb.chart" . }} release: {{ .Release.Name | quote }} heritage: {{ .Release.Service | quote }} {{- range $key, $value := .Values.metrics.serviceMonitor.selector }} {{ $key }}: {{ $value | quote }} {{- end }} spec: selector: matchLabels: app: {{ template "mariadb.name" . }} release: {{ .Release.Name | quote }} endpoints: - port: metrics {{- if .Values.metrics.serviceMonitor.interval }} interval: {{ .Values.metrics.serviceMonitor.interval }} {{- end }} {{- if .Values.metrics.serviceMonitor.scrapeTimeout }} scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} {{- end }} namespaceSelector: matchNames: - {{ .Release.Namespace }} {{- end }}