{{ $ingress := .Values.ingress }}
{{ if $ingress.enabled }}
{{ $serviceName := include "mattermost-team-edition.name" . }}
{{ $servicePort := .Values.service.externalPort }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ include "mattermost-team-edition.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
  annotations:
    {{- if .Values.ingress.tls }}
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    kubernetes.io/tls-acme: "true"
    {{- else }}
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    {{- end }}
    {{- with $ingress.annotations }}
    {{- . | toYaml | nindent 4 }}
    {{- end }}
spec:
  rules:
  {{ range $host := $ingress.hosts }}
  - host: {{ $host }}
    http:
      paths:
      - path: {{ $ingress.path }}
        backend:
          serviceName: {{ $serviceName }}
          servicePort: {{ $servicePort }}
  {{ end }}
  {{ if $ingress.tls }}
  tls:
    {{- $ingress.tls | toYaml | nindent 4 }}
  {{ end }}
{{ end }}
