{{- if .Values.alertmanager.enabled -}}
apiVersion: v1
kind: Service
metadata:
{{- if .Values.alertmanager.service.annotations }}
  annotations:
{{ toYaml .Values.alertmanager.service.annotations | indent 4 }}
{{- end }}
  labels:
    {{- include "prometheus.alertmanager.labels" . | nindent 4 }}
{{- if .Values.alertmanager.service.labels }}
{{ toYaml .Values.alertmanager.service.labels | indent 4 }}
{{- end }}
  name: {{ template "prometheus.alertmanager.fullname" . }}
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: http
      port: {{ .Values.alertmanager.service.servicePort }}
      protocol: TCP
      targetPort: 9093
    {{- if .Values.alertmanager.service.nodePort }}
      nodePort: {{ .Values.alertmanager.service.nodePort }}
    {{- end }}
{{- if .Values.alertmanager.service.enableMeshPeer }}
    - name: meshpeer
      port: 6783
      protocol: TCP
      targetPort: 6783
{{- end }}
  selector:
    {{- include "prometheus.alertmanager.matchLabels" . | nindent 4 }}
  type: "{{ .Values.alertmanager.service.type }}"
{{- end }}
