apiVersion: v1
kind: Service
metadata:
  name: {{ template "aerospike.fullname" . }}
  labels:
    app: {{ template "aerospike.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    {{- with .Values.labels }}
    {{ toYaml . | nindent 4 }}
    {{- end }}
  annotations:
    {{- with .Values.service.annotations }}
    {{ tpl (toYaml .) $ | nindent 4 }}
    {{- end }}
spec:
  # so the mesh peer-finder works
  publishNotReadyAddresses: true
  {{ if .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP | quote  }}
  {{ end }}
  type: {{ .Values.service.type }}
  {{ if eq .Values.service.type "LoadBalancer" -}} {{ if .Values.service.loadBalancerIP -}}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{ end -}}
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{ toYaml .Values.service.loadBalancerSourceRanges | nindent 2}}
  {{ end -}}
  {{- end -}}
  ports:
    - port: 3000
      protocol: TCP
      name: client
    - port: 3002
      protocol: TCP
      name: mesh
    {{ if .Values.metrics.enabled }}
    - port: 9145
      protocol: TCP
      name: metrics
    {{- end }}
  selector:
    app: {{ template "aerospike.name" . }}
    release: {{ .Release.Name }}
