{{- $namespace := .Release.Namespace -}}
{{- $scope := $ -}}
{{/*  fetch all the ingress application which is enable to expose to outside as domain address */}}
{{- $ingressList := list -}}
{{- range .Values.ingress.applicationNames }}
{{- $ingressList = append $ingressList . -}}
{{- end }}
{{- range $key, $enable := .Values.application.names }}
{{- if $enable -}}
{{- $applicationName := $key | trunc 63 }}
{{- if has $applicationName $ingressList -}}
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: {{ $applicationName }}
  namespace: {{ $namespace }}
  labels:
    cmii.type: {{ $.Values.application.type }}
    cmii.app: {{ $applicationName }}
    helm.sh/chart: {{ include "uavcloud-fe-core.chart" $scope }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
    {{- if $.Chart.AppVersion }}
    app.kubernetes.io/version: {{ $.Chart.AppVersion | quote }}
    {{- end }}
spec:
  {{- include "uavcloud-fe-core.trafik.tls" $scope | nindent 2 }}
  routes:
    - match: Host(`{{ $applicationName }}.{{ $namespace }}.io`)
      kind: Rule
      services:
        - name: {{ $applicationName }}
          port: {{ $.Values.service.ports.port }}
---
{{- end }}
{{- end }}
{{- end }}
