---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: metrics
spec:
  selector:
    matchLabels:
      name: metrics
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: "20%"
  template:
    metadata:
      labels:
        name: metrics
    spec:
      tolerations:
        - operator: Exists
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - {key: observeinc.com/unschedulable, operator: DoesNotExist}
                  - {key: eks.amazonaws.com/compute-type, operator: NotIn, values: [fargate]}
                  - {key: kubernetes.io/os, operator: NotIn, values: [windows]}
      terminationGracePeriodSeconds: 15
      containers:
        - name: grafana-agent
          image: grafana/agent:latest
          imagePullPolicy: IfNotPresent
          args:
            - -config.file=/etc/agent/agent.yaml
            - -config.expand-env
          command:
            - /bin/agent
          envFrom:
            - configMapRef:
                name: grafana-agent-env
            - secretRef:
                name: credentials
            - configMapRef:
                name: env-overrides
                optional: true
            - configMapRef:
                name: grafana-agent-env-overrides
                optional: true
          env:
            - name: HOSTNAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: OBSERVE_CLUSTER
              valueFrom:
                configMapKeyRef:
                  name: cluster-info
                  key: id
            - name: PROM_HOST_FILTER
              value: "true"
          resources:
            limits:
              cpu: 200m
              memory: 1Gi
            requests:
              cpu: 200m
              memory: 1Gi
          ports:
            - containerPort: 12345
              name: http-metrics
          volumeMounts:
            - mountPath: /etc/agent
              name: grafana-agent
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534
            capabilities:
              drop:
                - all
      serviceAccountName: metrics
      volumes:
        - name: grafana-agent
          configMap:
            name: grafana-agent
