{{- if and .Values.ingress.enabled .Values.nginx.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "cortex.nginxFullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "cortex.nginxLabels" . | nindent 4 }}
  annotations:
    {{- toYaml .Values.ingress.annotations | nindent 4 }}
spec:
{{- if .Values.ingress.ingressClass.enabled }}
  ingressClassName: {{ .Values.ingress.ingressClass.name }}
{{- end }}
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
        {{- range .paths }}
          - path: {{ . }}
            pathType: "Prefix"
            backend:
              service:
                name: {{ include "cortex.nginxFullname" $ }}
                port:
                  number: {{ $.Values.nginx.http_listen_port }}
        {{- end }}
  {{- end }}
{{- end }}
