{{- if .Values.storegateway.enabled -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "thanos.fullname" . }}-storegateway
  labels: {{- include "thanos.labels" . | nindent 4 }}
    app.kubernetes.io/component: storegateway
    {{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
    prometheus-operator/monitor: 'true'
    {{- end }}
  {{- if .Values.storegateway.service.annotations }}
  annotations: {{- include "thanos.tplValue" (dict "value" .Values.storegateway.service.annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.storegateway.service.type }}
  {{- if and .Values.storegateway.service.clusterIP (eq .Values.storegateway.service.type "ClusterIP") }}
  clusterIP: {{ .Values.storegateway.service.clusterIP }}
  {{- end }}
  {{- if and .Values.storegateway.service.loadBalancerIP (eq .Values.storegateway.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.storegateway.service.loadBalancerIP }}
  {{- end }}
  {{- if and (eq .Values.storegateway.service.type "LoadBalancer") .Values.storegateway.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.storegateway.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  ports:
    - port: {{ .Values.storegateway.service.http.port }}
      targetPort: http
      protocol: TCP
      name: http
      {{- if (and (or (eq .Values.storegateway.service.type "NodePort") (eq .Values.storegateway.service.type "LoadBalancer")) .Values.storegateway.service.http.nodePort) }}
      nodePort: {{ .Values.storegateway.service.http.nodePort }}
      {{- else if eq .Values.storegateway.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    - port: {{ .Values.storegateway.service.grpc.port }}
      targetPort: grpc
      protocol: TCP
      name: grpc
      {{- if (and (or (eq .Values.storegateway.service.type "NodePort") (eq .Values.storegateway.service.type "LoadBalancer")) .Values.storegateway.service.grpc.nodePort) }}
      nodePort: {{ .Values.storegateway.service.grpc.nodePort }}
      {{- else if eq .Values.storegateway.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "thanos.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: storegateway
{{- end }}
