{{- if .Values.ingress.enabled -}}
{{- $fullName := include "kibana.fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels: {{- include "kibana.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.ingress.certManager }}
    kubernetes.io/tls-acme: "true"
    {{- end }}
    {{- range $key, $value := .Values.ingress.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ .name }}
      http:
        paths:
          - path: {{ tpl (default "/" .path) $ }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: http
  {{- end }}
  tls:
  {{- range .Values.ingress.hosts }}
  {{- if .tls }}
    - hosts:
    {{- if .tlsHosts }}
      {{- range $host := .tlsHosts }}
        - {{ $host }}
      {{- end }}
    {{- else }}
        - {{ .name }}
    {{- end }}
      secretName: {{ .tlsSecret }}
  {{- end }}
  {{- end }}
{{- end }}
