{{- if .Values.enabled -}}
{{- if and .Values.controller.stats.enabled .Values.controller.metrics.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "nginx-ingress.controller.fullname" . }}-metrics
  namespace: {{ $.Release.Namespace }}
{{- if .Values.controller.metrics.service.annotations }}
  annotations:
  {{- range $key, $value := .Values.controller.metrics.service.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
{{- end }}
  labels:
{{ include "gitlab.standardLabels" . | indent 4 }}
    component: "{{ .Values.controller.name }}"
spec:
  clusterIP: "{{ .Values.controller.metrics.service.clusterIP }}"
{{- if .Values.controller.metrics.service.externalIPs }}
  externalIPs:
{{ toYaml .Values.controller.metrics.service.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.controller.metrics.service.loadBalancerIP }}
  loadBalancerIP: "{{ .Values.controller.metrics.service.loadBalancerIP }}"
{{- end }}
{{- if .Values.controller.metrics.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.controller.metrics.service.loadBalancerSourceRanges | indent 4 }}
{{- end }}
  ports:
    - name: metrics
      port: {{ .Values.controller.metrics.service.servicePort }}
      targetPort: metrics
  selector:
    app: {{ template "nginx-ingress.name" . }}
    component: "{{ .Values.controller.name }}"
    release: {{ .Release.Name }}
  type: "{{ .Values.controller.metrics.service.type }}"
{{- end }}
{{- end }}
