{{- if .Values.daemonset.enabled }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "metricbeat.fullname" . }}-daemonset-config
  labels:
    app: {{ template "metricbeat.name" . }}
    chart: {{ template "metricbeat.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  metricbeat.yml: {{ toYaml (default .Values.daemonset.config .Values.daemonset.overrideConfig) | indent 4 | b64enc }}
{{- end }}
---
{{- if .Values.deployment.enabled }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "metricbeat.fullname" . }}-deployment-config
  labels:
    app: {{ template "metricbeat.name" . }}
    chart: {{ template "metricbeat.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  metricbeat.yml: {{ toYaml (default .Values.deployment.config .Values.deployment.overrideConfig) | indent 4 | b64enc }}
{{- end }}
---
{{- if .Values.daemonset.enabled }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "metricbeat.fullname" . }}-daemonset-modules
  labels:
    app: {{ template "metricbeat.name" . }}
    chart: {{ template "metricbeat.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  {{- range $key, $value := (default .Values.daemonset.modules .Values.daemonset.overrideModules) }}
    {{- if eq $value.enabled true }}
      {{ $key }}.yml: {{ toYaml $value.config | b64enc }}
    {{- end }}
  {{- end }}
{{- end }}
---
{{- if .Values.deployment.enabled }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "metricbeat.fullname" . }}-deployment-modules
  labels:
    app: {{ template "metricbeat.name" . }}
    chart: {{ template "metricbeat.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  {{- range $key, $value := (default .Values.deployment.modules .Values.deployment.overrideModules) }}
    {{- if eq $value.enabled true }}
      {{ $key }}.yml: {{ toYaml $value.config | b64enc }}
    {{- end }}
  {{- end }}
{{- end }}
{{- range $secret := .Values.extraSecrets }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ $secret.name }}
  labels:
    app: {{ template "metricbeat.name" $ }}
    chart: {{ template "metricbeat.chart" $ }}
    release: {{ $.Release.Name }}
    heritage: {{ $.Release.Service }}
type: Opaque
data:
  {{- range $key, $value := $secret.data }}
    {{ $key }}: {{ $value | b64enc }}
  {{- end }}
{{- end}}
