{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "kong.fullname" . }}
  {{- if .Values.serviceMonitor.namespace }}
  namespace: {{ .Values.serviceMonitor.namespace }}
  {{- end }}
  labels:
    {{- include "kong.metaLabels" . | nindent 4 }}
  {{- if .Values.serviceMonitor.labels }}
    {{ toYaml .Values.serviceMonitor.labels | nindent 4 }}
  {{- end }}
spec:
  endpoints:
  - targetPort: metrics
    scheme: http
    {{- if .Values.serviceMonitor.interval }}
    interval: {{ .Values.serviceMonitor.interval }}
    {{- end }}
  jobLabel: {{ .Release.Name }}
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  selector:
    matchLabels:
      {{- include "kong.metaLabels" . | nindent 6 }}
{{- end }}
