{{- $app := .Values.server }}
{{- if and $app.scrape.enabled (empty $app.scrape.configMap) }}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ $fullname }}-scrapeconfig
  namespace: {{ $ns }}
  labels: {{ include "vm.labels" $ctx | nindent 4 }}
data:
  {{- $config := $app.scrape.config }}
  {{- with $app.scrape.extraScrapeConfigs }}
    {{- if hasKey $config "scrape_configs" }}
      {{- $_ := set $config "scrape_configs" (concat $config.scrape_configs .) }}
    {{- end }}
  {{- end }}
  scrape.yml: |{{ toYaml $config | nindent 4 }}
{{- end }}
