{{ $namespace := .Release.Namespace }}
{{ $appVersion := .Chart.AppVersion | quote }}
{{ $releaseIngress := .Release.Ingress }}
{{ $releaseName := .Release.Name }}
{{- range $ingress := .Values.[[ .Name ]].ingresses }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $ingress.name }}
  namespace: {{ $namespace }}
  labels:
    app.kubernetes.io/version: {{ $appVersion }}
    app.kubernetes.io/name: {{ $ingress.name | quote }}
    app.kubernetes.io/managed-by: {{ $releaseIngress }}
    app.kubernetes.io/instance: {{ $releaseName }}
spec:
{{- if $ingress.class }}
  ingressClassName: {{ $ingress.class }}
{{- end }}
{{- if $ingress.tls }}
  tls:
    - hosts:
        - {{ $ingress.host }}
{{- if $ingress.tls.exists }}
      secretName: {{ $ingress.tls.secretRef.name }}
{{- else }}
      secretName: {{ $ingress.tls.name }}
{{- end }}
{{- end }}
  rules:
    - host: {{ $ingress.host }}
      http:
        paths:
{{- range $path := $ingress.rules }}
{{ toYaml $path | indent 10 }}
{{- end }}
{{- end }}