apiVersion: v1
kind: Service
metadata:
  name: {{ template "vault.fullname" . }}
  labels:
    app: {{ template "vault.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
{{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
  {{- if eq .Values.service.type "LoadBalancer" }}
  loadBalancerSourceRanges:
    {{- range .Values.service.loadBalancerSourceRanges }}
    - {{ . }}
    {{- end }}
  {{- end }}
  ports:
  - port: {{ .Values.service.externalPort }}
    protocol: TCP
    targetPort: {{ .Values.service.port }}
    name: api
  selector:
    app: {{ template "vault.name" . }}
    release: {{ .Release.Name }}
