{{- if .Values.alertmanager.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "prometheus-operator.fullname" . }}-alertmanager
  labels:
    app: {{ template "prometheus-operator.name" . }}-alertmanager
{{ include "prometheus-operator.labels" . | indent 4 }}
{{- if .Values.alertmanager.service.annotations }}
  annotations:
{{ toYaml .Values.alertmanager.service.annotations | indent 4 }}
{{- end }}
spec:
{{- if .Values.alertmanager.service.clusterIP }}
  clusterIP: {{ .Values.alertmanager.service.clusterIP }}
{{- end }}
{{- if .Values.alertmanager.service.externalIPs }}
  externalIPs:
{{ toYaml .Values.alertmanager.service.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.alertmanager.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.alertmanager.service.loadBalancerIP }}
{{- end }}
{{- if .Values.alertmanager.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{- range $cidr := .Values.alertmanager.service.loadBalancerSourceRanges }}
    - {{ $cidr }}
  {{- end }}
{{- end }}
  ports:
    - name: web
    {{- if eq .Values.alertmanager.service.type "NodePort" }}
      nodePort: {{ .Values.alertmanager.service.nodePort }}
    {{- end }}
      port: 9093
      targetPort: 9093
      protocol: TCP
  selector:
    app: alertmanager
    alertmanager: {{ template "prometheus-operator.fullname" . }}-alertmanager
  type: "{{ .Values.alertmanager.service.type }}"
{{- end }}
