{{- if .Values.ingress.enabled -}}
{{- $serviceName := include "grafana.fullname" . }}
{{- $routePrefix := .Values.routePrefix }}
{{- $releaseName := .Release.Name }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
{{- if .Values.ingress.annotations }}
  annotations:
{{ toYaml .Values.ingress.annotations | indent 4 }}
{{- end }}
  labels:
    app: {{ template "grafana.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
{{- if .Values.ingress.labels }}
{{ toYaml .Values.ingress.labels | indent 4 }}
{{- end }}
  name: {{ template "grafana.fullname" . }}
spec:
  rules:
    {{- range $host := .Values.ingress.hosts }}
    - host: {{ $host }}
      http:
        paths:
          - path: "{{ $routePrefix }}"
            backend:
              serviceName: {{ printf "%s-%s" $releaseName "grafana" | trunc 63 }}
              servicePort: 80
    {{- end -}}              
{{- if .Values.ingress.tls }}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end }}
{{- end }}
