{{- if .Values.querier.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ include "thanos.fullname" . }}-querier
  labels: {{- include "thanos.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.querier.ingress.certManager }}
    kubernetes.io/tls-acme: "true"
    {{- end }}
    {{- range $key, $value := .Values.querier.ingress.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  rules:
    {{- if .Values.querier.ingress.hostname }}
    - host: {{ .Values.querier.ingress.hostname }}
      http:
        paths:
          - path: /
            backend:
              serviceName: {{ template "thanos.fullname" . }}-querier
              servicePort: http
    {{- end }}
    {{- range .Values.querier.ingress.extraHosts }}
    - host: {{ .name }}
      http:
        paths:
          - path: {{ default "/" .path }}
            backend:
              serviceName: {{ template "thanos.fullname" $ }}-querier
              servicePort: http
    {{- end }}
  {{- if or .Values.querier.ingress.tls .Values.querier.ingress.extraTls .Values.querier.ingress.hosts }}
  tls:
    {{- if .Values.querier.ingress.secrets }}
    - hosts:
        - {{ .Values.querier.ingress.hostname }}
      secretName: {{ printf "%s-tls" .Values.querier.ingress.hostname }}
    {{- end }}
    {{- if .Values.querier.ingress.extraTls }}
    {{- toYaml .Values.querier.ingress.extraTls | nindent 4 }}
    {{- end }}
  {{- end }}
{{- end }}
---
{{- if .Values.querier.ingress.grpc.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ include "thanos.fullname" . }}-grpc
  labels: {{- include "thanos.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.querier.ingress.grpc.certManager }}
    kubernetes.io/tls-acme: "true"
    {{- end }}
    {{- range $key, $value := .Values.querier.ingress.grpc.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  rules:
    {{- if .Values.querier.ingress.grpc.hostname }}
    - host: {{ .Values.querier.ingress.grpc.hostname }}
      http:
        paths:
          - path: /
            backend:
              serviceName: {{ template "thanos.fullname" . }}-querier
              servicePort: grpc
    {{- end }}
    {{- range .Values.querier.ingress.grpc.extraHosts }}
    - host: {{ .name }}
      http:
        paths:
          - path: {{ default "/" .path }}
            backend:
              serviceName: {{ template "thanos.fullname" $ }}-querier
              servicePort: grpc
    {{- end }}
  {{- if or .Values.querier.ingress.grpc.tls .Values.querier.ingress.grpc.extraTls .Values.querier.ingress.grpc.hosts }}
  tls:
    {{- if .Values.querier.ingress.grpc.tls }}
    - hosts:
        - {{ .Values.querier.ingress.grpc.hostname }}
      secretName: {{ printf "%s-tls" .Values.querier.ingress.grpc.hostname }}
    {{- end }}
    {{- if .Values.querier.ingress.grpc.extraTls }}
    {{- toYaml .Values.querier.ingress.grpc.extraTls | nindent 4 }}
    {{- end }}
  {{- end }}
{{- end }}
