{{- if .Values.agent.vector.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ .Values.agent.vector.serviceAccountName }}
  namespace: {{ .Values.namespaces.observability }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: vector-agent-config
  namespace: {{ .Values.namespaces.observability }}
data:
  vector.yaml: |
    {{- .Values.agent.vector.config | nindent 4 }}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: vector-agent
  namespace: {{ .Values.namespaces.observability }}
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: vector-agent
  template:
    metadata:
      labels:
        app.kubernetes.io/name: vector-agent
    spec:
      serviceAccountName: {{ .Values.agent.vector.serviceAccountName }}
      containers:
        - name: vector
          image: "{{ .Values.agent.vector.image.repository }}:{{ .Values.agent.vector.image.tag }}"
          imagePullPolicy: {{ .Values.agent.vector.image.pullPolicy }}
          resources:
            {{- toYaml .Values.agent.vector.resources | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /etc/vector
            {{- if .Values.agent.vector.volume.enabled }}
            - name: {{ .Values.agent.vector.volume.name }}
              mountPath: {{ .Values.agent.vector.volume.mountPath }}
            {{- end }}
            - name: var-log
              mountPath: /var/log
              readOnly: true
            - name: machine-id
              mountPath: /etc/machine-id
              readOnly: true
      volumes:
        - name: config
          configMap:
            name: vector-agent-config
        {{- if .Values.agent.vector.volume.enabled }}
        - name: {{ .Values.agent.vector.volume.name }}
          emptyDir:
            {{- if .Values.agent.vector.volume.sizeLimit }}
            sizeLimit: {{ .Values.agent.vector.volume.sizeLimit }}
            {{- end }}
        {{- end }}
        - name: var-log
          hostPath:
            path: /var/log
        - name: machine-id
          hostPath:
            path: /etc/machine-id
            type: File
{{- end }}
