{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if not .Values.alloy.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "common.names.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: alloy
    app.kubernetes.io/part-of: grafana-alloy
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
stringData:
  config.alloy: |
    {{- if .Values.alloy.configuration }}
    {{- include "common.tplvalues.render" (dict "value" .Values.alloy.configuration "context" .) | nindent 4 }}
    {{- else }}
    logging {
      level  = "info"
      format = "logfmt"
    }
    discovery.kubernetes "pods" {
      role = "pod"
    }
    discovery.kubernetes "nodes" {
      role = "node"
    }
    discovery.kubernetes "services" {
      role = "service"
    }
    discovery.kubernetes "endpoints" {
      role = "endpoints"
    }
    discovery.kubernetes "endpointslices" {
      role = "endpointslice"
    }
    discovery.kubernetes "ingresses" {
      role = "ingress"
    }
    {{- end }}
    {{- if .Values.alloy.extraConfig }}
    {{- include "common.tplvalues.render" (dict "value" .Values.alloy.extraConfig "context" .) | nindent 4 }}
    {{- end }}
{{- end }}