{{- if or .Values.prometheus.serviceMonitor.enabled .Values.prometheus.service.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "kube2iam.fullname" . }}-metrics
  labels:
    app.kubernetes.io/name: {{ template "kube2iam.name" . }}
    helm.sh/chart: {{ template "kube2iam.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  {{- if .Values.prometheus.service.annotations }}
  annotations:
    {{- toYaml .Values.prometheus.service.annotations | nindent 4 }}
  {{- end }}
spec:
  selector:
    app.kubernetes.io/name: {{ template "kube2iam.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
  ports:
    {{- if .Values.prometheus.metricsPort }}
    - name: metrics
      port: {{ .Values.prometheus.metricsPort }}
      targetPort: {{ .Values.prometheus.metricsPort }}
    {{- else }}
    - name: http
      port: {{ .Values.host.port }}
      targetPort: {{ .Values.host.port }}
    {{- end }}
      protocol: TCP
{{ end }}
