{{ $namespace := .Release.Namespace }}
{{ $appVersion := .Chart.AppVersion | quote }}
{{ $releaseIngress := .Release.Service }}
{{ $releaseName := .Release.Name }}
{{- range $ingress := .Values.frontend.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:
{{- toYaml $ingress.rules | nindent 10 }}
{{- end }}