{{- if .Values.ingress.enabled -}}
{{- $serviceName := printf "%s-%s" (include "pihole.fullname" .) "web" -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $pathType := .Values.ingress.pathType -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ template "pihole.fullname" . }}
  labels:
    app: {{ template "pihole.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
{{- if .Values.ingress.ingressClassName }}
  ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end }}
{{- if .Values.ingress.tls }}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ . | quote }}
      http:
        paths:
          - path: {{ $ingressPath }}
            pathType: {{ $pathType }}
            backend:
              service:
                name: {{ $serviceName }}
                port: 
                  name: http
  {{- end }}
{{- end }}
