{{- if and .Values.enabled.clusterMode .Values.ingress.enabled }}
{{- $namespace := .Release.Namespace -}}
{{- $applicationName := .Values.appName.clusterMode -}}
{{- $DeployDomainName := ternary (first (regexSplit ":" .Values.global.domain.DeployDomainName -1)) ( .Values.global.domain.DeployDomainName ) (contains ":" .Values.global.domain.DeployDomainName) -}}
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ $applicationName }}
  namespace: {{ $namespace }}
  labels:
    {{- include "uavcloud-middleware.emqx.labels.standard" . | nindent 4 }}
spec:
  rules:
    - host: "emqx.{{ $DeployDomainName }}"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              serviceName: {{ $applicationName }}
              servicePort: {{ .Values.containerPort.dashboard }}
  {{- if .Values.global.ingress.tls_enabled }}
  tls:
    - hosts:
        - "emqx.{{ $DeployDomainName }}"
      secretName: "x.{{ $DeployDomainName }}-tls"
  {{- end }}
---
{{- end }}
