# helm_charts_consul-ingress.yaml
{{- if .Values.uiIngress.enabled -}}
{{- $releaseName := .Release.Name -}}
{{- $servicePort := .Values.HttpPort -}}
{{- $serviceName := include "consul.fullname" . -}}
{{- $serviceHost := .Values.uiIngress.path }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
  {{- range $key, $value := .Values.uiIngress.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
    {{- range $key, $value := .Values.uiIngress.labels }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
  name: "{{ template "consul.fullname" . }}-ui"
spec:
  rules:
  {{- range .Values.uiIngress.hosts }}
    - host: {{ . }}
      http:
        paths:
          - backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
          {{- if $serviceHost }}
            path: {{ $serviceHost }}
          {{- end }}
  {{- end -}}
  {{- if .Values.uiIngress.tls }}
  tls:
{{ toYaml .Values.uiIngress.tls | indent 4 }}
  {{- end -}}
{{- end }}