{{- if .Values.logs.enabled }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "kubernetes-agent.fullname" . }}-logs
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kubernetes-agent.labels" . | nindent 4 }}
    component: log-collector
spec:
  selector:
    matchLabels:
      {{- include "kubernetes-agent.selectorLabels" . | nindent 6 }}
      component: log-collector
  template:
    metadata:
      labels:
        {{- include "kubernetes-agent.selectorLabels" . | nindent 8 }}
        component: log-collector
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap-daemonset.yaml") . | sha256sum }}
    spec:
      serviceAccountName: {{ include "kubernetes-agent.serviceAccountName" . }}
      tolerations:
        - operator: Exists
      containers:
        - name: otel-collector
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - "--config=/etc/otel/otel-collector-config.yaml"
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: ONEUPTIME_API_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "kubernetes-agent.fullname" . }}
                  key: api-key
          resources:
            {{- toYaml .Values.logs.resources | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /etc/otel
              readOnly: true
            - name: varlogpods
              mountPath: /var/log/pods
              readOnly: true
      volumes:
        - name: config
          configMap:
            name: {{ include "kubernetes-agent.fullname" . }}-daemonset
        - name: varlogpods
          hostPath:
            path: /var/log/pods
{{- end }}
