apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-{{ .Values.domain }}
  namespace: {{ .Release.Namespace }}
  annotations:
    {{- if .Values.annotations }}
    {{ toYaml .Values.annotations | nindent 4 }}
    {{- end }}
    {{- if .Values.certificateIssuer }}
    acme.cert-manager.io/http01-edit-in-place: "true"
    cert-manager.io/cluster-issuer: {{ .Values.certificateIssuer }}
    # nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    {{- end }}
    {{- if .Values.appRoot }}
    nginx.ingress.kubernetes.io/app-root: {{ .Values.appRoot }}
    {{- end }}
spec:
  ingressClassName: {{ .Values.ingressClassName }}
  {{- if .Values.certificateIssuer }}
  tls:
  - hosts:
    - {{ .Values.domain }}
    secretName: cert-{{ .Values.domain }}
  {{- end }}
  rules:
  - host: {{ .Values.domain }}
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: {{ .Values.service.name }}
            port:
              {{- if .Values.service.port.name }}
              name: {{ .Values.service.port.name }}
              {{- else }}
              number: {{ .Values.service.port.number }}
              {{- end}}
