{{- if.Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "aws-load-balancer-controller.fullname" . }}
  namespace: {{ default .Release.Namespace .Values.serviceMonitor.namespace }}
  labels:
    {{- include "aws-load-balancer-controller.labels" . | nindent 4 }}
  {{- with .Values.serviceMonitor.additionalLabels }}
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  jobLabel: app.kubernetes.io/instance
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  selector:
    matchLabels:
      {{- include "aws-load-balancer-controller.selectorLabels" . | nindent 6 }}
    matchExpressions:
      - key: prometheus.io/service-monitor
        operator: NotIn
        values:
          - "false"
  endpoints:
    - port: metrics-server
      path: /metrics
      scheme: http
    {{- with .Values.serviceMonitor.interval }}
      interval: {{ . }}
    {{- end }}
    {{- with .Values.serviceMonitor.scrapeTimeout  }}
      scrapeTimeout: {{ . }}
    {{- end }}
    {{- with .Values.serviceMonitor.relabelings }}
      relabelings:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.serviceMonitor.metricRelabelings }}
      metricRelabelings:
        {{- toYaml . | nindent 8 }}
    {{- end }}
{{- end -}}
