{{- if .Values.ingress.enabled }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "tomcat.fullname" . }}
  labels: {{- include "tomcat.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.ingress.certManager }}
    kubernetes.io/tls-acme: "true"
    {{- end }}
    {{- if .Values.ingress.annotations }}
    {{- include "tomcat.tplValue" ( dict "value" .Values.ingress.annotations "context" $) | nindent 4 }}
    {{- end }}
spec:
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .name }}
      http:
        paths:
          - path: {{ default "/" .path }}
            backend:
              serviceName: {{ template "tomcat.fullname" $ }}
              servicePort: http
    {{- end }}
  tls:
    {{- range .Values.ingress.hosts }}
    {{- if .tls }}
    - hosts:
        {{- if .tlsHosts }}
        {{- range $host := .tlsHosts }}
        - {{ $host }}
        {{- end }}
        {{- else }}
        - {{ .name }}
        {{- end }}
      secretName: {{ .tlsSecret }}
    {{- end }}
    {{- end }}
{{- end }}
