{{- if and .Values.enabled .Values.backendApplication.enabled }}
  {{- $namespace := .Release.Namespace -}}
{{- $TenantEnvironment  := .Values.global.domain.TenantEnvironment -}}
{{- $scope := $ -}}
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: backend-applications-ingress
  namespace: {{ $namespace }}
  labels:
    type: {{ .Values.backendApplication.type }}
    accessmode: {{ $.Values.backendApplication.accessmode }}
    helm.sh/chart: {{ include "all-ingress.name" $scope }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
    {{- if $.Values.global.image.tag }}
    app.kubernetes.io/version: {{ $.Values.global.image.tag | quote }}
    {{- end }}
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/enable-cors: "true"
spec:
  rules:
    {{- range $key,$value := .Values.backendApplication.manifest }}
    {{- $applicationName := $key | trunc 63 }}
    - host: {{ $applicationName }}.uavcloud-{{ $TenantEnvironment }}.io
      http:
        paths:
          - path: /
            backend:
              serviceName: {{ $applicationName }}
              servicePort: 8080
    {{- end }}
---
{{- end }}