apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.service.name }}
  labels: {{- include "mysql.labels" . | nindent 4 }}
    component: master
  {{- if or .Values.service.annotations .Values.metrics.service.annotations }}
  annotations:
  {{- if .Values.service.annotations }}
  {{- include "mysql.tplValue" ( dict "value" .Values.service.annotations "context" $) | nindent 4 }}
  {{- end }}
  {{- if .Values.metrics.service.annotations }}
  {{- include "mysql.tplValue" ( dict "value" .Values.metrics.service.annotations "context" $) | nindent 4 }}
  {{- end }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if and (eq .Values.service.type "LoadBalancer") (not (empty .Values.service.loadBalancerIP)) }}
  {{- if not (empty .Values.service.loadBalancerIP.master) }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP.master }}
  {{- end }}
  {{- end }}
  ports:
    - name: mysql
      port: {{ .Values.service.port }}
      targetPort: mysql
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }}
      nodePort: {{ .Values.service.nodePort.master }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.metrics.enabled }}
    - name: metrics
      port: {{ .Values.metrics.service.port }}
      targetPort: metrics
    {{- end }}
  selector: {{- include "mysql.matchLabels" . | nindent 4 }}
    component: master
