{{- if .Values.tempoQuery.ingress.enabled -}}
{{- $ingressApiIsStable := eq (include "tempo.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "tempo.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "tempo.ingress.supportsPathType" .) "true" -}}
{{- $fullName := include "tempo.fullname" . -}}
{{- $servicePort := .Values.tempoQuery.service.port -}}
{{- $ingressPath := .Values.tempoQuery.ingress.path -}}
{{- $ingressPathType := .Values.tempoQuery.ingress.pathType -}}
{{- $extraPaths := .Values.tempoQuery.ingress.extraPaths -}}
apiVersion: {{ include "tempo.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "tempo.labels" . | nindent 4 }}
    {{- with .Values.tempoQuery.ingress.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.tempoQuery.ingress.annotations }}
  annotations:
    {{- range $key, $value := . }}
    {{ $key }}: {{ tpl $value $ | quote }}
    {{- end }}
  {{- end }}
spec:
  {{- if and $ingressSupportsIngressClassName .Values.tempoQuery.ingress.ingressClassName }}
  ingressClassName: {{ .Values.tempoQuery.ingress.ingressClassName }}
  {{- end -}}
  {{- with .Values.tempoQuery.ingress.tls }}
  tls:
    {{- tpl (toYaml .) $ | nindent 4 }}
  {{- end }}
  rules:
  {{- if .Values.tempoQuery.ingress.hosts  }}
  {{- range .Values.tempoQuery.ingress.hosts }}
    - host: {{ tpl . $ }}
      http:
        paths:
          {{- with $extraPaths }}
          {{- toYaml . | nindent 10 }}
          {{- end }}
          - path: {{ $ingressPath }}
            {{- if $ingressSupportsPathType }}
            pathType: {{ $ingressPathType }}
            {{- end }}
            backend:
              {{- if $ingressApiIsStable }}
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $servicePort }}
              {{- else }}
              serviceName: {{ $fullName }}
              servicePort: {{ $servicePort }}
              {{- end }}
  {{- end }}
  {{- else }}
    - http:
        paths:
          - backend:
              {{- if $ingressApiIsStable }}
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $servicePort }}
              {{- else }}
              serviceName: {{ $fullName }}
              servicePort: {{ $servicePort }}
              {{- end }}
            {{- with $ingressPath }}
            path: {{ . }}
            {{- end }}
            {{- if $ingressSupportsPathType }}
            pathType: {{ $ingressPathType }}
            {{- end }}
  {{- end -}}
{{- end }}
