{{- if .Values.ingress.enabled -}}
{{- $pathType := .Values.ingress.pathType | default "Prefix" -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "kibana.fullname" . }}
  labels:
    {{- include "kibana.labels" . | nindent 4 }}
    {{- with .Values.ingress.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- if .Values.ingress.annotations }}
  annotations:
    {{- with .Values.ingress.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- end }}
spec:
  {{- if .Values.ingress.className }}
  ingressClassName: {{ .Values.ingress.className | quote }}
  {{- end }}
  {{- if .Values.ingress.tls.enabled }}
  tls:
  - hosts:
  {{- range .Values.ingress.hosts }}
    - {{ .host | quote }}
  {{- end }}
  {{- if .Values.ingress.tls.secretName }}
    secretName: {{ .Values.ingress.tls.secretName }}
  {{- else }}
    secretName: {{ include "kibana.fullname" . }}-kb-http-certs-internal
  {{- end }}
  {{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
  {{- $hostPath := .path | default "/" }}
  - host: {{ .host | quote }}
    http:
      paths:
      - path: {{ $hostPath }}
        pathType: {{ $pathType }}
        backend:
          service:
            name: {{ include "kibana.fullname" $ }}-kb-http
            port:
              number: 5601
  {{- end }}
{{ end }}
