# helm_charts_ingress-proxy.yaml
{{- if .Values.proxy.ingress.enabled -}}
{{- $serviceName := include "kong.fullname" . -}}
{{- $servicePort := include "kong.ingress.servicePort" .Values.proxy -}}
{{- $path := .Values.proxy.ingress.path -}}
{{- $hosts_count := len .Values.proxy.ingress.hosts -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "kong.fullname" . }}-proxy
  labels:
    {{- include "kong.metaLabels" . | nindent 4 }}
  annotations:
    {{- range $key, $value := .Values.proxy.ingress.annotations }}
      {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  rules:
    {{- if eq $hosts_count 0 }}
    - http:
        paths:
          - path: {{ $path }}
            backend:
              serviceName: {{ $serviceName }}-proxy
              servicePort: {{ $servicePort }}
    {{ else -}}
    {{- range $host := .Values.proxy.ingress.hosts }}
    - host: {{ $host | quote }}
      http:
        paths:
          - path: {{ $path }}
            backend:
              serviceName: {{ $serviceName }}-proxy
              servicePort: {{ $servicePort }}
    {{- end -}}
    {{- end -}}
  {{- if .Values.proxy.ingress.tls }}
  tls:
{{ toYaml .Values.proxy.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}