---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: logs
spec:
  selector:
    matchLabels:
      name: logs
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: "20%"
  template:
    metadata:
      labels:
        name: logs
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/path: "/api/v1/metrics/prometheus"
    spec:
      serviceAccountName: logs
      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: fluent-bit
          image: fluent/fluent-bit
          envFrom:
            - configMapRef:
                name: fluent-bit-env
            - secretRef:
                name: credentials
            - configMapRef:
                name: env-overrides
                optional: true
            - configMapRef:
                name: fluent-bit-env-overrides
                optional: true
          env:
            - name: NODE
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: OBSERVE_CLUSTER
              valueFrom:
                configMapKeyRef:
                  name: cluster-info
                  key: id
          ports:
            - containerPort: 2020
              name: http-metrics
          command:
            - /fluent-bit/bin/fluent-bit
            - -c
            - /fluent-bit/etc/fluent-bit.conf
          readinessProbe:
            httpGet:
              path: /api/v1/health
              port: 2020
          livenessProbe:
            httpGet:
              path: /api/v1/health
              port: 2020
            timeoutSeconds: 5
            failureThreshold: 5
          resources:
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi
          volumeMounts:
            - name: config
              mountPath: /fluent-bit/etc
            - name: varlog
              mountPath: /var/log
            - name: varlibdockercontainers
              mountPath: /var/lib/docker/containers
              readOnly: true
          securityContext:
            privileged: true
            capabilities:
              drop:
                - ALL
              add:
                - CAP_FOWNER
      volumes:
        - name: config
          configMap:
            name: fluent-bit-config
        - name: varlog
          hostPath:
            path: /var/log
        - name: varlibdockercontainers
          hostPath:
            path: /var/lib/docker/containers
