# helm_charts_ingressThanosSidecar.yaml
{{- if and .Values.prometheus.enabled .Values.prometheus.thanosIngress.enabled }}
{{- $serviceName := printf "%s-%s" (include "prometheus-operator.fullname" .) "prometheus" }}
{{- $thanosPort := .Values.prometheus.thanosIngress.servicePort -}}
{{- $routePrefix := list .Values.prometheus.prometheusSpec.routePrefix }}
{{- $paths := .Values.prometheus.thanosIngress.paths | default $routePrefix -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
{{- if .Values.prometheus.thanosIngress.annotations }}
  annotations:
{{ toYaml .Values.prometheus.thanosIngress.annotations | indent 4 }}
{{- end }}
  name: {{ template "prometheus-operator.fullname" . }}-thanos-gateway
  labels:
    app: {{ template "prometheus-operator.name" . }}-prometheus
{{ include "prometheus-operator.labels" . | indent 4 }}
{{- if .Values.prometheus.thanosIngress.labels }}
{{ toYaml .Values.prometheus.thanosIngress.labels | indent 4 }}
{{- end }}
spec:
  rules:
  {{- if .Values.prometheus.thanosIngress.hosts }}
  {{- range $host := .Values.prometheus.thanosIngress.hosts }}
    - host: {{ tpl $host $ }}
      http:
        paths:
  {{- range $p := $paths }}
          - path: {{ tpl $p $ }}
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $thanosPort }}
  {{- end -}}
  {{- end -}}
  {{- else }}
    - http:
        paths:
  {{- range $p := $paths }}
          - path: {{ tpl $p $ }}
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $thanosPort }}
  {{- end -}}
  {{- end -}}
  {{- if .Values.prometheus.thanosIngress.tls }}
  tls:
{{ toYaml .Values.prometheus.thanosIngress.tls | indent 4 }}
  {{- end -}}
{{- end -}}