{{- if .Values.ingress.enabled -}}
{{- $fullName := include "akhq.fullname" . -}}
{{- $ingressPaths := .Values.ingress.paths -}}
apiVersion: {{ include "akhq.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    app.kubernetes.io/name: {{ include "akhq.name" . }}
    helm.sh/chart: {{ include "akhq.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- tpl (toYaml .) $ | nindent 4 }}
  {{- end }}
spec:
{{- if and .Values.ingress.ingressClassName (eq (include "akhq.ingress.apiVersion" $) "networking.k8s.io/v1") }}
  ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end }}
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ . | quote }}
      http:
        paths:
	{{- range $ingressPaths }}
          - path: {{ . }}
            {{- if eq (include "akhq.ingress.apiVersion" $) "networking.k8s.io/v1" }}
            pathType: "ImplementationSpecific"
            {{- end }}
            backend:
              {{- if eq (include "akhq.ingress.apiVersion" $) "networking.k8s.io/v1" }}
              service:
                name: {{ $fullName }}
                port:
                  name: http
              {{ else }}
              serviceName: {{ $fullName }}
              servicePort: http
              {{- end }}
	{{- end }}
  {{- end }}
{{- end }}
