{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.bucketweb.enabled -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "thanos.bucketweb.fullname" . }}
  namespace: {{ include "common.names.namespace" . }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.bucketweb.service.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: bucketweb
    {{- include "thanos.servicemonitor.matchLabels" . | nindent 4 -}}
  {{- if or .Values.bucketweb.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.bucketweb.service.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.bucketweb.service.type }}
  {{- if and .Values.bucketweb.service.clusterIP (eq .Values.bucketweb.service.type "ClusterIP") }}
  clusterIP: {{ .Values.bucketweb.service.clusterIP }}
  {{- end }}
  {{- if ne .Values.bucketweb.service.type "ClusterIP" }}
  externalTrafficPolicy: {{ .Values.bucketweb.service.externalTrafficPolicy }}
  {{- end }}
  {{- if and .Values.bucketweb.service.loadBalancerIP (eq .Values.bucketweb.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.bucketweb.service.loadBalancerIP }}
  {{- end }}
  {{- if and (eq .Values.bucketweb.service.type "LoadBalancer") .Values.bucketweb.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.bucketweb.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  {{- if .Values.bucketweb.service.ipFamilyPolicy }}
  ipFamilyPolicy: {{ .Values.bucketweb.service.ipFamilyPolicy }}
  {{- end }}
  {{- if .Values.bucketweb.service.ipFamilies }}
  ipFamilies: {{ toYaml .Values.bucketweb.service.ipFamilies | nindent 4 }}
  {{- end }}
  ports:
    - port: {{ .Values.bucketweb.service.ports.http }}
      targetPort: http
      protocol: TCP
      name: http
      {{- if and (or (eq .Values.bucketweb.service.type "NodePort") (eq .Values.bucketweb.service.type "LoadBalancer")) .Values.bucketweb.service.nodePorts.http }}
      nodePort: {{ .Values.bucketweb.service.nodePorts.http }}
      {{- else if eq .Values.bucketweb.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.bucketweb.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.bucketweb.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector:
    {{- if .Values.bucketweb.service.labelSelectorsOverride }}
    {{- include "common.tplvalues.render" (dict "value" .Values.bucketweb.service.labelSelectorsOverride "context" $) | nindent 4 }}
    {{- else }}
    {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.bucketweb.podLabels .Values.commonLabels ) "context" . ) }}
    {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: bucketweb
    {{- end }}
{{- end }}
