{{- if .Values.ingress.enabled -}}
{{- $serviceName := include "vault.fullname" . -}}
{{- $servicePort := .Values.service.externalPort -}}
apiVersion: {{ template "ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ template "vault.fullname" . }}
  labels:
    app: {{ template "vault.name" . }}
    chart: "{{ template "vault.chart" . }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
{{- if .Values.ingress.labels }}
{{ toYaml .Values.ingress.labels | indent 4 }}
{{- end }}
  annotations:
    {{- range $key, $value := .Values.ingress.annotations }}
      {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  rules:
    {{- range $host := .Values.ingress.hosts }}
    - host: {{ $host }}
      http:
        paths:
          - backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
          {{- if $.Values.ingress.path }}
            path: {{ $.Values.ingress.path }}
          {{- end }}
    {{- end -}}
  {{- if .Values.ingress.tls }}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}
