{{- if .Values.ingress.enabled -}}
{{- $ingressPath := include "pathBase" . -}}
{{- $serviceName := $.Values.app.svc.spa -}}

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ template "webspa.fullname" . }}
  labels:
    app: {{ template "webspa.name" . }}
    chart: {{ template "webspa.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
{{- if and .Values.inf.tls.enabled .Values.inf.tls.issuer }}
    cert-manager.io/issuer: {{ .Values.inf.tls.issuer }} 
{{- end }}
{{- if .Values.inf.mesh.enabled }} 
{{- with .Values.ingress.mesh.annotations }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ . }}
      http:
        paths:
          - path: {{ $ingressPath }}
            pathType: Prefix            
            backend:
              service:
                name: {{ $serviceName }}
                port:
                  number: 80
  {{- end }}
{{- end }}
