{{- if and .Values.prometheus.enabled .Values.prometheus.thanosService.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "kube-prometheus-stack.fullname" . }}-thanos-discovery
  namespace: {{ template "kube-prometheus-stack.namespace" . }}
  labels:
    app: {{ template "kube-prometheus-stack.name" . }}-thanos-discovery
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
{{- if .Values.prometheus.thanosService.labels }}
{{ toYaml .Values.prometheus.thanosService.labels | indent 4 }}
{{- end }}
{{- if .Values.prometheus.thanosService.annotations }}
  annotations:
{{ toYaml .Values.prometheus.thanosService.annotations | indent 4 }}
{{- end }}
spec:
  type: {{ .Values.prometheus.thanosService.type }}
  clusterIP: {{ .Values.prometheus.thanosService.clusterIP }}
  ports:
  - name: {{ .Values.prometheus.thanosService.portName }}
    port: {{ .Values.prometheus.thanosService.port }}
    targetPort: {{ .Values.prometheus.thanosService.targetPort }}
    {{- if eq .Values.prometheus.thanosService.type "NodePort" }}
    nodePort: {{ .Values.prometheus.thanosService.nodePort }}
    {{- end }}
  - name: {{ .Values.prometheus.thanosService.httpPortName }}
    port: {{ .Values.prometheus.thanosService.httpPort }}
    targetPort: {{ .Values.prometheus.thanosService.targetHttpPort }}
    {{- if eq .Values.prometheus.thanosService.type "NodePort" }}
    nodePort: {{ .Values.prometheus.thanosService.httpNodePort }}
    {{- end }}
  selector:
    app.kubernetes.io/name: prometheus
    prometheus: {{ template "kube-prometheus-stack.fullname" . }}-prometheus
{{- end }}