{{- if .Values.ingress.enabled -}}
{{- $serviceName := .Values.service.name -}}
{{- $servicePort := .Values.service.port -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ $serviceName }}
  labels:
    app: {{ template "meep-ams.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    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 .Values.ingress.hosts }}
    - http:
        paths:
          {{- range $path := .paths }}
          - path: {{ $path }}
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
          {{- end -}}
      {{- if .name }}
      host: {{ .name }}
      {{- end }}
    {{- end -}}
  {{- if .Values.ingress.tls }}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}
