{{- if and .Values.alertmanager.enabled .Values.alertmanager.statefulSet.enabled -}}
apiVersion: v1
kind: Service
metadata:
{{- if .Values.alertmanager.statefulSet.headless.annotations }}
  annotations:
{{ toYaml .Values.alertmanager.statefulSet.headless.annotations | indent 4 }}
{{- end }}
  labels:
    {{- include "prometheus.alertmanager.labels" . | nindent 4 }}
{{- if .Values.alertmanager.statefulSet.headless.labels }}
{{ toYaml .Values.alertmanager.statefulSet.headless.labels | indent 4 }}
{{- end }}
  name: {{ template "prometheus.alertmanager.fullname" . }}-headless
{{ include "prometheus.namespace" . | indent 2 }}
spec:
  clusterIP: None
  ports:
    - name: http
      port: {{ .Values.alertmanager.statefulSet.headless.servicePort }}
      protocol: TCP
      targetPort: 9093
{{- if .Values.alertmanager.statefulSet.headless.enableMeshPeer }}
    - name: meshpeer
      port: 6783
      protocol: TCP
      targetPort: 6783
{{- end }}
  selector:
    {{- include "prometheus.alertmanager.matchLabels" . | nindent 4 }}
{{- end }}
