apiVersion: v1
kind: Service
metadata:
  name: {{ template "mariadb.fullname" . }}
  labels:
    app: {{ template "mariadb.name" . }}
    chart: {{ template "mariadb.chart" . }}
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
  annotations:
{{- if .Values.service.annotations }}
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
{{- if .Values.metrics.enabled }}
{{ toYaml .Values.metrics.annotations | indent 4 }}
{{- end }}
spec:
  type: {{ .Values.service.type }}
  ports:
  - name: mysql
    port: 3306
    targetPort: mysql
{{- if .Values.service.nodePort }}
    nodePort: {{ .Values.service.nodePort }}
{{- end }}
{{- if .Values.metrics.enabled }}
  - name: metrics
    port: 9104
    targetPort: metrics
{{- end }}
  selector:
    app: {{ template "mariadb.name" . }}
    release: "{{ .Release.Name }}"
