---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app.kubernetes.io/component: exporter
    metricsJob: node-exporter
    cadvisormetricsJob: cadvisor
    nodeExportermetricsJob: node
  name: grafana-agent
spec:
  selector:
    matchLabels:
      app.kubernetes.io/component: exporter
      metricsJob: node-exporter
      cadvisormetricsJob: cadvisor
      nodeExportermetricsJob: node
  template:
    metadata:
      labels:
        app.kubernetes.io/component: exporter
        metricsJob: node-exporter
        cadvisormetricsJob: cadvisor
        nodeExportermetricsJob: node
    spec:
      automountServiceAccountToken: true
      containers:
        - args:
            - --server.http.address=0.0.0.0:12345
            - --config.file=/etc/agent/agent.yaml
            - --config.expand-env=true
          name: grafana-agent
          image: "grafana/agent:v0.43.4"
          ports:
            - containerPort: 12345
              name: grafana-metrics
              protocol: TCP
          resources:
            limits:
              cpu: 1000m
              memory: 180Mi
            requests:
              cpu: 40m
              memory: 180Mi
          securityContext:
            capabilities:
              add:
                - SYS_TIME
            readOnlyRootFilesystem: false
            privileged: true
          volumeMounts:
            - mountPath: /host/sys
              mountPropagation: HostToContainer
              name: sys
              readOnly: true
            - mountPath: /host/proc
              mountPropagation: HostToContainer
              name: proc
              readOnly: true
            - mountPath: /host/root
              mountPropagation: HostToContainer
              name: rootfs
              readOnly: true
            - mountPath: /var/log
              mountPropagation: HostToContainer
              name: logs
              readOnly: true
            - name: config
              mountPath: "/etc/agent"
              readOnly: false
            - name: temp
              mountPath: "/tmp"
              readOnly: false
            - name: agent-data
              mountPath: "/etc/agent/data"
              readOnly: false
      dnsPolicy: ClusterFirst
      volumes:
        - hostPath:
            path: /sys
          name: sys
        - hostPath:
            path: /proc
          name: proc
        - hostPath:
            path: /
          name: rootfs
        - hostPath:
            path: /var/log
          name: logs
        - name: config
          configMap:
            name: grafana-agent
            items:
              - key: "agent.yaml"
                path: "agent.yaml"
        - name: temp
          emptyDir: {}
        - name: agent-data
          emptyDir: {}

        - name: var-run
          hostPath:
            path: /var/run
        - name: containerd
          hostPath:
            path: /var/lib/contairnerd
        - name: disk
          hostPath:
            path: /dev/disk

      nodeSelector:
        kubernetes.io/os: linux
      hostNetwork: true
      hostPID: true
      priorityClassName: system-cluster-critical
      serviceAccountName: grafana-agent
      tolerations:
        - operator: Exists
