{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "tod.fullname" . }}
  labels:
    {{- include "tod.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  ingressClassName: {{ .Values.ingress.className }}
  {{- if .Values.ingress.tls.enabled }}
  tls:
    - hosts:
        - {{ .Values.ingress.host }}
      {{- if .Values.ingress.tls.secretName }}
      secretName: {{ .Values.ingress.tls.secretName }}
      {{- end }}
  {{- end }}
  rules:
    - host: {{ .Values.ingress.host }}
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: {{ include "tod.fullname" . }}-api
                port:
                  number: 8000
          - path: /docs
            pathType: Prefix
            backend:
              service:
                name: {{ include "tod.fullname" . }}-api
                port:
                  number: 8000
          - path: /metrics
            pathType: Exact
            backend:
              service:
                name: {{ include "tod.fullname" . }}-api
                port:
                  number: 8000
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ include "tod.fullname" . }}-frontend
                port:
                  number: 80
{{- end }}
