{{- if and .Values.server.enabled .Values.metrics.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "postgresql.fullname" . }}-metrics
  labels:
    {{- include "postgresql.labels" . | nindent 4 }}
  {{- with .Values.metrics.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.metrics.service.type }}
  ports:
    - port: {{ .Values.metrics.service.port }}
      targetPort: metrics
      protocol: TCP
      name: metrics
  selector:
    {{- include "postgresql.selectorLabels" . | nindent 4 }}
{{- end }}
