# grafana_charts_ingress-gateway.yaml
{{- if and .Values.ingress.enabled .Values.gateway.ingress.enabled -}}
{{- fail "You have selected both ingress.enabled and gateway.ingress.enabled, you must select either ingress or gateway but not both" -}}
{{- end -}}

{{- if .Values.gateway.enabled -}}
{{- if .Values.gateway.ingress.enabled -}}
{{ $dict := dict "ctx" . "component" "gateway"  }}
{{- $ingressApiIsStable := eq (include "tempo.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "tempo.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "tempo.ingress.supportsPathType" .) "true" -}}
apiVersion: {{ include "tempo.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ include "tempo.resourceName" $dict }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "tempo.labels" (dict "ctx" . "component" "gateway") | nindent 4 }}
    {{- with .Values.gateway.ingress.labels }}
    {{- toYaml . | nindent 4}}
    {{- end}}
  {{- with .Values.gateway.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if and $ingressSupportsIngressClassName .Values.gateway.ingress.ingressClassName }}
  ingressClassName: {{ .Values.gateway.ingress.ingressClassName }}
  {{- end -}}
  {{- if .Values.gateway.ingress.tls }}
  tls:
    {{- range .Values.gateway.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      {{- with .secretName }}
      secretName: {{ . }}
      {{- end }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.gateway.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            {{- if $ingressSupportsPathType }}
            pathType: {{ .pathType }}
            {{- end }}
            backend:
              {{- if $ingressApiIsStable }}
              service:
                name: {{ include "tempo.resourceName" $dict }}
                port:
                  number: {{ $.Values.gateway.service.port }}
              {{- else }}
              serviceName: {{ include "tempo.resourceName" $dict }}
              servicePort: {{ $.Values.gateway.service.port }}
              {{- end }}
          {{- end }}
    {{- end }}
{{- end }}
{{- end }}