{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Release.Name }}
  labels:
    app.kubernetes.io/name: {{ .Values.appName }}
    app.kubernetes.io/instance: {{ .Release.Name }}
  annotations:
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    {{- if .Values.ingress.redirectToFromWww }}
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
    {{- end }}
    {{- with .Values.ingress.clusterIssuer }}
    cert-manager.io/cluster-issuer: {{ . }}
    {{- end }}
    {{- with .Values.ingress.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
    {{- if .Values.ingress.corsAllowOrigin }}
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-origin: "{{ .Values.ingress.corsAllowOrigin }}"
    {{- end}}
    {{- $noindex := .Values.ingress.noindex | required ".Values.ingress.noindex is required." -}}
    {{- if .Values.ingress.noindex }}
    nginx.ingress.kubernetes.io/server-snippet: |-
       add_header X-Robots-Tag "noindex, nofollow";
    {{- end}}
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - {{ .Values.host }}
        {{- if .Values.ingress.redirectToFromWww }}
        - www.{{ .Values.host }}
        {{- end }}
      {{- if .Values.ingress.tlsSecret }}
      secretName: {{ .Release.Name }}-tls
      {{- end }}
  rules:
  - host: {{ .Values.host }}
    http:
      paths:
      - path: {{ .Values.ingress.path }}
        pathType: Prefix
        backend:
          service:
            name: {{ .Release.Name }}
            port:
              number: {{ .Values.port }}
{{- end }}
